diff --git a/internal/listener/hashivault/listener.go b/internal/listener/hashivault/listener.go index 933c527..a5d29c4 100644 --- a/internal/listener/hashivault/listener.go +++ b/internal/listener/hashivault/listener.go @@ -42,8 +42,7 @@ func (h *HashicorpVault) processFn(message []byte) { // Removing "data" if any path := strings.TrimPrefix(strings.Split(msg.AuthRequest.Path, basePath)[1], "data/") switch msg.AuthRequest.Operation { - case "create": - case "update": + case "create", "update": h.logger.V(1).Info("Received Valid Message", "Message", msg) event := events.SecretRotationEvent{ SecretIdentifier: path, diff --git a/internal/listener/hashivault/listener_test.go b/internal/listener/hashivault/listener_test.go new file mode 100644 index 0000000..4035b5a --- /dev/null +++ b/internal/listener/hashivault/listener_test.go @@ -0,0 +1,32 @@ +package hashivault + +import ( + "context" + "testing" + + "github.com/external-secrets/reloader/internal/events" + "github.com/go-logr/logr" +) + +func TestProcessKVCreateEvent(t *testing.T) { + eventChan := make(chan events.SecretRotationEvent, 1) + listener := &HashicorpVault{ + context: context.Background(), + eventChan: eventChan, + logger: logr.Discard(), + } + listener.processFn([]byte(`{ + "type": "response", + "request": {"operation": "create", "path": "secret/data/apps/example/api-key"}, + "response": {"mount_type": "kv", "mount_point": "secret/"} + }`)) + + select { + case event := <-eventChan: + if event.SecretIdentifier != "apps/example/api-key" { + t.Errorf("unexpected secret identifier: %q", event.SecretIdentifier) + } + default: + t.Fatal("create operation did not emit a rotation event") + } +}