diff --git a/agent/dns_test.go b/agent/dns_test.go index 1df0c4d9db..a5aa787c4b 100644 --- a/agent/dns_test.go +++ b/agent/dns_test.go @@ -5790,15 +5790,17 @@ func TestDNS_AddressLookupIPV6(t *testing.T) { } } -func TestDNS_NonExistingDC(t *testing.T) { +// TestDNS_NonExistentDC_Server verifies NXDOMAIN is returned when +// Consul server agent is queried for a service in a non-existent +// domain. +func TestDNS_NonExistentDC_Server(t *testing.T) { t.Parallel() a := NewTestAgent(t, "") defer a.Shutdown() testrpc.WaitForLeader(t, a.RPC, "dc1") - // lookup a non-existing node, we should receive a SOA m := new(dns.Msg) - m.SetQuestion("consul.dc2.consul.", dns.TypeANY) + m.SetQuestion("consul.service.dc2.consul.", dns.TypeANY) c := new(dns.Client) in, _, err := c.Exchange(m, a.DNSAddr()) @@ -5811,6 +5813,47 @@ func TestDNS_NonExistingDC(t *testing.T) { } } +// TestDNS_NonExistentDC_RPC verifies NXDOMAIN is returned when +// Consul server agent is queried over RPC by a non-server agent +// for a service in a non-existent domain +func TestDNS_NonExistentDC_RPC(t *testing.T) { + t.Parallel() + s := NewTestAgent(t, ` + node_name = "test-server" + `) + + defer s.Shutdown() + c := NewTestAgent(t, ` + node_name = "test-client" + bootstrap = false + server = false + `) + defer c.Shutdown() + testrpc.WaitForLeader(t, s.RPC, "dc1") + + // Join LAN cluster + addr := fmt.Sprintf("127.0.0.1:%d", s.Config.SerfPortLAN) + _, err := c.JoinLAN([]string{addr}) + require.NoError(t, err) + retry.Run(t, func(r *retry.R) { + require.Len(r, s.LANMembers(), 2) + require.Len(r, c.LANMembers(), 2) + }) + + m := new(dns.Msg) + m.SetQuestion("consul.service.dc2.consul.", dns.TypeANY) + + d := new(dns.Client) + in, _, err := d.Exchange(m, c.DNSAddr()) + if err != nil { + t.Fatalf("err: %v", err) + } + + if in.Rcode != dns.RcodeNameError { + t.Fatalf("Expected RCode: %#v, had: %#v", dns.RcodeNameError, in.Rcode) + } +} + func TestDNS_NonExistingLookup(t *testing.T) { t.Parallel() a := NewTestAgent(t, "")