diff --git a/namecheap/domains_dns_set_hosts.go b/namecheap/domains_dns_set_hosts.go index f28efd7..ad60f10 100644 --- a/namecheap/domains_dns_set_hosts.go +++ b/namecheap/domains_dns_set_hosts.go @@ -37,6 +37,7 @@ var AllowedRecordTypeValues = []string{RecordTypeA, RecordTypeAAAA, RecordTypeAl var AllowedEmailTypeValues = []string{EmailTypeNone, EmailTypeMXE, EmailTypeMX, EmailTypeForward, EmailTypePrivate, EmailTypeGmail} var allowedTagValues = []string{"issue", "issuewild", "iodef"} +var validMailProtocolPrefix = regexp.MustCompile("mailto:.*@.*") var validURLProtocolPrefix = regexp.MustCompile("[a-z]+://") type DomainsDNSHostRecord struct { @@ -190,7 +191,7 @@ func validateDomainsDNSSetHostsArgs(args *DomainsDNSSetHostsArgs) error { return fmt.Errorf(`Records[%d].Address "%s" must contain a protocol prefix for %s record`, i, *record.Address, *record.RecordType) } } else if *record.RecordType == "CAA" { - if strings.Contains(*record.Address, "iodef") && !validURLProtocolPrefix.MatchString(*record.Address) { + if strings.Contains(*record.Address, "iodef") && !validMailProtocolPrefix.MatchString(*record.Address) && !validURLProtocolPrefix.MatchString(*record.Address) { return fmt.Errorf(`Records[%d].Address "%s" must contain a protocol prefix for %s iodef record`, i, *record.Address, *record.RecordType) } } diff --git a/namecheap/domains_dns_set_hosts_test.go b/namecheap/domains_dns_set_hosts_test.go index fa25e22..db547a6 100644 --- a/namecheap/domains_dns_set_hosts_test.go +++ b/namecheap/domains_dns_set_hosts_test.go @@ -301,6 +301,39 @@ func TestDomainsDNSSetHosts(t *testing.T) { assert.Equal(t, "0 iodef http://domain.com", sentBody.Get("Address1")) }) + t.Run("request_data_correct_CAA_iodef_record_mailto", func(t *testing.T) { + var sentBody url.Values + + mockServer := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { + body, _ := ioutil.ReadAll(request.Body) + query, _ := url.ParseQuery(string(body)) + sentBody = query + _, _ = writer.Write([]byte(fakeResponse)) + })) + defer mockServer.Close() + + client := setupClient(nil) + client.BaseURL = mockServer.URL + + _, err := client.DomainsDNS.SetHosts(&DomainsDNSSetHostsArgs{ + Domain: String("domain.net"), + Records: &[]DomainsDNSHostRecord{ + { + RecordType: String(RecordTypeCAA), + HostName: String("@"), + Address: String("0 iodef mailto:hostmaster@domain.com"), + }, + }, + }) + if err != nil { + t.Fatal("Unable to get domains", err) + } + + assert.Equal(t, RecordTypeCAA, sentBody.Get("RecordType1")) + assert.Equal(t, "@", sentBody.Get("HostName1")) + assert.Equal(t, "0 iodef mailto:hostmaster@domain.com", sentBody.Get("Address1")) + }) + var errorCases = []struct { Name string Args *DomainsDNSSetHostsArgs