mirror of https://github.com/status-im/consul.git
DNS: add test to verify NXDOMAIN is returned when a non-existent domain is queried over RPC
This commit is contained in:
parent
73e8face3c
commit
3b4ddaaab5
|
@ -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, "")
|
||||
|
|
Loading…
Reference in New Issue