-
Notifications
You must be signed in to change notification settings - Fork 1
/
duplicate_test.go
117 lines (92 loc) · 3.77 KB
/
duplicate_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package dns
import "testing"
func TestDuplicateA(t *testing.T) {
a1, _ := NewRR("www.example.org. 2700 IN A 127.0.0.1")
a2, _ := NewRR("www.example.org. IN A 127.0.0.1")
if !IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String())
}
a2, _ = NewRR("www.example.org. IN A 127.0.0.2")
if IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String())
}
}
func TestDuplicateTXT(t *testing.T) {
a1, _ := NewRR("www.example.org. IN TXT \"aa\"")
a2, _ := NewRR("www.example.org. IN TXT \"aa\"")
if !IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String())
}
a2, _ = NewRR("www.example.org. IN TXT \"aa\" \"bb\"")
if IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String())
}
a1, _ = NewRR("www.example.org. IN TXT \"aa\" \"bc\"")
if IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String())
}
}
func TestDuplicateSVCB(t *testing.T) {
a1, _ := NewRR(`example.com. 3600 IN SVCB 1 . ipv6hint=1::3:3:3:3 key65300=\254\032\030\000\ \043,\;`)
a2, _ := NewRR(`example.com. 3600 IN SVCB 1 . ipv6hint=1:0::3:3:3:3 key65300="\254\ \030\000 +\,;"`)
if !IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String())
}
a2, _ = NewRR(`example.com. 3600 IN SVCB 1 . ipv6hint=1::3:3:3:3 key65300="\255\ \030\000 +\,;"`)
if IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String())
}
a1, _ = NewRR(`example.com. 3600 IN SVCB 1 . ipv6hint=1::3:3:3:3`)
if IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String())
}
a2, _ = NewRR(`example.com. 3600 IN SVCB 1 . ipv4hint=1.1.1.1`)
if IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String())
}
a1, _ = NewRR(`example.com. 3600 IN SVCB 1 . ipv4hint=1.1.1.1,1.0.2.1`)
if IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String())
}
}
func TestDuplicateOwner(t *testing.T) {
a1, _ := NewRR("www.example.org. IN A 127.0.0.1")
a2, _ := NewRR("www.example.org. IN A 127.0.0.1")
if !IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String())
}
a2, _ = NewRR("WWw.exaMPle.org. IN A 127.0.0.2")
if IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String())
}
}
func TestDuplicateDomain(t *testing.T) {
a1, _ := NewRR("www.example.org. IN CNAME example.org.")
a2, _ := NewRR("www.example.org. IN CNAME example.org.")
if !IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String())
}
a2, _ = NewRR("www.example.org. IN CNAME exAMPLe.oRG.")
if !IsDuplicate(a1, a2) {
t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String())
}
}
func TestDuplicateWrongRrtype(t *testing.T) {
// Test that IsDuplicate won't panic for a record that's lying about
// it's Rrtype.
r1 := &A{Hdr: RR_Header{Rrtype: TypeA}}
r2 := &AAAA{Hdr: RR_Header{Rrtype: TypeA}}
if IsDuplicate(r1, r2) {
t.Errorf("expected %s/%s not to be duplicates, but got true", r1.String(), r2.String())
}
r3 := &AAAA{Hdr: RR_Header{Rrtype: TypeA}}
r4 := &A{Hdr: RR_Header{Rrtype: TypeA}}
if IsDuplicate(r3, r4) {
t.Errorf("expected %s/%s not to be duplicates, but got true", r3.String(), r4.String())
}
r5 := &AAAA{Hdr: RR_Header{Rrtype: TypeA}}
r6 := &AAAA{Hdr: RR_Header{Rrtype: TypeA}}
if !IsDuplicate(r5, r6) {
t.Errorf("expected %s/%s to be duplicates, but got false", r5.String(), r6.String())
}
}