mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
checking only one cname on a name (#81)
This commit is contained in:
@ -260,9 +260,30 @@ func NormalizeAndValidateConfig(config *models.DNSConfig) (errs []error) {
|
|||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, d := range config.Domains {
|
||||||
|
errs = append(errs, checkCNAMEs(d)...)
|
||||||
|
}
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkCNAMEs(dc *models.DomainConfig) (errs []error) {
|
||||||
|
cnames := map[string]bool{}
|
||||||
|
for _, r := range dc.Records {
|
||||||
|
if r.Type == "CNAME" {
|
||||||
|
if cnames[r.Name] {
|
||||||
|
errs = append(errs, fmt.Errorf("Cannot have multiple CNAMEs with same name: %s", r.NameFQDN))
|
||||||
|
}
|
||||||
|
cnames[r.Name] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, r := range dc.Records {
|
||||||
|
if cnames[r.Name] && r.Type != "CNAME" {
|
||||||
|
errs = append(errs, fmt.Errorf("Cannot have CNAME and %s record with same name: %s", r.Type, r.NameFQDN))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func applyRecordTransforms(domain *models.DomainConfig) error {
|
func applyRecordTransforms(domain *models.DomainConfig) error {
|
||||||
for _, rec := range domain.Records {
|
for _, rec := range domain.Records {
|
||||||
if rec.Type != "A" {
|
if rec.Type != "A" {
|
||||||
|
@ -3,6 +3,8 @@ package normalize
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/models"
|
"github.com/StackExchange/dnscontrol/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -137,3 +139,33 @@ func TestTransforms(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCNAMEMutex(t *testing.T) {
|
||||||
|
var recA = &models.RecordConfig{Type: "CNAME", Name: "foo", NameFQDN: "foo.example.com", Target: "example.com."}
|
||||||
|
tests := []struct {
|
||||||
|
rType string
|
||||||
|
name string
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
{"A", "foo", true},
|
||||||
|
{"A", "foo2", false},
|
||||||
|
{"CNAME", "foo", true},
|
||||||
|
{"CNAME", "foo2", false},
|
||||||
|
}
|
||||||
|
for _, tst := range tests {
|
||||||
|
t.Run(fmt.Sprintf("%s %s", tst.rType, tst.name), func(t *testing.T) {
|
||||||
|
var recB = &models.RecordConfig{Type: tst.rType, Name: tst.name, NameFQDN: tst.name + ".example.com", Target: "example2.com."}
|
||||||
|
dc := &models.DomainConfig{
|
||||||
|
Name: "example.com",
|
||||||
|
Records: []*models.RecordConfig{recA, recB},
|
||||||
|
}
|
||||||
|
errs := checkCNAMEs(dc)
|
||||||
|
if errs != nil && !tst.fail {
|
||||||
|
t.Error("Got error but expected none")
|
||||||
|
}
|
||||||
|
if errs == nil && tst.fail {
|
||||||
|
t.Error("Expected error but got none")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user