-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathvenom_output_test.go
More file actions
158 lines (141 loc) 路 4.37 KB
/
Copy pathvenom_output_test.go
File metadata and controls
158 lines (141 loc) 路 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package venom
import (
"context"
"encoding/base64"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCleanUpSecrets(t *testing.T) {
v := New()
ts := TestSuite{
Name: "HTTP Auth Test",
Secrets: []string{"basic_auth_password"},
Vars: H{
"url": "http://127.0.0.1:8000",
"basic_auth_user": "testuser",
"basic_auth_password": "my_secret",
},
TestCases: []TestCase{
{
TestCaseInput: TestCaseInput{
Name: "GET with credentials",
Vars: H{
"basic_auth_password": "my_secret",
},
},
TestStepResults: []TestStepResult{
{
Name: "GET-with-credentials",
InputVars: map[string]string{
"basic_auth_user": "testuser",
"basic_auth_password": "my_secret",
},
Raw: []byte(`type: http
basic_auth_password: "{{.basic_auth_password}}"
`),
Interpolated: []byte(`type: http
basic_auth_password: my_secret
basic_auth_user: testuser
method: GET
`),
Systemout: "Authorization: Basic dGVzdHVzZXI6bXlfc2VjcmV0",
},
},
},
},
}
cleaned := v.CleanUpSecrets(ts)
assert.Equal(t, "__hidden__", cleaned.Vars["basic_auth_password"])
assert.Equal(t, "testuser", cleaned.Vars["basic_auth_user"])
result := cleaned.TestCases[0].TestStepResults[0]
assert.Equal(t, "__hidden__", result.InputVars["basic_auth_password"])
assert.NotContains(t, string(result.Raw.([]byte)), "my_secret")
assert.NotContains(t, string(result.Interpolated.([]byte)), "my_secret")
assert.NotContains(t, result.Systemout, "my_secret")
assert.NotContains(t, result.Systemout, "dGVzdHVzZXI6bXlfc2VjcmV0")
data, err := json.Marshal(cleaned)
require.NoError(t, err)
assert.NotContains(t, string(data), "my_secret")
}
func TestHideSensitiveBytes(t *testing.T) {
ctx := context.WithValue(context.Background(), ContextKey("secrets"), []string{"my_secret"})
redacted := hideSensitiveBytes(ctx, []byte("basic_auth_password: my_secret\n"))
assert.Equal(t, "basic_auth_password: __hidden__\n", string(redacted))
}
func TestReplaceSecretsLongestFirst(t *testing.T) {
secrets := []string{"foo", "foobar"}
assert.Equal(t, "__hidden__", replaceSecrets("foobar", secrets))
}
func TestAppendDerivedSecretsBasicAuth(t *testing.T) {
v := New()
ts := TestSuite{
Secrets: []string{"basic_auth_password"},
Vars: H{
"basic_auth_user": "testuser",
"basic_auth_password": "my_secret",
},
}
ctx := v.processSecrets(context.Background(), &ts, nil)
secrets := ctx.Value(ContextKey("secrets")).([]string)
token := base64.StdEncoding.EncodeToString([]byte("testuser:my_secret"))
found := false
for _, s := range secrets {
if s == token {
found = true
break
}
}
assert.True(t, found, "basic auth token should be registered as a derived secret")
assert.Equal(t, "__hidden__", HideSensitive(ctx, token))
}
func TestAppendDerivedSecretsFromTestCaseVars(t *testing.T) {
v := New()
ts := TestSuite{
Secrets: []string{"basic_auth_password"},
Vars: H{},
TestCases: []TestCase{
{
TestCaseInput: TestCaseInput{
Vars: H{
"basic_auth_user": "testuser",
"basic_auth_password": "my_secret",
},
},
},
},
}
ctx := v.processSecrets(context.Background(), &ts, &ts.TestCases[0])
token := base64.StdEncoding.EncodeToString([]byte("testuser:my_secret"))
assert.Equal(t, "__hidden__", HideSensitive(ctx, token))
assert.Equal(t, "__hidden__", HideSensitive(ctx, base64.StdEncoding.EncodeToString([]byte("my_secret"))))
assert.NotContains(t, HideSensitive(ctx, "Authorization: Basic "+token), token)
}
func TestHideSensitiveBasicAuthHeaderInCleanupContext(t *testing.T) {
v := New()
ts := TestSuite{
Secrets: []string{"basic_auth_password"},
Vars: H{
"basic_auth_user": "testuser",
"basic_auth_password": "my_secret",
},
TestCases: []TestCase{
{TestCaseInput: TestCaseInput{Vars: H{"basic_auth_password": "my_secret"}}},
},
}
ctx := v.processSecrets(context.Background(), &ts, &ts.TestCases[0])
out := HideSensitive(ctx, "Authorization: Basic dGVzdHVzZXI6bXlfc2VjcmV0")
assert.NotContains(t, out, "dGVzdHVzZXI6bXlfc2VjcmV0")
}
func TestProcessSecretsUsesTestSuiteVars(t *testing.T) {
v := New()
ts := TestSuite{
Secrets: []string{"token"},
Vars: H{
"token": "secret-value",
},
}
ctx := v.processSecrets(context.Background(), &ts, nil)
assert.Equal(t, "__hidden__", HideSensitive(ctx, "secret-value"))
}