Compare commits

...
2 Commits
4 changed files with 46 additions and 7 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ func MatchDomain(pattern string, domain string) (isMatched bool) {
var portIndex = strings.LastIndex(patternPiece, ":*") var portIndex = strings.LastIndex(patternPiece, ":*")
if portIndex >= 0 { if portIndex >= 0 {
var prefix = patternPiece[:portIndex] var prefix = patternPiece[:portIndex]
if strings.HasPrefix(domainPieces[index], prefix+":") { if strings.HasPrefix(domainPieces[index], prefix+":") || domainPieces[index] == prefix {
continue continue
} }
} }
+8
View File
@@ -94,6 +94,14 @@ func TestMatchDomain(t *testing.T) {
var ok = MatchDomains([]string{"*.example.com:8001"}, "a.example.com:8001") var ok = MatchDomains([]string{"*.example.com:8001"}, "a.example.com:8001")
a.IsTrue(ok) a.IsTrue(ok)
} }
{
var ok = MatchDomains([]string{"a.example.com:*"}, "a.example.com:8001")
a.IsTrue(ok)
}
{
var ok = MatchDomains([]string{"a.example.com:*"}, "a.example.com")
a.IsTrue(ok)
}
{ {
var ok = MatchDomains([]string{"*.example.com:*"}, "a.example.com:8001") var ok = MatchDomains([]string{"*.example.com:*"}, "a.example.com:8001")
a.IsTrue(ok) a.IsTrue(ok)
@@ -0,0 +1,26 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package firewallconfigs_test
import (
"fmt"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"strings"
"testing"
)
func TestRuleCheckpoint_Markdown(t *testing.T) {
var result = []string{}
for _, def := range firewallconfigs.AllCheckpoints {
def.Description = strings.ReplaceAll(def.Description, "<code-label>", "`")
def.Description = strings.ReplaceAll(def.Description, "</code-label>", "`")
var row = "## " + def.Name + "\n"
row += "* 名称:" + def.Name + "\n"
row += "* 代号:`${" + def.Prefix + "}`\n"
row += "* 描述:" + def.Description + "\n"
result = append(result, row)
}
fmt.Print(strings.Join(result, "\n") + "\n")
}
@@ -1,17 +1,22 @@
package firewallconfigs package firewallconfigs_test
import ( import (
"fmt" "fmt"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
"strings" "strings"
"testing" "testing"
) )
func TestRuleOperator_Markdown(t *testing.T) { func TestRuleOperator_Markdown(t *testing.T) {
result := []string{} var result = []string{}
for _, def := range AllRuleOperators { for _, def := range firewallconfigs.AllRuleOperators {
row := "## " + def.Name + "\n" def.Description = strings.ReplaceAll(def.Description, "<code-label>", "`")
row += "符号:`" + def.Code + "`\n" def.Description = strings.ReplaceAll(def.Description, "</code-label>", "`")
row += "描述:" + def.Description + "\n"
var row = "## " + def.Name + "\n"
row += "* 名称:" + def.Name + "\n"
row += "* 代号:`" + def.Code + "`\n"
row += "* 描述:" + def.Description + "\n"
result = append(result, row) result = append(result, row)
} }