mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-24 23:53:01 +08:00
HEXONET: Support long TXT records and fix whitespace bug (#1283)
* HEXONET: Support for long TXT records * HEXONET: Revert and update comments in auditrecords.go * Update auditrecords.go * HEXONET: Sync TXT support with reality * Fix the fixed unit tests Co-authored-by: Burak Tamturk <buraktamturk@gmail.com>
This commit is contained in:
parent
eef8c25a95
commit
7f071b4ce8
3 changed files with 21 additions and 37 deletions
|
@ -9,25 +9,10 @@ import (
|
|||
// supportable by this provider.
|
||||
func AuditRecords(records []*models.RecordConfig) error {
|
||||
|
||||
// if err := recordaudit.TxtNoLongStrings(records); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// Not needed as of 2021-03-26
|
||||
|
||||
if err := recordaudit.TxtNoMultipleStrings(records); err != nil {
|
||||
return err
|
||||
}
|
||||
// Still needed as of 2021-03-07
|
||||
|
||||
if err := recordaudit.TxtNotEmpty(records); err != nil {
|
||||
return err
|
||||
}
|
||||
// Still needed as of 2021-03-01
|
||||
|
||||
if err := recordaudit.TxtNoTrailingSpace(records); err != nil {
|
||||
return err
|
||||
}
|
||||
// Still needed as of 2021-03-01
|
||||
// Still needed as of 2021-10-01
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/StackExchange/dnscontrol/v3/models"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
|
||||
"github.com/StackExchange/dnscontrol/v3/pkg/txtutil"
|
||||
)
|
||||
|
||||
// HXRecord covers an individual DNS resource record.
|
||||
|
@ -69,6 +70,7 @@ func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Corr
|
|||
|
||||
// Normalize
|
||||
models.PostProcessRecords(actual)
|
||||
txtutil.SplitSingleLongTxt(dc.Records)
|
||||
|
||||
differ := diff.New(dc)
|
||||
_, create, del, mod, err := differ.IncrementalDiff(actual)
|
||||
|
@ -276,15 +278,12 @@ func (n *HXClient) deleteRecordString(record *HXRecord, domain string) string {
|
|||
|
||||
// encodeTxt encodes TxtStrings for sending in the CREATE/MODIFY API:
|
||||
func encodeTxt(txts []string) string {
|
||||
ans := txts[0]
|
||||
|
||||
if len(txts) > 1 {
|
||||
ans = ""
|
||||
for _, t := range txts {
|
||||
ans += `"` + strings.Replace(t, `"`, `\"`, -1) + `"`
|
||||
}
|
||||
var r []string
|
||||
for _, txt := range txts {
|
||||
n := `"` + strings.Replace(txt, `"`, `\"`, -1) + `"`
|
||||
r = append(r, n)
|
||||
}
|
||||
return ans
|
||||
return strings.Join(r, " ")
|
||||
}
|
||||
|
||||
// finds a string surrounded by quotes that might contain an escaped quote character.
|
||||
|
|
|
@ -9,16 +9,16 @@ var txtData = []struct {
|
|||
decoded []string
|
||||
encoded string
|
||||
}{
|
||||
{[]string{`simple`}, `simple`},
|
||||
{[]string{`changed`}, `changed`},
|
||||
{[]string{`with spaces`}, `with spaces`},
|
||||
{[]string{`with whitespace`}, `with whitespace`},
|
||||
{[]string{"one", "two"}, `"one""two"`},
|
||||
{[]string{"eh", "bee", "cee"}, `"eh""bee""cee"`},
|
||||
{[]string{"o\"ne", "tw\"o"}, `"o\"ne""tw\"o"`},
|
||||
{[]string{"dimple"}, `dimple`},
|
||||
{[]string{"fun", "two"}, `"fun""two"`},
|
||||
{[]string{"eh", "bzz", "cee"}, `"eh""bzz""cee"`},
|
||||
{[]string{`simple`}, `"simple"`},
|
||||
{[]string{`changed`}, `"changed"`},
|
||||
{[]string{`with spaces`}, `"with spaces"`},
|
||||
{[]string{`with whitespace`}, `"with whitespace"`},
|
||||
{[]string{"one", "two"}, `"one" "two"`},
|
||||
{[]string{"eh", "bee", "cee"}, `"eh" "bee" "cee"`},
|
||||
{[]string{"o\"ne", "tw\"o"}, `"o\"ne" "tw\"o"`},
|
||||
{[]string{"dimple"}, `"dimple"`},
|
||||
{[]string{"fun", "two"}, `"fun" "two"`},
|
||||
{[]string{"eh", "bzz", "cee"}, `"eh" "bzz" "cee"`},
|
||||
}
|
||||
|
||||
func TestEncodeTxt(t *testing.T) {
|
||||
|
@ -26,7 +26,7 @@ func TestEncodeTxt(t *testing.T) {
|
|||
for i, test := range txtData {
|
||||
enc := encodeTxt(test.decoded)
|
||||
if enc != test.encoded {
|
||||
t.Errorf("%v: txt\n data: []string{%v}\nexpected: %s\n got: %s",
|
||||
t.Errorf("%v: txt\n data: []string{%v}\nexpected: %q\n got: %q",
|
||||
i, "`"+strings.Join(test.decoded, "`, `")+"`", test.encoded, enc)
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,11 @@ func TestDecodeTxt(t *testing.T) {
|
|||
got := decodeTxt(data)
|
||||
wanted := test.decoded
|
||||
if len(got) != len(wanted) {
|
||||
t.Errorf("%v: txt\n decode: %v\nexpected: `%v`\n got: `%v`\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
|
||||
t.Errorf("%v: txt\n decode: %v\nexpected: %q\n got: %q\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
|
||||
} else {
|
||||
for j := range got {
|
||||
if got[j] != wanted[j] {
|
||||
t.Errorf("%v: txt\n decode: %v\nexpected: `%v`\n got: `%v`\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
|
||||
t.Errorf("%v: txt\n decode: %v\nexpected: %q\n got: %q\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue