resolver: lower-case DNS names in record values (closes #157)
check / check (push) Successful in 58s
check / check (push) Successful in 58s
Nameservers may answer with DNS names in any letter case. For eeqj.de, y.ns.joker.com answers in upper case while its peers answer in lower case, so the inconsistency check fired on every cycle. extractRecordValue now lower-cases CNAME, MX, SRV and NS targets, so the inconsistency check and the record-change check both compare names regardless of case. A, AAAA, TXT and CAA values are formatted as before. State saved before this change can hold upper-case names, which report a one-time record change on the first check after upgrading. Model: opus-5-5
This commit was merged in pull request #160.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package resolver_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"sneak.berlin/go/dnswatcher/internal/resolver"
|
||||
)
|
||||
|
||||
func TestExtractRecordValue_LetterCase(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
rr dns.RR
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "MX target lower-cased",
|
||||
rr: &dns.MX{Preference: 1, Mx: "ASPMX.L.GOOGLE.COM."},
|
||||
want: "1 aspmx.l.google.com.",
|
||||
},
|
||||
{
|
||||
name: "NS target lower-cased",
|
||||
rr: &dns.NS{Ns: "x.ns.joker.COM."},
|
||||
want: "x.ns.joker.com.",
|
||||
},
|
||||
{
|
||||
name: "CNAME target lower-cased",
|
||||
rr: &dns.CNAME{Target: "WWW.Example.Com."},
|
||||
want: "www.example.com.",
|
||||
},
|
||||
{
|
||||
name: "SRV target lower-cased",
|
||||
rr: &dns.SRV{
|
||||
Priority: 10, Weight: 5, Port: 443,
|
||||
Target: "SIP.Example.Com.",
|
||||
},
|
||||
want: "10 5 443 sip.example.com.",
|
||||
},
|
||||
{
|
||||
name: "TXT value keeps its case",
|
||||
rr: &dns.TXT{Txt: []string{"Verify=AbC123"}},
|
||||
want: "Verify=AbC123",
|
||||
},
|
||||
{
|
||||
name: "CAA value keeps its case",
|
||||
rr: &dns.CAA{Flag: 0, Tag: "issue", Value: "LetsEncrypt.org"},
|
||||
want: `0 issue "LetsEncrypt.org"`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, tt.want, resolver.ExtractRecordValue(tt.rr))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user