1package dns 2 3import "testing" 4 5func TestDuplicateA(t *testing.T) { 6 a1, _ := NewRR("www.example.org. 2700 IN A 127.0.0.1") 7 a2, _ := NewRR("www.example.org. IN A 127.0.0.1") 8 if !IsDuplicate(a1, a2) { 9 t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String()) 10 } 11 12 a2, _ = NewRR("www.example.org. IN A 127.0.0.2") 13 if IsDuplicate(a1, a2) { 14 t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String()) 15 } 16} 17 18func TestDuplicateTXT(t *testing.T) { 19 a1, _ := NewRR("www.example.org. IN TXT \"aa\"") 20 a2, _ := NewRR("www.example.org. IN TXT \"aa\"") 21 22 if !IsDuplicate(a1, a2) { 23 t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String()) 24 } 25 26 a2, _ = NewRR("www.example.org. IN TXT \"aa\" \"bb\"") 27 if IsDuplicate(a1, a2) { 28 t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String()) 29 } 30 31 a1, _ = NewRR("www.example.org. IN TXT \"aa\" \"bc\"") 32 if IsDuplicate(a1, a2) { 33 t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String()) 34 } 35} 36 37func TestDuplicateSVCB(t *testing.T) { 38 a1, _ := NewRR(`example.com. 3600 IN SVCB 1 . ipv6hint=1::3:3:3:3 key65300=\254\032\030\000\ \043,\;`) 39 a2, _ := NewRR(`example.com. 3600 IN SVCB 1 . ipv6hint=1:0::3:3:3:3 key65300="\254\ \030\000 +\,;"`) 40 41 if !IsDuplicate(a1, a2) { 42 t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String()) 43 } 44 45 a2, _ = NewRR(`example.com. 3600 IN SVCB 1 . ipv6hint=1::3:3:3:3 key65300="\255\ \030\000 +\,;"`) 46 47 if IsDuplicate(a1, a2) { 48 t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String()) 49 } 50 51 a1, _ = NewRR(`example.com. 3600 IN SVCB 1 . ipv6hint=1::3:3:3:3`) 52 53 if IsDuplicate(a1, a2) { 54 t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String()) 55 } 56 57 a2, _ = NewRR(`example.com. 3600 IN SVCB 1 . ipv4hint=1.1.1.1`) 58 59 if IsDuplicate(a1, a2) { 60 t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String()) 61 } 62 63 a1, _ = NewRR(`example.com. 3600 IN SVCB 1 . ipv4hint=1.1.1.1,1.0.2.1`) 64 65 if IsDuplicate(a1, a2) { 66 t.Errorf("expected %s/%s not to be duplicates, but got true", a1.String(), a2.String()) 67 } 68} 69 70func TestDuplicateOwner(t *testing.T) { 71 a1, _ := NewRR("www.example.org. IN A 127.0.0.1") 72 a2, _ := NewRR("www.example.org. IN A 127.0.0.1") 73 if !IsDuplicate(a1, a2) { 74 t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String()) 75 } 76 77 a2, _ = NewRR("WWw.exaMPle.org. IN A 127.0.0.2") 78 if IsDuplicate(a1, a2) { 79 t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String()) 80 } 81} 82 83func TestDuplicateDomain(t *testing.T) { 84 a1, _ := NewRR("www.example.org. IN CNAME example.org.") 85 a2, _ := NewRR("www.example.org. IN CNAME example.org.") 86 if !IsDuplicate(a1, a2) { 87 t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String()) 88 } 89 90 a2, _ = NewRR("www.example.org. IN CNAME exAMPLe.oRG.") 91 if !IsDuplicate(a1, a2) { 92 t.Errorf("expected %s/%s to be duplicates, but got false", a1.String(), a2.String()) 93 } 94} 95 96func TestDuplicateWrongRrtype(t *testing.T) { 97 // Test that IsDuplicate won't panic for a record that's lying about 98 // it's Rrtype. 99 100 r1 := &A{Hdr: RR_Header{Rrtype: TypeA}} 101 r2 := &AAAA{Hdr: RR_Header{Rrtype: TypeA}} 102 if IsDuplicate(r1, r2) { 103 t.Errorf("expected %s/%s not to be duplicates, but got true", r1.String(), r2.String()) 104 } 105 106 r3 := &AAAA{Hdr: RR_Header{Rrtype: TypeA}} 107 r4 := &A{Hdr: RR_Header{Rrtype: TypeA}} 108 if IsDuplicate(r3, r4) { 109 t.Errorf("expected %s/%s not to be duplicates, but got true", r3.String(), r4.String()) 110 } 111 112 r5 := &AAAA{Hdr: RR_Header{Rrtype: TypeA}} 113 r6 := &AAAA{Hdr: RR_Header{Rrtype: TypeA}} 114 if !IsDuplicate(r5, r6) { 115 t.Errorf("expected %s/%s to be duplicates, but got false", r5.String(), r6.String()) 116 } 117} 118