diff --git a/integrationTest/integration_test.go b/integrationTest/integration_test.go index dccd4b904..a7e32aa37 100644 --- a/integrationTest/integration_test.go +++ b/integrationTest/integration_test.go @@ -1561,22 +1561,22 @@ func makeTests(t *testing.T) []*TestGroup { testgroup("AZURE_ALIAS_CNAME", requires(providers.CanUseAzureAlias), tc("create dependent CNAME records", - cname("foo.cname", "google.com"), - cname("quux.cname", "google2.com"), + cname("foo.cname", "google.com."), + cname("quux.cname", "google2.com."), ), tc("ALIAS to CNAME record in same zone", - cname("foo.cname", "google.com"), - cname("quux.cname", "google2.com"), + cname("foo.cname", "google.com."), + cname("quux.cname", "google2.com."), azureAlias("bar.cname", "CNAME", "/subscriptions/**subscription-id**/resourceGroups/**resource-group**/providers/Microsoft.Network/dnszones/**current-domain-no-trailing**/CNAME/foo.cname"), ), tc("change aliasCNAME", - cname("foo.cname", "google.com"), - cname("quux.cname", "google2.com"), + cname("foo.cname", "google.com."), + cname("quux.cname", "google2.com."), azureAlias("bar.cname", "CNAME", "/subscriptions/**subscription-id**/resourceGroups/**resource-group**/providers/Microsoft.Network/dnszones/**current-domain-no-trailing**/CNAME/quux.cname"), ), tc("change backCNAME", - cname("foo.cname", "google.com"), - cname("quux.cname", "google2.com"), + cname("foo.cname", "google.com."), + cname("quux.cname", "google2.com."), azureAlias("bar.cname", "CNAME", "/subscriptions/**subscription-id**/resourceGroups/**resource-group**/providers/Microsoft.Network/dnszones/**current-domain-no-trailing**/CNAME/foo.cname"), ), ), diff --git a/models/record.go b/models/record.go index b36e55204..80b206223 100644 --- a/models/record.go +++ b/models/record.go @@ -566,14 +566,12 @@ func Downcase(recs []*RecordConfig) { r.Name = strings.ToLower(r.Name) r.NameFQDN = strings.ToLower(r.NameFQDN) switch r.Type { // #rtype_variations - case "ANAME", "CNAME", "DS", "MX", "NS", "PTR", "NAPTR", "SRV", "TLSA", "AKAMAICDN": - // These record types have a target that is case insensitive, so we downcase it. + case "AKAMAICDN", "AAAA", "ANAME", "CNAME", "DS", "MX", "NS", "NAPTR", "PTR", "SRV", "TLSA": + // Target is case insensitive. Downcase it. r.target = strings.ToLower(r.target) - case "LOC": - // Do nothing to affect case of letters. - case "A", "AAAA", "ALIAS", "CAA", "IMPORT_TRANSFORM", "TXT", "SSHFP", "CF_REDIRECT", "CF_TEMP_REDIRECT", "CF_WORKER_ROUTE": - // These record types have a target that is case sensitive, or is an IP address. We leave them alone. - // Do nothing. + // BUGFIX(tlim): isn't ALIAS in the wrong case statement? + case "A", "ALIAS", "CAA", "CF_REDIRECT", "CF_TEMP_REDIRECT", "CF_WORKER_ROUTE", "IMPORT_TRANSFORM", "LOC", "SSHFP", "TXT": + // Do nothing. (IP address or case sensitive target) case "SOA": if r.target != "DEFAULT_NOT_SET." { r.target = strings.ToLower(r.target) // .target stores the Ns @@ -586,3 +584,25 @@ func Downcase(recs []*RecordConfig) { } } } + +// CanonicalizeTargets turns Targets into FQDNs +func CanonicalizeTargets(recs []*RecordConfig, origin string) { + for _, r := range recs { + switch r.Type { // #rtype_variations + case "AKAMAICDN", "ANAME", "CNAME", "DS", "MX", "NS", "NAPTR", "PTR", "SRV": + // Target is a hostname that might be a shortname. Turn it into a FQDN. + r.target = dnsutil.AddOrigin(r.target, origin) + case "A", "ALIAS", "CAA", "CF_REDIRECT", "CF_TEMP_REDIRECT", "CF_WORKER_ROUTE", "IMPORT_TRANSFORM", "LOC", "SSHFP", "TLSA", "TXT": + // Do nothing. + case "SOA": + if r.target != "DEFAULT_NOT_SET." { + r.target = dnsutil.AddOrigin(r.target, origin) // .target stores the Ns + } + if r.SoaMbox != "DEFAULT_NOT_SET." { + r.SoaMbox = dnsutil.AddOrigin(r.SoaMbox, origin) + } + default: + // TODO: we'd like to panic here, but custom record types complicate things. + } + } +} diff --git a/pkg/zonerecs/zonerecords.go b/pkg/zonerecs/zonerecords.go index bee00d744..be8c882ae 100644 --- a/pkg/zonerecs/zonerecords.go +++ b/pkg/zonerecs/zonerecords.go @@ -16,6 +16,9 @@ func CorrectZoneRecords(driver models.DNSProvider, dc *models.DomainConfig) ([]* // downcase models.Downcase(existingRecords) + models.Downcase(dc.Records) + models.CanonicalizeTargets(existingRecords, dc.Name) + models.CanonicalizeTargets(dc.Records, dc.Name) // Copy dc so that any corrections code that wants to // modify the records may. For example, if the provider only