diff --git a/command/agent/user_event.go b/command/agent/user_event.go index d019a310a6..184e3eab78 100644 --- a/command/agent/user_event.go +++ b/command/agent/user_event.go @@ -85,16 +85,15 @@ func (a *Agent) UserEvent(dc, token string, params *UserEvent) error { return fmt.Errorf("UserEvent encoding failed: %v", err) } - // Send an RPC to service this + // Service the event fire over RPC. This ensures that we authorize + // the request against the token first. args := structs.EventFireRequest{ - Datacenter: dc, - Name: params.Name, - Payload: payload, + Datacenter: dc, + Name: params.Name, + Payload: payload, + QueryOptions: structs.QueryOptions{Token: token}, } - // Pass along the ACL token, if any - args.Token = token - // Any server can process in the remote DC, since the // gossip will take over anyways args.AllowStale = true diff --git a/consul/client.go b/consul/client.go index 8089bb4621..35b77445ed 100644 --- a/consul/client.go +++ b/consul/client.go @@ -201,11 +201,6 @@ func (c *Client) RemoveFailedNode(node string) error { return c.serf.RemoveFailedNode(node) } -// UserEvent is used to fire an event via the Serf layer -func (c *Client) UserEvent(name string, payload []byte) error { - return c.serf.UserEvent(userEventName(name), payload, false) -} - // KeyManagerLAN returns the LAN Serf keyring manager func (c *Client) KeyManagerLAN() *serf.KeyManager { return c.serf.KeyManager() diff --git a/consul/client_test.go b/consul/client_test.go index c799696abc..b650b83725 100644 --- a/consul/client_test.go +++ b/consul/client_test.go @@ -276,26 +276,18 @@ func TestClientServer_UserEvent(t *testing.T) { }) // Fire the user event - err := c1.UserEvent("foo", []byte("bar")) - if err != nil { - t.Fatalf("err: %v", err) - } - - err = s1.UserEvent("bar", []byte("baz")) - if err != nil { + if err := s1.UserEvent("foo", []byte("baz")); err != nil { t.Fatalf("err: %v", err) } // Wait for all the events - var serverFoo, serverBar, clientFoo, clientBar bool - for i := 0; i < 4; i++ { + var clientReceived, serverReceived bool + for i := 0; i < 2; i++ { select { case e := <-clientOut: switch e.Name { case "foo": - clientFoo = true - case "bar": - clientBar = true + clientReceived = true default: t.Fatalf("Bad: %#v", e) } @@ -303,9 +295,7 @@ func TestClientServer_UserEvent(t *testing.T) { case e := <-serverOut: switch e.Name { case "foo": - serverFoo = true - case "bar": - serverBar = true + serverReceived = true default: t.Fatalf("Bad: %#v", e) } @@ -315,7 +305,7 @@ func TestClientServer_UserEvent(t *testing.T) { } } - if !(serverFoo && serverBar && clientFoo && clientBar) { + if !serverReceived || !clientReceived { t.Fatalf("missing events") } }