chore: add tests for case-insensitive TXT prefix

This commit is contained in:
Martin Linkhorst 2019-07-31 11:55:43 +02:00
parent d7516a2580
commit 1cdb941d88
2 changed files with 9 additions and 8 deletions

View File

@ -196,17 +196,12 @@ type prefixNameMapper struct {
var _ nameMapper = prefixNameMapper{}
func newPrefixNameMapper(prefix string) prefixNameMapper {
return prefixNameMapper{prefix: prefix}
return prefixNameMapper{prefix: strings.ToLower(prefix)}
}
func (pr prefixNameMapper) toEndpointName(txtDNSName string) string {
log.Debugf("TXT record is %s", txtDNSName)
log.Debugf("Prefix is %s", pr.prefix)
prefixLower := strings.ToLower(pr.prefix)
if strings.HasPrefix(txtDNSName, prefixLower) {
log.Debug("Will trim prefix")
log.Debug(strings.TrimPrefix(txtDNSName, prefixLower))
return strings.TrimPrefix(txtDNSName, prefixLower)
if strings.HasPrefix(txtDNSName, pr.prefix) {
return strings.TrimPrefix(txtDNSName, pr.prefix)
}
return ""
}

View File

@ -136,6 +136,12 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
records, _ := r.Records()
assert.True(t, testutils.SameEndpoints(records, expectedRecords))
// Ensure prefix is case-insensitive
r, _ = NewTXTRegistry(p, "TxT.", "owner", time.Hour)
records, _ = r.Records()
assert.True(t, testutils.SameEndpoints(records, expectedRecords))
}
func testTXTRegistryRecordsNoPrefix(t *testing.T) {