check / check (push) Failing after 2m7s
ResolveIPAddresses now returns an error, not no addresses, when no nameserver of the name's zone answered. A nameserver with status timeout or error is not an answer; one answer, even NXDOMAIN, is enough for an empty result without an error. When every server of a zone fails, FindAuthoritativeNameservers moves on to the parent name, whose servers only refer the query onward. Such a referral now has status error, so it is no answer either, and a hostname's saved records show it as error. The only caller, the nameserver address lookup, already keeps the previous addresses on an error; its comment no longer says the resolver hides this case. Model: opus-5-5
95 lines
2.3 KiB
Go
95 lines
2.3 KiB
Go
package resolver_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/miekg/dns"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"sneak.berlin/go/dnswatcher/internal/resolver"
|
|
)
|
|
|
|
// TestCollectIPs_OneAnswerIsEnough checks that one nameserver answering
|
|
// NXDOMAIN says the name has no addresses, though the other timed out.
|
|
func TestCollectIPs_OneAnswerIsEnough(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ips, _, err := resolver.CollectIPs(
|
|
map[string]*resolver.NameserverResponse{
|
|
"ns1.example.": {Status: resolver.StatusTimeout},
|
|
"ns2.example.": {Status: resolver.StatusNXDomain},
|
|
},
|
|
)
|
|
require.NoError(t, err)
|
|
assert.Empty(t, ips)
|
|
}
|
|
|
|
// TestCollectIPs_FailedIsNoAnswer checks that nameservers that all have
|
|
// status error, from a refusal, a server failure, a network error or a
|
|
// referral, are no answer rather than a name with no addresses.
|
|
func TestCollectIPs_FailedIsNoAnswer(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ips, _, err := resolver.CollectIPs(
|
|
map[string]*resolver.NameserverResponse{
|
|
"ns1.example.": {Status: resolver.StatusError},
|
|
"ns2.example.": {Status: resolver.StatusError},
|
|
},
|
|
)
|
|
require.ErrorIs(t, err, resolver.ErrNoNameserverAnswered)
|
|
assert.Empty(t, ips)
|
|
}
|
|
|
|
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))
|
|
})
|
|
}
|
|
}
|