-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlocals_test.go
83 lines (71 loc) · 2.22 KB
/
locals_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
74
75
76
77
78
79
80
81
82
83
package main
import (
"net"
"testing"
"github.com/markdingo/autoreverse/log"
"github.com/markdingo/autoreverse/mock"
)
func TestGenerateLocalForward(t *testing.T) {
ar := newAutoReverse(nil, nil)
ar.generateLocalForward("example.net.")
if ar.authorities.len() != 1 {
t.Error("GLF should have added authority", ar.authorities.len())
}
auth := ar.authorities.slice[0]
if auth.Domain != "example.net." {
t.Error("Auth was net set", auth)
}
}
func TestGenerateLocalReverse(t *testing.T) {
out := &mock.IOWriter{}
log.SetOut(out)
log.SetLevel(log.MajorLevel)
ar := newAutoReverse(nil, nil)
// Set up a forward as locals assumes there's already one present. Include an NS
// to ensure it's copied to the locals
ar.generateLocalForward("example.net.")
ar.forwardAuthority.NS = append(ar.forwardAuthority.NS,
newRR("example.net. IN NS a.ns.example.net."))
_, ipNet, err := net.ParseCIDR("2001:db8::/20")
if err != nil {
t.Fatal("Setup error", err)
}
ar.localReverses = append(ar.localReverses, ipNet)
_, ipNet, err = net.ParseCIDR("192.0.2.0/16")
if err != nil {
t.Fatal("Setup error", err)
}
ar.localReverses = append(ar.localReverses, ipNet)
err = ar.generateLocalReverses()
if err != nil {
t.Error("Unexpected v4 error", ipNet, err)
}
if ar.authorities.len() != 3 { // Forward + two reverses
t.Error("GLR should have added authority", ar.authorities.len())
}
auth := ar.authorities.slice[1]
exp := "0.1.0.0.2.ip6.arpa."
if auth.Domain != exp {
t.Error("Wrong v6 reverse. Exp", exp, "Got", auth.Domain)
}
if len(auth.NS) != 1 {
t.Error("Forward NS was not copied across")
} else if auth.NS[0].Header().Name != exp {
t.Error("Reverse NS was not transmogrified", auth.NS[0].Header().Name)
}
auth = ar.authorities.slice[2]
exp = "0.192.in-addr.arpa."
if auth.Domain != exp {
t.Error("Wrong v4 reverse. Exp", exp, "Got", auth.Domain)
}
if len(auth.NS) != 1 {
t.Error("Forward NS was not copied across")
} else if auth.NS[0].Header().Name != exp {
t.Error("Reverse NS was not transmogrified", auth.NS[0].Header().Name)
}
// Calling a second time exercises the duplicate tests code - in a lazy way
err = ar.generateLocalReverses()
if err == nil {
t.Error("Expected a 'duplicates' error")
}
}