consul: filter services by ACL when using ChecksInState.

pull/1140/head
Ryan Uber 2015-07-27 16:57:56 -07:00
parent a6317f2fb2
commit f2b71940f5
3 changed files with 32 additions and 1 deletions

View File

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

View File

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

View File

@ -316,3 +316,33 @@ func TestHealth_ServiceNodes_FilterACL(t *testing.T) {
t.Fatalf("bad: %#v", reply.Nodes) 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)
}
}