修复规则问题
This commit is contained in:
63
test_rule.go
Normal file
63
test_rule.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"dns-server/config"
|
||||
"dns-server/shield"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 创建一个简单的配置
|
||||
cfg := &config.ShieldConfig{
|
||||
LocalRulesFile: "",
|
||||
RemoteRulesCacheDir: "/tmp",
|
||||
UpdateInterval: 3600,
|
||||
}
|
||||
|
||||
// 创建屏蔽管理器
|
||||
manager := shield.NewShieldManager(cfg)
|
||||
|
||||
// 添加测试规则
|
||||
testRules := []string{
|
||||
"||example.com", // 应该只屏蔽 example.com
|
||||
"||www.example.com", // 应该只屏蔽 www.example.com
|
||||
"/text/", // 应该屏蔽包含 text 的域名
|
||||
}
|
||||
|
||||
for _, rule := range testRules {
|
||||
manager.AddRule(rule)
|
||||
}
|
||||
|
||||
// 测试域名
|
||||
testDomains := []string{
|
||||
"example.com",
|
||||
"www.example.com",
|
||||
"subdomain.example.com",
|
||||
"anotherexample.com",
|
||||
"google.com",
|
||||
"www.anytext.com",
|
||||
"text.example.com",
|
||||
"example.text.com",
|
||||
"example.com.text",
|
||||
"examplewithouttext.com",
|
||||
}
|
||||
|
||||
fmt.Println("测试结果:")
|
||||
fmt.Println("----------------------------------------")
|
||||
|
||||
for _, domain := range testDomains {
|
||||
details := manager.CheckDomainBlockDetails(domain)
|
||||
blocked := details["blocked"].(bool)
|
||||
blockRule := details["blockRule"].(string)
|
||||
blockRuleType := details["blockRuleType"].(string)
|
||||
|
||||
status := "允许"
|
||||
if blocked {
|
||||
status = fmt.Sprintf("屏蔽 (规则: %s, 类型: %s)", blockRule, blockRuleType)
|
||||
}
|
||||
|
||||
fmt.Printf("%s: %s\n", domain, status)
|
||||
}
|
||||
|
||||
fmt.Println("----------------------------------------")
|
||||
}
|
||||
Reference in New Issue
Block a user