|
@@ -8,6 +8,7 @@ import (
|
|
|
|
|
|
"github.com/abh/geodns/v3/targeting"
|
|
|
"github.com/abh/geodns/v3/targeting/geoip2"
|
|
|
+ "github.com/miekg/dns"
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
)
|
|
|
|
|
@@ -161,3 +162,99 @@ func CopyFile(src, dst string) (int64, error) {
|
|
|
defer df.Close()
|
|
|
return io.Copy(df, sf)
|
|
|
}
|
|
|
+
|
|
|
+func TestCAARecords(t *testing.T) {
|
|
|
+ // Create test data inline
|
|
|
+ jsonData := map[string]interface{}{
|
|
|
+ "": map[string]interface{}{
|
|
|
+ "ns": map[string]interface{}{
|
|
|
+ "ns1.example.com.": nil,
|
|
|
+ "ns2.example.com.": nil,
|
|
|
+ },
|
|
|
+ "caa": []interface{}{
|
|
|
+ map[string]interface{}{
|
|
|
+ "flag": float64(0),
|
|
|
+ "tag": "issue",
|
|
|
+ "value": "ca.example.net",
|
|
|
+ },
|
|
|
+ map[string]interface{}{
|
|
|
+ "tag": "issuewild",
|
|
|
+ "value": "ca.example.net",
|
|
|
+ },
|
|
|
+ map[string]interface{}{
|
|
|
+ "flag": float64(128),
|
|
|
+ "tag": "iodef",
|
|
|
+ "value": "mailto:[email protected]",
|
|
|
+ "weight": float64(100),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ // Create a test zone
|
|
|
+ zone := &Zone{
|
|
|
+ Origin: "test.com",
|
|
|
+ Labels: make(map[string]*Label),
|
|
|
+ Options: ZoneOptions{Ttl: 600},
|
|
|
+ }
|
|
|
+
|
|
|
+ // Set up zone data
|
|
|
+ setupZoneData(jsonData, zone)
|
|
|
+
|
|
|
+ // Verify the apex label was created
|
|
|
+ apexLabel, exists := zone.Labels[""]
|
|
|
+ if !exists {
|
|
|
+ t.Fatal("Apex label not found")
|
|
|
+ }
|
|
|
+
|
|
|
+ // Verify CAA records exist
|
|
|
+ caaRecords, exists := apexLabel.Records[dns.TypeCAA]
|
|
|
+ if !exists {
|
|
|
+ t.Fatal("CAA records not found")
|
|
|
+ }
|
|
|
+
|
|
|
+ // Should have 3 CAA records
|
|
|
+ assert.Equal(t, 3, len(caaRecords), "Expected 3 CAA records")
|
|
|
+
|
|
|
+ // Debug: print the actual records
|
|
|
+ for i, record := range caaRecords {
|
|
|
+ caa := record.RR.(*dns.CAA)
|
|
|
+ t.Logf("CAA record %d: flag=%d, tag=%s, value=%s, weight=%d", i, caa.Flag, caa.Tag, caa.Value, record.Weight)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Test records - order may vary based on JSON parsing
|
|
|
+ var issue, issuewild, iodef *dns.CAA
|
|
|
+ var iodefWeight int
|
|
|
+
|
|
|
+ for _, record := range caaRecords {
|
|
|
+ caa := record.RR.(*dns.CAA)
|
|
|
+ switch caa.Tag {
|
|
|
+ case "issue":
|
|
|
+ issue = caa
|
|
|
+ case "issuewild":
|
|
|
+ issuewild = caa
|
|
|
+ case "iodef":
|
|
|
+ iodef = caa
|
|
|
+ iodefWeight = record.Weight
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Test issue CAA record
|
|
|
+ assert.NotNil(t, issue, "Issue CAA record should exist")
|
|
|
+ assert.Equal(t, uint8(0), issue.Flag, "Issue CAA record flag should be 0")
|
|
|
+ assert.Equal(t, "issue", issue.Tag, "Issue CAA record tag should be 'issue'")
|
|
|
+ assert.Equal(t, "ca.example.net", issue.Value, "Issue CAA record value should be 'ca.example.net'")
|
|
|
+
|
|
|
+ // Test issuewild CAA record
|
|
|
+ assert.NotNil(t, issuewild, "Issuewild CAA record should exist")
|
|
|
+ assert.Equal(t, uint8(0), issuewild.Flag, "Issuewild CAA record flag should default to 0")
|
|
|
+ assert.Equal(t, "issuewild", issuewild.Tag, "Issuewild CAA record tag should be 'issuewild'")
|
|
|
+ assert.Equal(t, "ca.example.net", issuewild.Value, "Issuewild CAA record value should be 'ca.example.net'")
|
|
|
+
|
|
|
+ // Test iodef CAA record
|
|
|
+ assert.NotNil(t, iodef, "Iodef CAA record should exist")
|
|
|
+ assert.Equal(t, uint8(128), iodef.Flag, "Iodef CAA record flag should be 128")
|
|
|
+ assert.Equal(t, "iodef", iodef.Tag, "Iodef CAA record tag should be 'iodef'")
|
|
|
+ assert.Equal(t, "mailto:[email protected]", iodef.Value, "Iodef CAA record value should be 'mailto:[email protected]'")
|
|
|
+ assert.Equal(t, 100, iodefWeight, "Iodef CAA record weight should be 100")
|
|
|
+}
|