mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
fix test
This commit is contained in:
@ -74,6 +74,14 @@ func (rc *RecordConfig) zoneFileQuoted() string {
|
|||||||
return full[len(header):]
|
return full[len(header):]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTargetRFC1035Quoted returns the target as it would be in an
|
||||||
|
// RFC1035-style zonefile.
|
||||||
|
// Do not use this function if RecordConfig might be a pseudo-rtype
|
||||||
|
// such as R53_ALIAS. Use GetTargetCombined() instead.
|
||||||
|
func (rc *RecordConfig) GetTargetRFC1035Quoted() string {
|
||||||
|
return rc.zoneFileQuoted()
|
||||||
|
}
|
||||||
|
|
||||||
// GetTargetDebug returns a string with the various fields spelled out.
|
// GetTargetDebug returns a string with the various fields spelled out.
|
||||||
func (rc *RecordConfig) GetTargetDebug() string {
|
func (rc *RecordConfig) GetTargetDebug() string {
|
||||||
target := rc.target
|
target := rc.target
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
// TxtHasBackslash audits TXT records for strings that contains one or more backslashes.
|
// TxtHasBackslash audits TXT records for strings that contains one or more backslashes.
|
||||||
func TxtHasBackslash(rc *models.RecordConfig) error {
|
func TxtHasBackslash(rc *models.RecordConfig) error {
|
||||||
if strings.Contains(rc.GetTargetField(), `\`) {
|
if strings.Contains(rc.GetTargetTXTJoined(), `\`) {
|
||||||
return fmt.Errorf("txtstring contains backslashes")
|
return fmt.Errorf("txtstring contains backslashes")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -19,7 +19,7 @@ func TxtHasBackslash(rc *models.RecordConfig) error {
|
|||||||
|
|
||||||
// TxtHasBackticks audits TXT records for strings that contain backticks.
|
// TxtHasBackticks audits TXT records for strings that contain backticks.
|
||||||
func TxtHasBackticks(rc *models.RecordConfig) error {
|
func TxtHasBackticks(rc *models.RecordConfig) error {
|
||||||
if strings.Contains(rc.GetTargetField(), "`") {
|
if strings.Contains(rc.GetTargetTXTJoined(), "`") {
|
||||||
return fmt.Errorf("txtstring contains backtick")
|
return fmt.Errorf("txtstring contains backtick")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -27,7 +27,7 @@ func TxtHasBackticks(rc *models.RecordConfig) error {
|
|||||||
|
|
||||||
// TxtHasDoubleQuotes audits TXT records for strings that contain doublequotes.
|
// TxtHasDoubleQuotes audits TXT records for strings that contain doublequotes.
|
||||||
func TxtHasDoubleQuotes(rc *models.RecordConfig) error {
|
func TxtHasDoubleQuotes(rc *models.RecordConfig) error {
|
||||||
if strings.Contains(rc.GetTargetField(), `"`) {
|
if strings.Contains(rc.GetTargetTXTJoined(), `"`) {
|
||||||
return fmt.Errorf("txtstring contains doublequotes")
|
return fmt.Errorf("txtstring contains doublequotes")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -35,7 +35,7 @@ func TxtHasDoubleQuotes(rc *models.RecordConfig) error {
|
|||||||
|
|
||||||
// TxtHasSegmentLen256orLonger audits TXT records for strings that are >255 octets.
|
// TxtHasSegmentLen256orLonger audits TXT records for strings that are >255 octets.
|
||||||
func TxtHasSegmentLen256orLonger(rc *models.RecordConfig) error {
|
func TxtHasSegmentLen256orLonger(rc *models.RecordConfig) error {
|
||||||
if len(rc.GetTargetField()) > 255 {
|
if len(rc.GetTargetTXTJoined()) > 255 {
|
||||||
return fmt.Errorf("%q txtstring length > 255", rc.GetLabel())
|
return fmt.Errorf("%q txtstring length > 255", rc.GetLabel())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -43,15 +43,23 @@ func TxtHasSegmentLen256orLonger(rc *models.RecordConfig) error {
|
|||||||
|
|
||||||
// TxtHasSingleQuotes audits TXT records for strings that contain single-quotes.
|
// TxtHasSingleQuotes audits TXT records for strings that contain single-quotes.
|
||||||
func TxtHasSingleQuotes(rc *models.RecordConfig) error {
|
func TxtHasSingleQuotes(rc *models.RecordConfig) error {
|
||||||
if strings.Contains(rc.GetTargetField(), "'") {
|
if strings.Contains(rc.GetTargetTXTJoined(), "'") {
|
||||||
return fmt.Errorf("txtstring contains single-quotes")
|
return fmt.Errorf("txtstring contains single-quotes")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TxtHasMultipleSegments audits TXT records for multiple strings
|
||||||
|
func TxtHasMultipleSegments(rc *models.RecordConfig) error {
|
||||||
|
if len(rc.GetTargetTXTSegmented()) > 1 {
|
||||||
|
return fmt.Errorf("multiple strings in one txt")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// TxtHasTrailingSpace audits TXT records for strings that end with space.
|
// TxtHasTrailingSpace audits TXT records for strings that end with space.
|
||||||
func TxtHasTrailingSpace(rc *models.RecordConfig) error {
|
func TxtHasTrailingSpace(rc *models.RecordConfig) error {
|
||||||
txt := rc.GetTargetField()
|
txt := rc.GetTargetTXTJoined()
|
||||||
if txt != "" && txt[ultimate(txt)] == ' ' {
|
if txt != "" && txt[ultimate(txt)] == ' ' {
|
||||||
return fmt.Errorf("txtstring ends with space")
|
return fmt.Errorf("txtstring ends with space")
|
||||||
}
|
}
|
||||||
@ -60,7 +68,7 @@ func TxtHasTrailingSpace(rc *models.RecordConfig) error {
|
|||||||
|
|
||||||
// TxtHasUnpairedDoubleQuotes audits TXT records for strings that contain unpaired doublequotes.
|
// TxtHasUnpairedDoubleQuotes audits TXT records for strings that contain unpaired doublequotes.
|
||||||
func TxtHasUnpairedDoubleQuotes(rc *models.RecordConfig) error {
|
func TxtHasUnpairedDoubleQuotes(rc *models.RecordConfig) error {
|
||||||
if strings.Count(rc.GetTargetField(), `"`)%2 == 1 {
|
if strings.Count(rc.GetTargetTXTJoined(), `"`)%2 == 1 {
|
||||||
return fmt.Errorf("txtstring contains unpaired doublequotes")
|
return fmt.Errorf("txtstring contains unpaired doublequotes")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -68,7 +76,7 @@ func TxtHasUnpairedDoubleQuotes(rc *models.RecordConfig) error {
|
|||||||
|
|
||||||
// TxtIsEmpty audits TXT records for empty strings.
|
// TxtIsEmpty audits TXT records for empty strings.
|
||||||
func TxtIsEmpty(rc *models.RecordConfig) error {
|
func TxtIsEmpty(rc *models.RecordConfig) error {
|
||||||
if len(rc.GetTargetField()) == 0 {
|
if len(rc.GetTargetTXTJoined()) == 0 {
|
||||||
return fmt.Errorf("txtstring is empty")
|
return fmt.Errorf("txtstring is empty")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -77,7 +85,7 @@ func TxtIsEmpty(rc *models.RecordConfig) error {
|
|||||||
// TxtIsExactlyLen255 audits TXT records for strings exactly 255 octets long.
|
// TxtIsExactlyLen255 audits TXT records for strings exactly 255 octets long.
|
||||||
// This is rare; you probably want to use TxtNoStringsLen256orLonger() instead.
|
// This is rare; you probably want to use TxtNoStringsLen256orLonger() instead.
|
||||||
func TxtIsExactlyLen255(rc *models.RecordConfig) error {
|
func TxtIsExactlyLen255(rc *models.RecordConfig) error {
|
||||||
if len(rc.GetTargetField()) == 255 {
|
if len(rc.GetTargetTXTJoined()) == 255 {
|
||||||
return fmt.Errorf("txtstring length is 255")
|
return fmt.Errorf("txtstring length is 255")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -85,7 +93,7 @@ func TxtIsExactlyLen255(rc *models.RecordConfig) error {
|
|||||||
|
|
||||||
// TxtLongerThan255 audits TXT records for multiple strings
|
// TxtLongerThan255 audits TXT records for multiple strings
|
||||||
func TxtLongerThan255(rc *models.RecordConfig) error {
|
func TxtLongerThan255(rc *models.RecordConfig) error {
|
||||||
if len(rc.GetTargetField()) > 255 {
|
if len(rc.GetTargetTXTJoined()) > 255 {
|
||||||
return fmt.Errorf("multiple strings in one txt")
|
return fmt.Errorf("multiple strings in one txt")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v4/models"
|
"github.com/StackExchange/dnscontrol/v4/models"
|
||||||
"github.com/StackExchange/dnscontrol/v4/pkg/diff"
|
"github.com/StackExchange/dnscontrol/v4/pkg/diff"
|
||||||
@ -237,7 +236,7 @@ func (c *desecProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, exist
|
|||||||
// However the code doesn't seem to have such situation. All tests
|
// However the code doesn't seem to have such situation. All tests
|
||||||
// pass. That said, if this breaks anything, the easiest fix might
|
// pass. That said, if this breaks anything, the easiest fix might
|
||||||
// be to just remove the sort.
|
// be to just remove the sort.
|
||||||
sort.Slice(corrections, func(i, j int) bool { return diff.CorrectionLess(corrections, i, j) })
|
//sort.Slice(corrections, func(i, j int) bool { return diff.CorrectionLess(corrections, i, j) })
|
||||||
|
|
||||||
return corrections, nil
|
return corrections, nil
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,8 @@ func TestToRecordConfig(t *testing.T) {
|
|||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "large.example.com", recordConfig.NameFQDN)
|
assert.Equal(t, "large.example.com", recordConfig.NameFQDN)
|
||||||
assert.Equal(t, largeContent, recordConfig.String())
|
assert.Equal(t, `"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"`,
|
||||||
|
recordConfig.String())
|
||||||
assert.Equal(t, uint32(5), recordConfig.TTL)
|
assert.Equal(t, uint32(5), recordConfig.TTL)
|
||||||
assert.Equal(t, "TXT", recordConfig.Type)
|
assert.Equal(t, "TXT", recordConfig.Type)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user