package dnsrec import "testing" // Route53 stores a TXT value as a quoted character-string. SPF and DMARC // values contain spaces and semicolons, so an unquoted value is either // rejected or silently stored as something no resolver will match — which // looks like "DNS published, verification still pending" forever. func TestTXTValuesAreQuoted(t *testing.T) { got := quoteTXT(`v=DMARC1; p=none; adkim=s; aspf=s`) want := `"v=DMARC1; p=none; adkim=s; aspf=s"` if got != want { t.Fatalf("quoteTXT = %s, want %s", got, want) } } // A TXT value with an embedded quote must be escaped, not truncated. func TestTXTQuotingEscapes(t *testing.T) { if got := quoteTXT(`a"b`); got != `"a\"b"` { t.Fatalf("quoteTXT = %s, want %s", got, `"a\"b"`) } } // A CNAME or MX value is NOT quoted — quoting one produces a record Route53 // accepts and no resolver can follow. func TestNonTXTValuesAreNotQuoted(t *testing.T) { for _, typ := range []string{TypeCNAME, TypeMX} { if got := renderValue(typ, "x.dkim.amazonses.com"); got != "x.dkim.amazonses.com" { t.Fatalf("renderValue(%s) = %q, want unquoted", typ, got) } } if got := renderValue(TypeTXT, "hello"); got != `"hello"` { t.Fatalf("renderValue(TXT) = %q, want quoted", got) } }