Initial commit
This commit is contained in:
commit
66cf1fc9aa
30 changed files with 2735 additions and 0 deletions
74
checker/dnsbl_test.go
Normal file
74
checker/dnsbl_test.go
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDecodeSpamhausDBL(t *testing.T) {
|
||||
cases := []struct {
|
||||
ip string
|
||||
contains string
|
||||
}{
|
||||
{"127.0.1.2", "Spam"},
|
||||
{"127.0.1.4", "Phishing"},
|
||||
{"127.0.1.5", "Malware"},
|
||||
{"127.0.1.6", "Botnet"},
|
||||
{"127.0.1.255", "refused"},
|
||||
{"127.255.255.254", "refused"},
|
||||
{"127.0.1.99", "code"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := decodeSpamhausDBL(net.ParseIP(c.ip))
|
||||
if len(got) != 1 || !strings.Contains(got[0], c.contains) {
|
||||
t.Errorf("decodeSpamhausDBL(%s) = %v, want substring %q", c.ip, got, c.contains)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeSURBLMulti(t *testing.T) {
|
||||
got := decodeSURBLMulti(net.ParseIP("127.0.0.12")) // 4 + 8
|
||||
if len(got) != 2 || !strings.Contains(got[0], "Phishing") || !strings.Contains(got[1], "Malware") {
|
||||
t.Errorf("decodeSURBLMulti = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeURIBLMulti(t *testing.T) {
|
||||
got := decodeURIBLMulti(net.ParseIP("127.0.0.2"))
|
||||
if len(got) != 1 || !strings.Contains(got[0], "black") {
|
||||
t.Errorf("decodeURIBLMulti(black) = %v", got)
|
||||
}
|
||||
got = decodeURIBLMulti(net.ParseIP("127.0.0.1"))
|
||||
if len(got) != 1 || !strings.Contains(got[0], "blocked") {
|
||||
t.Errorf("decodeURIBLMulti(refused) = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitList(t *testing.T) {
|
||||
got := splitList("a, b\nc;d e")
|
||||
want := []string{"a", "b", "c", "d", "e"}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("splitList = %v, want %v", got, want)
|
||||
}
|
||||
if !slices.Contains(got, "c") {
|
||||
t.Errorf("expected 'c' in %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeDomain(t *testing.T) {
|
||||
if got := normalizeDomain(" Example.COM. "); got != "example.com" {
|
||||
t.Errorf("normalizeDomain = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatURL(t *testing.T) {
|
||||
if got := formatURL("https://x/?q=%s", "abc"); got != "https://x/?q=abc" {
|
||||
t.Errorf("formatURL = %q", got)
|
||||
}
|
||||
if got := formatURL("https://x/", "abc"); got != "https://x/" {
|
||||
t.Errorf("formatURL noplaceholder = %q", got)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue