dns: fix data race in TestDNS_ServiceLookup_FilterACL

The agent config cannot be modified after start.
This commit is contained in:
Frank Schroeder 2017-06-30 22:05:23 +02:00 committed by Frank Schröder
parent 62b695fb17
commit 6715a7a0c2
1 changed files with 45 additions and 45 deletions

View File

@ -3615,54 +3615,54 @@ func TestDNS_ServiceLookup_SRV_RFC_TCP_Default(t *testing.T) {
func TestDNS_ServiceLookup_FilterACL(t *testing.T) { func TestDNS_ServiceLookup_FilterACL(t *testing.T) {
t.Parallel() t.Parallel()
cfg := TestConfig() tests := []struct {
cfg.ACLMasterToken = "root" token string
cfg.ACLDatacenter = "dc1" results int
cfg.ACLDownPolicy = "deny" }{
cfg.ACLDefaultPolicy = "deny" {"root", 1},
a := NewTestAgent(t.Name(), cfg) {"anonymous", 0},
defer a.Shutdown() }
for _, tt := range tests {
t.Run("ACLToken == "+tt.token, func(t *testing.T) {
cfg := TestConfig()
cfg.ACLToken = tt.token
cfg.ACLMasterToken = "root"
cfg.ACLDatacenter = "dc1"
cfg.ACLDownPolicy = "deny"
cfg.ACLDefaultPolicy = "deny"
a := NewTestAgent(t.Name(), cfg)
defer a.Shutdown()
// Register a service // Register a service
args := &structs.RegisterRequest{ args := &structs.RegisterRequest{
Datacenter: "dc1", Datacenter: "dc1",
Node: "foo", Node: "foo",
Address: "127.0.0.1", Address: "127.0.0.1",
Service: &structs.NodeService{ Service: &structs.NodeService{
Service: "foo", Service: "foo",
Port: 12345, Port: 12345,
}, },
WriteRequest: structs.WriteRequest{Token: "root"}, WriteRequest: structs.WriteRequest{Token: "root"},
} }
var out struct{} var out struct{}
if err := a.RPC("Catalog.Register", args, &out); err != nil { if err := a.RPC("Catalog.Register", args, &out); err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
// Set up the DNS query // Set up the DNS query
c := new(dns.Client) c := new(dns.Client)
addr, _ := a.Config.ClientListener("", a.Config.Ports.DNS) addr, _ := a.Config.ClientListener("", a.Config.Ports.DNS)
m := new(dns.Msg) m := new(dns.Msg)
m.SetQuestion("foo.service.consul.", dns.TypeA) m.SetQuestion("foo.service.consul.", dns.TypeA)
// Query with the root token. Should get results. in, _, err := c.Exchange(m, addr.String())
a.Config.ACLToken = "root" if err != nil {
in, _, err := c.Exchange(m, addr.String()) t.Fatalf("err: %v", err)
if err != nil { }
t.Fatalf("err: %v", err) if len(in.Answer) != tt.results {
} t.Fatalf("Bad: %#v", in)
if len(in.Answer) != 1 { }
t.Fatalf("Bad: %#v", in) })
}
// Query with a non-root token without access. Should get nothing.
a.Config.ACLToken = "anonymous"
in, _, err = c.Exchange(m, addr.String())
if err != nil {
t.Fatalf("err: %v", err)
}
if len(in.Answer) != 0 {
t.Fatalf("Bad: %#v", in)
} }
} }