Skip to content

Commit

Permalink
Add mailto support to CAA IODEF records
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Armstrong <[email protected]>
  • Loading branch information
psa committed Sep 2, 2022
1 parent 9ee560d commit 9c24e8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion namecheap/domains_dns_set_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down
33 changes: 33 additions & 0 deletions namecheap/domains_dns_set_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]"),
},
},
})
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:[email protected]", sentBody.Get("Address1"))
})

var errorCases = []struct {
Name string
Args *DomainsDNSSetHostsArgs
Expand Down

0 comments on commit 9c24e8c

Please sign in to comment.