|
@@ -9,31 +9,25 @@ import (
|
|
|
|
|
|
func TestMaskSecretKeys(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
- path string
|
|
|
+ doc string
|
|
|
input map[string]interface{}
|
|
|
expected map[string]interface{}
|
|
|
}{
|
|
|
{
|
|
|
- path: "/v1.30/secrets/create",
|
|
|
+ doc: "secret/config create and update requests",
|
|
|
input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
|
|
|
expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
|
|
|
},
|
|
|
{
|
|
|
- path: "/v1.30/secrets/create//",
|
|
|
- input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
|
|
|
- expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
|
|
|
- },
|
|
|
-
|
|
|
- {
|
|
|
- path: "/secrets/create?key=val",
|
|
|
- input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
|
|
|
- expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
|
|
|
- },
|
|
|
- {
|
|
|
- path: "/v1.30/some/other/path",
|
|
|
+ doc: "masking other fields (recursively)",
|
|
|
input: map[string]interface{}{
|
|
|
- "password": "pass",
|
|
|
+ "password": "pass",
|
|
|
+ "secret": "secret",
|
|
|
+ "jointoken": "jointoken",
|
|
|
+ "unlockkey": "unlockkey",
|
|
|
+ "signingcakey": "signingcakey",
|
|
|
"other": map[string]interface{}{
|
|
|
+ "password": "pass",
|
|
|
"secret": "secret",
|
|
|
"jointoken": "jointoken",
|
|
|
"unlockkey": "unlockkey",
|
|
@@ -41,8 +35,13 @@ func TestMaskSecretKeys(t *testing.T) {
|
|
|
},
|
|
|
},
|
|
|
expected: map[string]interface{}{
|
|
|
- "password": "*****",
|
|
|
+ "password": "*****",
|
|
|
+ "secret": "*****",
|
|
|
+ "jointoken": "*****",
|
|
|
+ "unlockkey": "*****",
|
|
|
+ "signingcakey": "*****",
|
|
|
"other": map[string]interface{}{
|
|
|
+ "password": "*****",
|
|
|
"secret": "*****",
|
|
|
"jointoken": "*****",
|
|
|
"unlockkey": "*****",
|
|
@@ -50,10 +49,27 @@ func TestMaskSecretKeys(t *testing.T) {
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ doc: "case insensitive field matching",
|
|
|
+ input: map[string]interface{}{
|
|
|
+ "PASSWORD": "pass",
|
|
|
+ "other": map[string]interface{}{
|
|
|
+ "PASSWORD": "pass",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ expected: map[string]interface{}{
|
|
|
+ "PASSWORD": "*****",
|
|
|
+ "other": map[string]interface{}{
|
|
|
+ "PASSWORD": "*****",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
for _, testcase := range tests {
|
|
|
- maskSecretKeys(testcase.input, testcase.path)
|
|
|
- assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
|
|
|
+ t.Run(testcase.doc, func(t *testing.T) {
|
|
|
+ maskSecretKeys(testcase.input)
|
|
|
+ assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
|
|
|
+ })
|
|
|
}
|
|
|
}
|