consul: filter services by ACL when using ChecksInState.

pull/1140/head
Ryan Uber 9 years ago
parent a6317f2fb2
commit f2b71940f5

@ -816,6 +816,7 @@ func testACLFilterServer(t *testing.T) (dir, token string, srv *Server, client *
CheckID: "service:foo",
Name: "service:foo",
ServiceID: "foo",
Status: structs.HealthPassing,
},
WriteRequest: structs.WriteRequest{Token: "root"},
}

@ -25,7 +25,7 @@ func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
state.QueryTables("ChecksInState"),
func() error {
reply.Index, reply.HealthChecks = state.ChecksInState(args.State)
return nil
return h.srv.filterACL(args.Token, reply)
})
}

@ -316,3 +316,33 @@ func TestHealth_ServiceNodes_FilterACL(t *testing.T) {
t.Fatalf("bad: %#v", reply.Nodes)
}
}
func TestHealth_ChecksInState_FilterACL(t *testing.T) {
dir, token, srv, client := testACLFilterServer(t)
defer os.RemoveAll(dir)
defer srv.Shutdown()
defer client.Close()
opt := structs.ChecksInStateRequest{
Datacenter: "dc1",
State: structs.HealthPassing,
QueryOptions: structs.QueryOptions{Token: token},
}
reply := structs.IndexedHealthChecks{}
if err := client.Call("Health.ChecksInState", &opt, &reply); err != nil {
t.Fatalf("err: %s", err)
}
found := false
for _, chk := range reply.HealthChecks {
switch chk.ServiceName {
case "foo":
found = true
case "bar":
t.Fatalf("bad service 'bar': %#v", reply.HealthChecks)
}
}
if !found {
t.Fatalf("missing service 'foo': %#v", reply.HealthChecks)
}
}

Loading…
Cancel
Save