1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

VULTR: Fix TXT quoting issue (#1239)

* VULTR: Fix TXT quoting issue
* VULTR: Add tests that trigger Vultr's SPF mode
* VULTR: Enforce the fact that VULTR only supports a single string in TXT records

Co-authored-by: Lee Martin <lmartin@stackoverflow.com>
This commit is contained in:
Tom Limoncelli
2021-08-17 15:58:10 -04:00
committed by GitHub
parent b6779adf92
commit 0203154021
3 changed files with 21 additions and 2 deletions

View File

@@ -789,6 +789,12 @@ func makeTests(t *testing.T) []*TestGroup {
tc("Create a TXT with spaces", txt("foo", "with spaces")),
),
testgroup("simple TXT-spf1",
// This was added because Vultr syntax-checks TXT records with
// SPF contents.
tc("Create a TXT/SPF", txt("foo", "v=spf1 ip4:99.99.99.99 -all")),
),
testgroup("long TXT",
tc("Create long TXT", txt("foo", strings.Repeat("A", 300))),
tc("Change long TXT", txt("foo", strings.Repeat("B", 310))),

View File

@@ -16,5 +16,9 @@ func AuditRecords(records []*models.RecordConfig) error {
}
// Still needed as of 2021-03-02
if err := recordaudit.TxtNoMultipleStrings(records); err != nil {
return err
}
return nil
}

View File

@@ -200,8 +200,12 @@ func toRecordConfig(domain string, r *govultr.DNSRecord) (*models.RecordConfig,
// Vultr returns SRV records in the format "[weight] [port] [target]".
return rc, rc.SetTargetSRVPriorityString(uint16(vultrPriority(r)), data)
case "TXT":
// Remove quotes if it is a TXT record.
if !strings.HasPrefix(data, `"`) || !strings.HasSuffix(data, `"`) {
// TXT records from Vultr are always surrounded by quotes.
// They don't permit quotes within the string, therefore there is no
// need to resolve \" or other quoting.
if !(strings.HasPrefix(data, `"`) && strings.HasSuffix(data, `"`)) {
// Give an error if Vultr changes their protocol. We'd rather break
// than do the wrong thing.
return nil, errors.New("unexpected lack of quotes in TXT record from Vultr")
}
return rc, rc.SetTargetTXT(data[1 : len(data)-1])
@@ -251,6 +255,11 @@ func toVultrRecord(dc *models.DomainConfig, rc *models.RecordConfig, vultrID int
r.Data = fmt.Sprintf(`%v %s "%s"`, rc.CaaFlag, rc.CaaTag, rc.GetTargetField())
case "SSHFP":
r.Data = fmt.Sprintf("%d %d %s", rc.SshfpAlgorithm, rc.SshfpFingerprint, rc.GetTargetField())
case "TXT":
// Vultr doesn't permit TXT strings to include double-quotes
// therefore, we don't have to escape interior double-quotes.
// Vultr's API requires the string to begin and end with double-quotes.
r.Data = `"` + strings.Join(rc.TxtStrings, "") + `"`
default:
}