forked from TrueCloudLab/lego
Added testcase for in-valid.co.uk
Camelcased: fqdn2zone to fqdnToZone Grammatical fix in externally visible error message
This commit is contained in:
parent
4945919c69
commit
8b90b1a380
3 changed files with 22 additions and 13 deletions
|
@ -18,7 +18,7 @@ type preCheckDNSFunc func(fqdn, value string) (bool, error)
|
|||
|
||||
var (
|
||||
preCheckDNS preCheckDNSFunc = checkDNSPropagation
|
||||
fqdn2zone = map[string]string{}
|
||||
fqdnToZone = map[string]string{}
|
||||
)
|
||||
|
||||
var recursiveNameserver = "google-public-dns-a.google.com:53"
|
||||
|
@ -185,7 +185,7 @@ func lookupNameservers(fqdn string) ([]string, error) {
|
|||
// findZoneByFqdn determines the zone of the given fqdn
|
||||
func findZoneByFqdn(fqdn, nameserver string) (string, error) {
|
||||
// Do we have it cached?
|
||||
if zone, ok := fqdn2zone[fqdn]; ok {
|
||||
if zone, ok := fqdnToZone[fqdn]; ok {
|
||||
return zone, nil
|
||||
}
|
||||
|
||||
|
@ -210,9 +210,9 @@ func findZoneByFqdn(fqdn, nameserver string) (string, error) {
|
|||
// If we ended up on one of the TLDs, it means the domain did not exist.
|
||||
publicsuffix, _ := publicsuffix.PublicSuffix(unFqdn(zone))
|
||||
if publicsuffix == unFqdn(zone) {
|
||||
return "", fmt.Errorf("Could not determine zone authoritively")
|
||||
return "", fmt.Errorf("Could not determine zone authoritatively")
|
||||
}
|
||||
fqdn2zone[fqdn] = zone
|
||||
fqdnToZone[fqdn] = zone
|
||||
return zone, nil
|
||||
}
|
||||
}
|
||||
|
@ -225,9 +225,9 @@ func findZoneByFqdn(fqdn, nameserver string) (string, error) {
|
|||
// If we ended up on one of the TLDs, it means the domain did not exist.
|
||||
publicsuffix, _ := publicsuffix.PublicSuffix(unFqdn(zone))
|
||||
if publicsuffix == unFqdn(zone) {
|
||||
return "", fmt.Errorf("Could not determine zone authoritively")
|
||||
return "", fmt.Errorf("Could not determine zone authoritatively")
|
||||
}
|
||||
fqdn2zone[fqdn] = zone
|
||||
fqdnToZone[fqdn] = zone
|
||||
return zone, nil
|
||||
}
|
||||
}
|
||||
|
@ -252,6 +252,11 @@ func unFqdn(name string) string {
|
|||
return name
|
||||
}
|
||||
|
||||
// clearFqdnCache clears the cache of fqdn to zone mappings. Primarily used in testing.
|
||||
func clearFqdnCache() {
|
||||
fqdnToZone = map[string]string{}
|
||||
}
|
||||
|
||||
// waitFor polls the given function 'f', once every 'interval' seconds, up to 'timeout' seconds.
|
||||
func waitFor(timeout, interval int, f func() (bool, error)) error {
|
||||
var lastErr string
|
||||
|
|
|
@ -26,7 +26,7 @@ var (
|
|||
var reqChan = make(chan *dns.Msg, 10)
|
||||
|
||||
func TestRFC2136CanaryLocalTestServer(t *testing.T) {
|
||||
fqdn2zone = map[string]string{}
|
||||
clearFqdnCache()
|
||||
dns.HandleFunc("example.com.", serverHandlerHello)
|
||||
defer dns.HandleRemove("example.com.")
|
||||
|
||||
|
@ -50,7 +50,7 @@ func TestRFC2136CanaryLocalTestServer(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRFC2136ServerSuccess(t *testing.T) {
|
||||
fqdn2zone = map[string]string{}
|
||||
clearFqdnCache()
|
||||
dns.HandleFunc(rfc2136TestZone, serverHandlerReturnSuccess)
|
||||
defer dns.HandleRemove(rfc2136TestZone)
|
||||
|
||||
|
@ -70,7 +70,7 @@ func TestRFC2136ServerSuccess(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRFC2136ServerError(t *testing.T) {
|
||||
fqdn2zone = map[string]string{}
|
||||
clearFqdnCache()
|
||||
dns.HandleFunc(rfc2136TestZone, serverHandlerReturnErr)
|
||||
defer dns.HandleRemove(rfc2136TestZone)
|
||||
|
||||
|
@ -92,7 +92,7 @@ func TestRFC2136ServerError(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRFC2136TsigClient(t *testing.T) {
|
||||
fqdn2zone = map[string]string{}
|
||||
clearFqdnCache()
|
||||
dns.HandleFunc(rfc2136TestZone, serverHandlerReturnSuccess)
|
||||
defer dns.HandleRemove(rfc2136TestZone)
|
||||
|
||||
|
@ -112,7 +112,7 @@ func TestRFC2136TsigClient(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRFC2136ValidUpdatePacket(t *testing.T) {
|
||||
fqdn2zone = map[string]string{}
|
||||
clearFqdnCache()
|
||||
dns.HandleFunc(rfc2136TestZone, serverHandlerPassBackRequest)
|
||||
defer dns.HandleRemove(rfc2136TestZone)
|
||||
|
||||
|
|
|
@ -35,11 +35,15 @@ var lookupNameserversTestsErr = []struct {
|
|||
}{
|
||||
// invalid tld
|
||||
{"_null.n0n0.",
|
||||
"Could not determine zone authoritively",
|
||||
"Could not determine zone authoritatively",
|
||||
},
|
||||
// invalid domain
|
||||
{"_null.com.",
|
||||
"Could not determine zone authoritively",
|
||||
"Could not determine zone authoritatively",
|
||||
},
|
||||
// invalid domain
|
||||
{"in-valid.co.uk.",
|
||||
"Could not determine zone authoritatively",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue