mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
reverse zone: fix Normalize (#4621)
Make normalize return multiple "hosts" (= reverse zones) when a non-octet boundary cidr is given. Added pkg/cidr package that holds the cidr calculation routines; felt they didn't really fit dnsutil. This change means the IPNet return parameter isn't needed, the hosts are all correct. The tests that tests this is also removed: TestSplitHostPortReverse The fallout was that zoneAddr _also_ doesn't need the IPNet member, that in turn make it visible that zoneAddr in address.go duplicated a bunch of stuff from register.go; removed/refactored that too. Created a plugin.OriginsFromArgsOrServerBlock to help plugins do the right things, by consuming ZONE arguments; this now expands reverse zones correctly. This is mostly mechanical. Remove the reverse test in plugin/kubernetes which is a copy-paste from a core test (which has since been fixed). Remove MustNormalize as it has no plugin users. This change is not backwards compatible to plugins that have a ZONE argument that they parse in the setup util. All in-tree plugins have been updated. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -2,83 +2,6 @@ package dnsserver
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeZone(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
input string
|
||||
expected string
|
||||
shouldErr bool
|
||||
}{
|
||||
{".", "dns://.:53", false},
|
||||
{".:54", "dns://.:54", false},
|
||||
{"..", "://:", true},
|
||||
{".:", "://:", true},
|
||||
{"dns://.", "dns://.:53", false},
|
||||
{"dns://.:5353", "dns://.:5353", false},
|
||||
{"dns://..", "://:", true},
|
||||
{"dns://.:", "://:", true},
|
||||
{"tls://.", "tls://.:853", false},
|
||||
{"tls://.:8953", "tls://.:8953", false},
|
||||
{"tls://..", "://:", true},
|
||||
{"tls://.:", "://:", true},
|
||||
{"grpc://.", "grpc://.:443", false},
|
||||
{"grpc://.:8443", "grpc://.:8443", false},
|
||||
{"grpc://..", "://:", true},
|
||||
{"grpc://.:", "://:", true},
|
||||
{"https://.", "https://.:443", false},
|
||||
{"https://.:8443", "https://.:8443", false},
|
||||
{"https://..", "://:", true},
|
||||
{"https://.:", "://:", true},
|
||||
} {
|
||||
addr, err := normalizeZone(test.input)
|
||||
actual := addr.String()
|
||||
if test.shouldErr && err == nil {
|
||||
t.Errorf("Test %d: Expected error, but there wasn't any", i)
|
||||
}
|
||||
if !test.shouldErr && err != nil {
|
||||
t.Errorf("Test %d: Expected no error, but there was one: %v", i, err)
|
||||
}
|
||||
if actual != test.expected {
|
||||
t.Errorf("Test %d: Expected %s but got %s", i, test.expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeZoneReverse(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
input string
|
||||
expected string
|
||||
shouldErr bool
|
||||
}{
|
||||
{"2003::1/64", "dns://0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.2.ip6.arpa.:53", false},
|
||||
{"2003::1/64.", "dns://2003::1/64.:53", false}, // OK, with closing dot the parse will fail.
|
||||
{"2003::1/64:53", "dns://0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.2.ip6.arpa.:53", false},
|
||||
{"2003::1/64.:53", "dns://2003::1/64.:53", false},
|
||||
|
||||
{"10.0.0.0/24", "dns://0.0.10.in-addr.arpa.:53", false},
|
||||
{"10.0.0.0/24.", "dns://10.0.0.0/24.:53", false},
|
||||
{"10.0.0.0/24:53", "dns://0.0.10.in-addr.arpa.:53", false},
|
||||
{"10.0.0.0/24.:53", "dns://10.0.0.0/24.:53", false},
|
||||
|
||||
// non %8==0 netmasks
|
||||
{"2003::53/67", "dns://0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.2.ip6.arpa.:53", false},
|
||||
{"10.0.0.0/25.", "dns://10.0.0.0/25.:53", false}, // has dot
|
||||
{"10.0.0.0/25", "dns://0.0.10.in-addr.arpa.:53", false},
|
||||
{"fd00:77:30::0/110", "dns://0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.7.7.0.0.0.0.d.f.ip6.arpa.:53", false},
|
||||
} {
|
||||
addr, err := normalizeZone(test.input)
|
||||
actual := addr.String()
|
||||
if test.shouldErr && err == nil {
|
||||
t.Errorf("Test %d: Expected error, but there wasn't any", i)
|
||||
}
|
||||
if !test.shouldErr && err != nil {
|
||||
t.Errorf("Test %d: Expected no error, but there was one: %v", i, err)
|
||||
}
|
||||
if actual != test.expected {
|
||||
t.Errorf("Test %d: Expected %s but got %s", i, test.expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitProtocolHostPort(t *testing.T) {
|
||||
for i, test := range []struct {
|
||||
input string
|
||||
|
||||
Reference in New Issue
Block a user