You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
588 B
Go
32 lines
588 B
Go
9 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/miekg/dns"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestInblacklist(t *testing.T) {
|
||
|
logger = NewLogger("", false)
|
||
|
Blacklist_ips = Kv{"1.2.3.4": 1, "2.3.4.5": 1}
|
||
|
test_ips := map[string]bool{
|
||
|
"1.2.3.4": true,
|
||
|
"2.3.4.5": true,
|
||
|
"2.3.4.1": false,
|
||
|
"1.2.4.3": false,
|
||
|
}
|
||
|
|
||
|
for ip, r := range test_ips {
|
||
|
msg := new(dns.Msg)
|
||
|
s := fmt.Sprintf("example.com. IN A %s", ip)
|
||
|
rr, err := dns.NewRR(s)
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
}
|
||
|
msg.Answer = append(msg.Answer, rr)
|
||
|
if in_blacklist(msg) != r {
|
||
|
t.Errorf("%s must match in %v result\n", ip, r)
|
||
|
}
|
||
|
}
|
||
|
}
|