-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
godnsbl_test.go
73 lines (56 loc) · 1.5 KB
/
godnsbl_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package godnsbl_test
import (
"testing"
"github.com/HelixSpiral/godnsbl"
)
func TestLookupIP(t *testing.T) {
dnsbl := godnsbl.NewLookupService()
dnsbl.DnsblListing = append(dnsbl.DnsblListing, godnsbl.Dnsbl{
Name: "Test - DroneBL",
Address: ".dnsbl.dronebl.org",
BlockMessage: "%IPADDR found",
})
reply := dnsbl.LookupIP("127.0.0.2")
if reply.Type != "BLOCK" {
t.Errorf("Expended a ban, got: %+v\r\n", reply)
}
reply = dnsbl.LookupIP("2001:4860:4860::8888")
if reply.Type != "CLEAR" {
t.Errorf("Expended a clear, got: %+v\r\n", reply)
}
}
func TestLookupIPGetAll(t *testing.T) {
dnsbl := godnsbl.NewLookupService()
dnsbl.DnsblListing = append(dnsbl.DnsblListing, godnsbl.Dnsbl{
Name: "Test - DroneBL",
Address: ".dnsbl.dronebl.org",
BlockMessage: "%IPADDR found",
})
dnsbl.DnsblListing = append(dnsbl.DnsblListing, godnsbl.Dnsbl{
Name: "Test2 - DroneBL",
Address: ".dnsbl.dronebl.org",
BlockMessage: "%IPADDR found",
})
replies := dnsbl.LookupIPGetAll("127.0.0.2")
var foundBlock bool
for _, reply := range replies {
if reply.Type == "BLOCK" {
foundBlock = true
break
}
}
if foundBlock != true {
t.Errorf("Did not find blocking reply: %+v\r\n", replies)
}
replies = dnsbl.LookupIPGetAll("2001:4860:4860::8888")
var foundClear bool
for _, reply := range replies {
if reply.Type == "CLEAR" {
foundClear = true
break
}
}
if foundClear != true {
t.Errorf("Did not find clearing reply: %+v\r\n", replies)
}
}