Add tests for - case-insensitive matching of fields - recursive masking Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit db5f811216e70bcb4a10e477c1558d6c68f618c5) Signed-off-by: Tibor Vass <tibor@docker.com> (cherry picked from commit 18dac2cf32faeaada3bd4e8e2bffa576ad4329fe) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 310770b6deae3ff2f244654b8e84c14576e38493 Component: engine
84 lines
2.3 KiB
Go
84 lines
2.3 KiB
Go
package middleware // import "github.com/docker/docker/api/server/middleware"
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gotest.tools/assert"
|
|
is "gotest.tools/assert/cmp"
|
|
)
|
|
|
|
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",
|
|
"secret": "secret",
|
|
"jointoken": "jointoken",
|
|
"unlockkey": "unlockkey",
|
|
"signingcakey": "signingcakey",
|
|
"other": map[string]interface{}{
|
|
"password": "pass",
|
|
"secret": "secret",
|
|
"jointoken": "jointoken",
|
|
"unlockkey": "unlockkey",
|
|
"signingcakey": "signingcakey",
|
|
},
|
|
},
|
|
expected: map[string]interface{}{
|
|
"password": "*****",
|
|
"secret": "*****",
|
|
"jointoken": "*****",
|
|
"unlockkey": "*****",
|
|
"signingcakey": "*****",
|
|
"other": map[string]interface{}{
|
|
"password": "*****",
|
|
"secret": "*****",
|
|
"jointoken": "*****",
|
|
"unlockkey": "*****",
|
|
"signingcakey": "*****",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
path: "/v1.30/some/other/path",
|
|
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))
|
|
}
|
|
}
|