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"
|
|
|
|
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2017-06-29 19:04:47 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMaskSecretKeys(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
path string
|
|
|
|
input map[string]interface{}
|
|
|
|
expected 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: "/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",
|
|
|
|
input: map[string]interface{}{
|
|
|
|
"password": "pass",
|
|
|
|
"other": map[string]interface{}{
|
|
|
|
"secret": "secret",
|
|
|
|
"jointoken": "jointoken",
|
|
|
|
"unlockkey": "unlockkey",
|
|
|
|
"signingcakey": "signingcakey",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: map[string]interface{}{
|
|
|
|
"password": "*****",
|
|
|
|
"other": map[string]interface{}{
|
|
|
|
"secret": "*****",
|
|
|
|
"jointoken": "*****",
|
|
|
|
"unlockkey": "*****",
|
|
|
|
"signingcakey": "*****",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testcase := range tests {
|
|
|
|
maskSecretKeys(testcase.input, testcase.path)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
|
2017-06-29 19:04:47 -04:00
|
|
|
}
|
|
|
|
}
|