From 8b90b1a3801fb7fd4a621fe9782c4441082467b1 Mon Sep 17 00:00:00 2001 From: Pauline Middelink Date: Mon, 29 Feb 2016 08:46:15 +0100 Subject: [PATCH] Added testcase for in-valid.co.uk Camelcased: fqdn2zone to fqdnToZone Grammatical fix in externally visible error message --- acme/dns_challenge.go | 17 +++++++++++------ acme/dns_challenge_rfc2136_test.go | 10 +++++----- acme/dns_challenge_test.go | 8 ++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/acme/dns_challenge.go b/acme/dns_challenge.go index bf837760..533431ca 100644 --- a/acme/dns_challenge.go +++ b/acme/dns_challenge.go @@ -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 diff --git a/acme/dns_challenge_rfc2136_test.go b/acme/dns_challenge_rfc2136_test.go index b5905556..1a0ed5cc 100644 --- a/acme/dns_challenge_rfc2136_test.go +++ b/acme/dns_challenge_rfc2136_test.go @@ -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) diff --git a/acme/dns_challenge_test.go b/acme/dns_challenge_test.go index 84b805f4..54d5e095 100644 --- a/acme/dns_challenge_test.go +++ b/acme/dns_challenge_test.go @@ -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", }, }