dns: fix data race in TestDNS_ServiceLookup_FilterACL

The agent config cannot be modified after start.
pull/3241/head
Frank Schroeder 2017-06-30 22:05:23 +02:00 committed by Frank Schröder
parent bcd2301b81
commit 00f6ba298e
1 changed files with 45 additions and 45 deletions

View File

@ -3615,7 +3615,17 @@ 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()
tests := []struct {
token string
results int
}{
{"root", 1},
{"anonymous", 0},
}
for _, tt := range tests {
t.Run("ACLToken == "+tt.token, func(t *testing.T) {
cfg := TestConfig() cfg := TestConfig()
cfg.ACLToken = tt.token
cfg.ACLMasterToken = "root" cfg.ACLMasterToken = "root"
cfg.ACLDatacenter = "dc1" cfg.ACLDatacenter = "dc1"
cfg.ACLDownPolicy = "deny" cfg.ACLDownPolicy = "deny"
@ -3645,24 +3655,14 @@ func TestDNS_ServiceLookup_FilterACL(t *testing.T) {
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.
a.Config.ACLToken = "root"
in, _, err := c.Exchange(m, addr.String()) in, _, err := c.Exchange(m, addr.String())
if err != nil { if err != nil {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
if len(in.Answer) != 1 { if len(in.Answer) != tt.results {
t.Fatalf("Bad: %#v", in) 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)
} }
} }