mirror of
https://github.com/coredns/coredns.git
synced 2026-08-20 23:08:28 -04:00
core/dnsserver: normalize server block zones (#8320)
This commit is contained in:
@@ -100,7 +100,7 @@ func (h *dnsContext) InspectServerBlocks(_sourceFile string, serverBlocks []cadd
|
||||
}
|
||||
}
|
||||
for i := range hosts {
|
||||
zoneAddrs = append(zoneAddrs, zoneAddr{Zone: dns.Fqdn(hosts[i]), Port: port, Transport: trans})
|
||||
zoneAddrs = append(zoneAddrs, zoneAddr{Zone: plugin.Name(hosts[i]).Normalize(), Port: port, Transport: trans})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +143,19 @@ func TestInspectServerBlocks(t *testing.T) {
|
||||
"dns://example.org.:53": {Zone: "example.org.", Port: "53", Transport: "dns"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "uppercase dns",
|
||||
serverBlocks: []caddyfile.ServerBlock{
|
||||
{Keys: []string{"EXAMPLE.ORG"}},
|
||||
},
|
||||
expectedServerBlocks: []caddyfile.ServerBlock{
|
||||
{Keys: []string{"dns://example.org.:53"}},
|
||||
},
|
||||
expectedConfigsLen: 1,
|
||||
expectedZoneAddrs: map[string]zoneAddr{
|
||||
"dns://example.org.:53": {Zone: "example.org.", Port: "53", Transport: "dns"},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dns with port",
|
||||
serverBlocks: []caddyfile.ServerBlock{
|
||||
|
||||
@@ -2,6 +2,8 @@ package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// TestCorefileParsing tests the Corefile parsing functionality.
|
||||
@@ -61,3 +63,23 @@ acl
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUppercaseServerBlockZone(t *testing.T) {
|
||||
instance, udp, _, err := CoreDNSServerAndPorts(`EXAMPLE.ORG.:0 {
|
||||
whoami
|
||||
}`)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start CoreDNS: %v", err)
|
||||
}
|
||||
defer CoreDNSServerStop(instance)
|
||||
|
||||
query := new(dns.Msg)
|
||||
query.SetQuestion("www.example.org.", dns.TypeA)
|
||||
response, _, err := new(dns.Client).Exchange(query, udp)
|
||||
if err != nil {
|
||||
t.Fatalf("DNS exchange failed: %v", err)
|
||||
}
|
||||
if response.Rcode != dns.RcodeSuccess {
|
||||
t.Fatalf("expected response code %s, got %s", dns.RcodeToString[dns.RcodeSuccess], dns.RcodeToString[response.Rcode])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user