2018-02-05 16:05:59 -05:00
|
|
|
package middleware // import "github.com/docker/docker/api/server/middleware"
|
2017-06-29 19:04:47 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2017-06-29 19:04:47 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMaskSecretKeys(t *testing.T) {
|
|
|
|
tests := []struct {
|
2019-07-02 07:29:24 -04:00
|
|
|
doc string
|
2017-06-29 19:04:47 -04:00
|
|
|
input map[string]interface{}
|
|
|
|
expected map[string]interface{}
|
|
|
|
}{
|
|
|
|
{
|
2019-07-03 10:16:22 -04:00
|
|
|
doc: "secret/config create and update requests",
|
2017-06-29 19:04:47 -04:00
|
|
|
input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
|
|
|
|
expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
|
|
|
|
},
|
|
|
|
{
|
2019-07-03 10:16:22 -04:00
|
|
|
doc: "masking other fields (recursively)",
|
2017-06-29 19:04:47 -04:00
|
|
|
input: map[string]interface{}{
|
2019-07-02 07:21:04 -04:00
|
|
|
"password": "pass",
|
|
|
|
"secret": "secret",
|
|
|
|
"jointoken": "jointoken",
|
|
|
|
"unlockkey": "unlockkey",
|
|
|
|
"signingcakey": "signingcakey",
|
2017-06-29 19:04:47 -04:00
|
|
|
"other": map[string]interface{}{
|
2019-07-02 07:21:04 -04:00
|
|
|
"password": "pass",
|
2017-06-29 19:04:47 -04:00
|
|
|
"secret": "secret",
|
|
|
|
"jointoken": "jointoken",
|
|
|
|
"unlockkey": "unlockkey",
|
|
|
|
"signingcakey": "signingcakey",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: map[string]interface{}{
|
2019-07-02 07:21:04 -04:00
|
|
|
"password": "*****",
|
|
|
|
"secret": "*****",
|
|
|
|
"jointoken": "*****",
|
|
|
|
"unlockkey": "*****",
|
|
|
|
"signingcakey": "*****",
|
2017-06-29 19:04:47 -04:00
|
|
|
"other": map[string]interface{}{
|
2019-07-02 07:21:04 -04:00
|
|
|
"password": "*****",
|
2017-06-29 19:04:47 -04:00
|
|
|
"secret": "*****",
|
|
|
|
"jointoken": "*****",
|
|
|
|
"unlockkey": "*****",
|
|
|
|
"signingcakey": "*****",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-02 07:21:04 -04:00
|
|
|
{
|
2019-07-03 10:16:22 -04:00
|
|
|
doc: "case insensitive field matching",
|
2019-07-02 07:21:04 -04:00
|
|
|
input: map[string]interface{}{
|
|
|
|
"PASSWORD": "pass",
|
|
|
|
"other": map[string]interface{}{
|
|
|
|
"PASSWORD": "pass",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: map[string]interface{}{
|
|
|
|
"PASSWORD": "*****",
|
|
|
|
"other": map[string]interface{}{
|
|
|
|
"PASSWORD": "*****",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-06-29 19:04:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, testcase := range tests {
|
2019-07-02 07:29:24 -04:00
|
|
|
t.Run(testcase.doc, func(t *testing.T) {
|
2019-07-03 10:16:22 -04:00
|
|
|
maskSecretKeys(testcase.input)
|
2019-07-02 07:29:24 -04:00
|
|
|
assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
|
|
|
|
})
|
2017-06-29 19:04:47 -04:00
|
|
|
}
|
|
|
|
}
|