Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions pkg/normalize/importTransform_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package normalize

import (
"strings"
"testing"

dnsv2 "codeberg.org/miekg/dns"
Expand Down Expand Up @@ -46,3 +47,36 @@ func TestImportTransform(t *testing.T) {
t.Fatalf("Expected 3 records in internal, but got %d", len(d.Records))
}
}

// An IMPORT_TRANSFORM that names a domain that is not in the config must be
// reported as an error. It must not crash.
func TestImportTransformMissingDomain(t *testing.T) {
const transformSingle = "0.0.0.0~1.1.1.1~~8.0.0.0"

dc := models.MustNewDomainConfig("internal")
dc.AddRecordConfig(dc.MustNewRecordConfig("www", 0, dnsv2.TypeA, "0.0.3.3"))
dc.AddRecordConfig(dc.MustNewRecordConfig("@", 0, privatetypes.TypeIMPORTTRANSFORM, transformSingle, 299, "com.internal", "missing.example"))

cfg := &models.DNSConfig{}
cfg.Domains = append(cfg.Domains, dc)
if err := cfg.PostProcess(); err != nil {
t.Fatal(err)
}

var errs []error
func() {
defer func() {
if r := recover(); r != nil {
t.Fatalf("ValidateAndNormalizeConfig panicked: %v", r)
}
}()
errs = ValidateAndNormalizeConfig(cfg)
}()

for _, err := range errs {
if strings.Contains(err.Error(), `IMPORT_TRANSFORM mentions non-existent domain "missing.example"`) {
return
}
}
t.Errorf("expected an error about the non-existent domain, got %v", errs)
}
1 change: 1 addition & 0 deletions pkg/normalize/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
if c == nil {
err = fmt.Errorf("IMPORT_TRANSFORM mentions non-existent domain %q", targetDomain)
errs = append(errs, err)
continue
}
err = importTransform(c, domain, table, ttl, suffixstrip)
if err != nil {
Expand Down
Loading