From 37cbf7a9cd788bffd5ceaebfa48e21626f8cc600 Mon Sep 17 00:00:00 2001 From: Ishwar Date: Tue, 31 Mar 2026 14:50:59 +0530 Subject: [PATCH] test: repurpose decline test to cover sensitive data detection path Renames test to Test_preChecks_sensitive_data_detected_decline. Uses a temporary .env file with an AWS token to reliably trigger the DefangLabs secret detector, and confirms that preChecks correctly aborts early on user decline. Signed-off-by: Ishwar --- pkg/compose/publish_test.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/compose/publish_test.go b/pkg/compose/publish_test.go index c0028c740..31932632f 100644 --- a/pkg/compose/publish_test.go +++ b/pkg/compose/publish_test.go @@ -18,6 +18,7 @@ package compose import ( "errors" + "os" "slices" "testing" @@ -102,18 +103,22 @@ services: }, cmp.Ignore())) } -func Test_preChecks_decline_returns_ErrPublishAborted(t *testing.T) { +func Test_preChecks_sensitive_data_detected_decline(t *testing.T) { + + dir := t.TempDir() + envPath := dir + "/secrets.env" + secretData := `AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"` + err := os.WriteFile(envPath, []byte(secretData), 0o600) + assert.NilError(t, err) + project := &types.Project{ + Services: types.Services{ "web": { Name: "web", Image: "nginx", - Volumes: []types.ServiceVolumeConfig{ - { - Type: types.VolumeTypeBind, - Source: "/host/path", - Target: "/container/path", - }, + EnvFiles: []types.EnvFile{ + {Path: envPath, Required: true}, }, }, },