From f35c2eb837fae057f17d8a380f7382d9c8e9fafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sj=C3=B6din?= Date: Tue, 27 Oct 2026 13:40:25 +0100 Subject: [PATCH 1/2] Fix Vault create events being ignored MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sjödin --- internal/listener/hashivault/listener.go | 3 +- internal/listener/hashivault/listener_test.go | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 internal/listener/hashivault/listener_test.go 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..eb508cb --- /dev/null +++ b/internal/listener/hashivault/listener_test.go @@ -0,0 +1,56 @@ +package hashivault + +import ( + "context" + "fmt" + "testing" + + "github.com/external-secrets/reloader/internal/events" + "github.com/external-secrets/reloader/internal/listener/schema" + "github.com/go-logr/logr" +) + +func TestProcessKVWriteEvents(t *testing.T) { + for _, operation := range []string{"create", "update", "read"} { + for _, version := range []string{"v1", "v2"} { + t.Run(operation+"/"+version, func(t *testing.T) { + path := "secret/apps/example/api-key" + if version == "v2" { + path = "secret/data/apps/example/api-key" + } + eventChan := make(chan events.SecretRotationEvent, 1) + listener := &HashicorpVault{ + context: context.Background(), + eventChan: eventChan, + logger: logr.Discard(), + } + listener.processFn([]byte(fmt.Sprintf(`{ + "type": "response", + "request": {"operation": %q, "path": %q}, + "response": {"mount_type": "kv", "mount_point": "secret/"} + }`, operation, path))) + + if operation == "read" { + if len(eventChan) != 0 { + t.Fatal("read operation emitted a rotation event") + } + return + } + select { + case event := <-eventChan: + if event.SecretIdentifier != "apps/example/api-key" { + t.Errorf("unexpected secret identifier: %q", event.SecretIdentifier) + } + if event.TriggerSource != schema.HASHICORP_VAULT { + t.Errorf("unexpected trigger source: %q", event.TriggerSource) + } + if event.RotationTimestamp == "" { + t.Error("missing rotation timestamp") + } + default: + t.Fatal("write operation did not emit a rotation event") + } + }) + } + } +} From 402d9607ab9d0e29592a725f191cb158b2ecf9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sj=C3=B6din?= Date: Tue, 27 Oct 2026 13:44:44 +0100 Subject: [PATCH 2/2] Keep one focused create-event regression test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sjödin --- internal/listener/hashivault/listener_test.go | 60 ++++++------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/internal/listener/hashivault/listener_test.go b/internal/listener/hashivault/listener_test.go index eb508cb..4035b5a 100644 --- a/internal/listener/hashivault/listener_test.go +++ b/internal/listener/hashivault/listener_test.go @@ -2,55 +2,31 @@ package hashivault import ( "context" - "fmt" "testing" "github.com/external-secrets/reloader/internal/events" - "github.com/external-secrets/reloader/internal/listener/schema" "github.com/go-logr/logr" ) -func TestProcessKVWriteEvents(t *testing.T) { - for _, operation := range []string{"create", "update", "read"} { - for _, version := range []string{"v1", "v2"} { - t.Run(operation+"/"+version, func(t *testing.T) { - path := "secret/apps/example/api-key" - if version == "v2" { - path = "secret/data/apps/example/api-key" - } - eventChan := make(chan events.SecretRotationEvent, 1) - listener := &HashicorpVault{ - context: context.Background(), - eventChan: eventChan, - logger: logr.Discard(), - } - listener.processFn([]byte(fmt.Sprintf(`{ - "type": "response", - "request": {"operation": %q, "path": %q}, - "response": {"mount_type": "kv", "mount_point": "secret/"} - }`, operation, path))) +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/"} + }`)) - if operation == "read" { - if len(eventChan) != 0 { - t.Fatal("read operation emitted a rotation event") - } - return - } - select { - case event := <-eventChan: - if event.SecretIdentifier != "apps/example/api-key" { - t.Errorf("unexpected secret identifier: %q", event.SecretIdentifier) - } - if event.TriggerSource != schema.HASHICORP_VAULT { - t.Errorf("unexpected trigger source: %q", event.TriggerSource) - } - if event.RotationTimestamp == "" { - t.Error("missing rotation timestamp") - } - default: - t.Fatal("write operation did not emit a rotation event") - } - }) + 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") } }