mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-04 20:06:27 +02:00
Fixes events subscribe for non-root namespaces (#22580)
* Fixes events subscribe for non-root namespaces * Adds a test
This commit is contained in:
parent
4264c5a262
commit
36174bc913
@ -202,7 +202,7 @@ func NewEventBus(logger hclog.Logger) (*EventBus, error) {
|
||||
}
|
||||
|
||||
func (bus *EventBus) Subscribe(ctx context.Context, ns *namespace.Namespace, pattern string) (<-chan *eventlogger.Event, context.CancelFunc, error) {
|
||||
return bus.SubscribeMultipleNamespaces(ctx, []string{ns.Path}, pattern)
|
||||
return bus.SubscribeMultipleNamespaces(ctx, []string{strings.Trim(ns.Path, "/")}, pattern)
|
||||
}
|
||||
|
||||
func (bus *EventBus) SubscribeMultipleNamespaces(ctx context.Context, namespacePathPatterns []string, pattern string) (<-chan *eventlogger.Event, context.CancelFunc, error) {
|
||||
|
||||
@ -73,6 +73,50 @@ func TestBusBasics(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSubscribeNonRootNamespace verifies that events for non-root namespaces
|
||||
// aren't filtered out by the bus.
|
||||
func TestSubscribeNonRootNamespace(t *testing.T) {
|
||||
bus, err := NewEventBus(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bus.Start()
|
||||
ctx := context.Background()
|
||||
|
||||
eventType := logical.EventType("someType")
|
||||
|
||||
ns := &namespace.Namespace{
|
||||
ID: "abc",
|
||||
Path: "abc/",
|
||||
}
|
||||
|
||||
ch, cancel, err := bus.Subscribe(ctx, ns, string(eventType))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
event, err := logical.NewEvent()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = bus.SendEventInternal(ctx, ns, nil, eventType, event)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
timeout := time.After(1 * time.Second)
|
||||
select {
|
||||
case message := <-ch:
|
||||
if message.Payload.(*logical.EventReceived).Event.Id != event.Id {
|
||||
t.Errorf("Got unexpected message: %+v", message)
|
||||
}
|
||||
case <-timeout:
|
||||
t.Error("Timeout waiting for message")
|
||||
}
|
||||
}
|
||||
|
||||
// TestNamespaceFiltering verifies that events for other namespaces are filtered out by the bus.
|
||||
func TestNamespaceFiltering(t *testing.T) {
|
||||
bus, err := NewEventBus(nil)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user