mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-09 08:07:01 +02:00
Biggest change: we rename `Send` to `SendEvent` in `logical.EventSender`.. Initially we picked `Send` to match the underlying go-eventlogger broker's `Send` method, and to avoid the stuttering of `events.SendEvent`. However, I think it is more useful for the `logical.EventSender` interface to use the method `SendEvent` so that, for example, `framework.Backend` can implement it. This is a relatively change now that should not affect anything except the KV plugin, which is being fixed in another PR. Another change: if the `secret_path` metadata is present, then the plugin-aware `EventBus` will prepend it with the plugin mount. This allows the `secret_path` to be the full path to any referenced secret. This change is also backwards compatible, since this field was not present in the KV plugin. (It did use the slightly different `path` field, which we can keep for now.)
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package logical
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type fakeSender struct {
|
|
captured *EventData
|
|
}
|
|
|
|
func (f *fakeSender) SendEvent(ctx context.Context, eventType EventType, event *EventData) error {
|
|
f.captured = event
|
|
return nil
|
|
}
|
|
|
|
// TestSendEventWithOddParametersAddsExtraMetadata tests that an extra parameter is added to the metadata
|
|
// with a special key to note that it was extra.
|
|
func TestSendEventWithOddParametersAddsExtraMetadata(t *testing.T) {
|
|
sender := &fakeSender{}
|
|
// 0 or 2 arguments are okay
|
|
err := SendEvent(context.Background(), sender, "foo")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m := sender.captured.Metadata.AsMap()
|
|
assert.NotContains(t, m, extraMetadataArgument)
|
|
err = SendEvent(context.Background(), sender, "foo", "bar", "baz")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m = sender.captured.Metadata.AsMap()
|
|
assert.NotContains(t, m, extraMetadataArgument)
|
|
|
|
// 1 or 3 arguments should give result in extraMetadataArgument in metadata
|
|
err = SendEvent(context.Background(), sender, "foo", "extra")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m = sender.captured.Metadata.AsMap()
|
|
assert.Contains(t, m, extraMetadataArgument)
|
|
assert.Equal(t, "extra", m[extraMetadataArgument])
|
|
|
|
err = SendEvent(context.Background(), sender, "foo", "bar", "baz", "extra")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m = sender.captured.Metadata.AsMap()
|
|
assert.Contains(t, m, extraMetadataArgument)
|
|
assert.Equal(t, "extra", m[extraMetadataArgument])
|
|
}
|