-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(endpoint): reject alias property on unsupported record types #6188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1d536e5
520cf59
c6c1eae
d596421
c8db779
825031c
0c335bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,11 @@ package endpoint | |
| import ( | ||
| "fmt" | ||
| "reflect" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
| "github.com/sirupsen/logrus/hooks/test" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "sigs.k8s.io/external-dns/pkg/events" | ||
|
|
@@ -939,6 +942,95 @@ func TestCheckEndpoint(t *testing.T) { | |
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| description: "A record with alias=true is valid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeA, | ||
| Targets: Targets{"my-elb-123.us-east-1.elb.amazonaws.com"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| description: "AAAA record with alias=true is valid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeAAAA, | ||
| Targets: Targets{"dualstack.my-elb-123.us-east-1.elb.amazonaws.com"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| description: "CNAME record with alias=true is valid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeCNAME, | ||
| Targets: Targets{"d111111abcdef8.cloudfront.net"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| description: "MX record with alias=true is invalid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeMX, | ||
| Targets: Targets{"10 mail.example.com"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| description: "TXT record with alias=true is invalid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeTXT, | ||
| Targets: Targets{"v=spf1 ~all"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| description: "NS record with alias=true is invalid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeNS, | ||
| Targets: Targets{"ns1.example.com"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| description: "SRV record with alias=true is invalid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "_sip._tcp.example.com", | ||
| RecordType: RecordTypeSRV, | ||
| Targets: Targets{"10 5 5060 sip.example.com."}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| expected: false, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. false is default
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you clarify what you mean by "false is default"?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do not need explicit false, as its a default value |
||
| }, | ||
| { | ||
| description: "MX record with alias=false is also invalid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeMX, | ||
| Targets: Targets{"10 mail.example.com"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "false"}}, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| description: "MX record without alias property is valid", | ||
| endpoint: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeMX, | ||
| Targets: Targets{"10 mail.example.com"}, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
|
|
@@ -949,6 +1041,69 @@ func TestCheckEndpoint(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestCheckEndpoint_AliasWarningLog(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| ep Endpoint | ||
| wantLog bool | ||
| }{ | ||
| { | ||
| name: "unsupported type with alias logs warning", | ||
| ep: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeMX, | ||
| Targets: Targets{"10 mail.example.com"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| wantLog: true, | ||
| }, | ||
| { | ||
| name: "supported type with alias does not log", | ||
| ep: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeA, | ||
| Targets: Targets{"my-elb-123.us-east-1.elb.amazonaws.com"}, | ||
| ProviderSpecific: ProviderSpecific{{Name: providerSpecificAlias, Value: "true"}}, | ||
| }, | ||
| wantLog: false, | ||
| }, | ||
| { | ||
| name: "unsupported type without alias does not log", | ||
| ep: Endpoint{ | ||
| DNSName: "example.com", | ||
| RecordType: RecordTypeMX, | ||
| Targets: Targets{"10 mail.example.com"}, | ||
| }, | ||
| wantLog: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| logger, hook := test.NewNullLogger() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure to use shared construct. let's not create for every test a solution
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, it’s difficult to use a shared construct due to circular dependencies.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
| log.AddHook(hook) | ||
| log.SetOutput(logger.Out) | ||
| log.SetLevel(log.WarnLevel) | ||
|
|
||
| tt.ep.CheckEndpoint() | ||
|
|
||
| warnMsg := "does not support alias records" | ||
| found := false | ||
| for _, entry := range hook.AllEntries() { | ||
| if strings.Contains(entry.Message, warnMsg) && entry.Level == log.WarnLevel { | ||
| found = true | ||
| } | ||
| } | ||
|
|
||
| if tt.wantLog { | ||
| assert.True(t, found, "Expected warning log message not found") | ||
| } else { | ||
| assert.False(t, found, "Unexpected warning log message found") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestEndpoint_WithRefObject(t *testing.T) { | ||
| ep := &Endpoint{} | ||
| ref := &events.ObjectReference{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most likely too long, but not an issue. You not using this constant in tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed it.