Skip to content

Commit c25632e

Browse files
ivan-velascoyesnault
authored andcommitted
feat: compute derived secrets from test case variables
Updated the processSecrets function to compute derived secrets using effective variables from both the test suite and the test case. Added a new test to verify that secrets are correctly derived from test case-level variables, ensuring sensitive information is properly redacted in the output. Signed-off-by: Ivan Velasco <ivan.velasco@socotra.com>
1 parent eb16e65 commit c25632e

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

process_testcase.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,17 @@ func (v *Venom) processSecrets(ctx context.Context, ts *TestSuite, tc *TestCase)
172172
if tc != nil {
173173
collect(tc.Vars)
174174
}
175-
computedSecrets = appendDerivedSecrets(computedSecrets, seen, ts.Vars, ts.Secrets)
175+
176+
// Derived secrets (e.g. base64 basic-auth tokens) must be computed from the
177+
// effective vars, which may only define the secret at the test case level.
178+
derivedVars := ts.Vars.Clone()
179+
if derivedVars == nil {
180+
derivedVars = H{}
181+
}
182+
if tc != nil {
183+
derivedVars.AddAll(tc.Vars)
184+
}
185+
computedSecrets = appendDerivedSecrets(computedSecrets, seen, derivedVars, ts.Secrets)
176186
return context.WithValue(ctx, ContextKey("secrets"), computedSecrets)
177187
}
178188

venom_output_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,30 @@ func TestAppendDerivedSecretsBasicAuth(t *testing.T) {
103103
assert.Equal(t, "__hidden__", HideSensitive(ctx, token))
104104
}
105105

106+
func TestAppendDerivedSecretsFromTestCaseVars(t *testing.T) {
107+
v := New()
108+
ts := TestSuite{
109+
Secrets: []string{"basic_auth_password"},
110+
Vars: H{},
111+
TestCases: []TestCase{
112+
{
113+
TestCaseInput: TestCaseInput{
114+
Vars: H{
115+
"basic_auth_user": "testuser",
116+
"basic_auth_password": "my_secret",
117+
},
118+
},
119+
},
120+
},
121+
}
122+
ctx := v.processSecrets(context.Background(), &ts, &ts.TestCases[0])
123+
124+
token := base64.StdEncoding.EncodeToString([]byte("testuser:my_secret"))
125+
assert.Equal(t, "__hidden__", HideSensitive(ctx, token))
126+
assert.Equal(t, "__hidden__", HideSensitive(ctx, base64.StdEncoding.EncodeToString([]byte("my_secret"))))
127+
assert.NotContains(t, HideSensitive(ctx, "Authorization: Basic "+token), token)
128+
}
129+
106130
func TestHideSensitiveBasicAuthHeaderInCleanupContext(t *testing.T) {
107131
v := New()
108132
ts := TestSuite{

0 commit comments

Comments
 (0)