watcher tests: far fewer live queries, longer live attempts (closes #214)
check / check (push) Successful in 1m11s
check / check (push) Successful in 1m11s
A domain check looked up each nameserver's addresses by asking every nameserver of that name's zone for all eight record types; it now asks only for A, AAAA and CNAME, the ones it reads. The watcher tests now check example.org instead of cloudflare.com (two nameservers instead of five) and desec.io instead of example.com (its nameservers are in zones with two, not cloudflare.com's five). The record change and NS failure tests start from saved state built on one NS lookup instead of a first full check, and the port change test runs only the port checks again. A live test attempt may take 18 seconds, not 8. A new live test checks that a nameserver's addresses include IPv4 and IPv6. Model: opus-5-5
This commit was merged in pull request #215.
This commit is contained in:
@@ -533,12 +533,39 @@ func (r *Resolver) FindAuthoritativeNameservers(
|
||||
return nil, ErrNoNameservers
|
||||
}
|
||||
|
||||
// recordTypes returns the record types a nameserver is asked for when a
|
||||
// name is checked.
|
||||
func recordTypes() []uint16 {
|
||||
return []uint16{
|
||||
dns.TypeA, dns.TypeAAAA, dns.TypeCNAME,
|
||||
dns.TypeMX, dns.TypeTXT, dns.TypeSRV,
|
||||
dns.TypeCAA, dns.TypeNS,
|
||||
}
|
||||
}
|
||||
|
||||
// addressTypes returns the record types ResolveIPAddresses asks for,
|
||||
// the only ones it reads.
|
||||
func addressTypes() []uint16 {
|
||||
return []uint16{dns.TypeA, dns.TypeAAAA, dns.TypeCNAME}
|
||||
}
|
||||
|
||||
// QueryNameserver queries a specific nameserver for all record
|
||||
// types and builds a NameserverResponse.
|
||||
func (r *Resolver) QueryNameserver(
|
||||
ctx context.Context,
|
||||
nsHostname string,
|
||||
hostname string,
|
||||
) (*NameserverResponse, error) {
|
||||
return r.queryNameserver(ctx, nsHostname, hostname, recordTypes())
|
||||
}
|
||||
|
||||
// queryNameserver queries a specific nameserver for the record types
|
||||
// in qtypes and builds a NameserverResponse.
|
||||
func (r *Resolver) queryNameserver(
|
||||
ctx context.Context,
|
||||
nsHostname string,
|
||||
hostname string,
|
||||
qtypes []uint16,
|
||||
) (*NameserverResponse, error) {
|
||||
if checkCtx(ctx) != nil {
|
||||
return nil, ErrContextCanceled
|
||||
@@ -551,7 +578,7 @@ func (r *Resolver) QueryNameserver(
|
||||
|
||||
hostname = dns.Fqdn(hostname)
|
||||
|
||||
return r.queryAllTypes(ctx, nsHostname, nsIPs[0], hostname)
|
||||
return r.queryTypes(ctx, nsHostname, nsIPs[0], hostname, qtypes)
|
||||
}
|
||||
|
||||
// QueryNameserverIP queries a nameserver by its IP address directly,
|
||||
@@ -568,14 +595,15 @@ func (r *Resolver) QueryNameserverIP(
|
||||
|
||||
hostname = dns.Fqdn(hostname)
|
||||
|
||||
return r.queryAllTypes(ctx, nsHostname, nsIP, hostname)
|
||||
return r.queryTypes(ctx, nsHostname, nsIP, hostname, recordTypes())
|
||||
}
|
||||
|
||||
func (r *Resolver) queryAllTypes(
|
||||
func (r *Resolver) queryTypes(
|
||||
ctx context.Context,
|
||||
nsHostname string,
|
||||
nsIP string,
|
||||
hostname string,
|
||||
qtypes []uint16,
|
||||
) (*NameserverResponse, error) {
|
||||
resp := &NameserverResponse{
|
||||
Nameserver: nsHostname,
|
||||
@@ -583,12 +611,6 @@ func (r *Resolver) queryAllTypes(
|
||||
Status: StatusOK,
|
||||
}
|
||||
|
||||
qtypes := []uint16{
|
||||
dns.TypeA, dns.TypeAAAA, dns.TypeCNAME,
|
||||
dns.TypeMX, dns.TypeTXT, dns.TypeSRV,
|
||||
dns.TypeCAA, dns.TypeNS,
|
||||
}
|
||||
|
||||
state := r.queryEachType(ctx, nsIP, hostname, qtypes, resp)
|
||||
classifyResponse(resp, state)
|
||||
|
||||
@@ -779,18 +801,19 @@ func (r *Resolver) QueryAllNameservers(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r.queryEachNS(ctx, nameservers, hostname)
|
||||
return r.queryEachNS(ctx, nameservers, hostname, recordTypes())
|
||||
}
|
||||
|
||||
func (r *Resolver) queryEachNS(
|
||||
ctx context.Context,
|
||||
nameservers []string,
|
||||
hostname string,
|
||||
qtypes []uint16,
|
||||
) (map[string]*NameserverResponse, error) {
|
||||
results := make(map[string]*NameserverResponse)
|
||||
|
||||
for _, ns := range nameservers {
|
||||
resp, err := r.QueryNameserver(ctx, ns, hostname)
|
||||
resp, err := r.queryNameserver(ctx, ns, hostname, qtypes)
|
||||
|
||||
// A query the context cut short says nothing about the
|
||||
// nameserver, so it must not be returned as its failure.
|
||||
@@ -835,9 +858,10 @@ func (r *Resolver) LookupAllRecords(
|
||||
}
|
||||
|
||||
// ResolveIPAddresses resolves a hostname to all IPv4 and IPv6
|
||||
// addresses, following CNAME chains up to MaxCNAMEDepth. When no
|
||||
// nameserver of the name's zone answered, it returns an error rather
|
||||
// than no addresses.
|
||||
// addresses, following CNAME chains up to MaxCNAMEDepth. It asks each
|
||||
// nameserver of the name's zone for its A, AAAA and CNAME records only.
|
||||
// When no nameserver of the name's zone answered, it returns an error
|
||||
// rather than no addresses.
|
||||
func (r *Resolver) ResolveIPAddresses(
|
||||
ctx context.Context,
|
||||
hostname string,
|
||||
@@ -858,7 +882,12 @@ func (r *Resolver) resolveIPWithCNAME(
|
||||
return nil, ErrCNAMEDepthExceeded
|
||||
}
|
||||
|
||||
results, err := r.QueryAllNameservers(ctx, hostname)
|
||||
nameservers, err := r.FindAuthoritativeNameservers(ctx, hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
results, err := r.queryEachNS(ctx, nameservers, hostname, addressTypes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user