github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/api/server/middleware/debug_test.go (about) 1 package middleware // import "github.com/docker/docker/api/server/middleware" 2 3 import ( 4 "testing" 5 6 "github.com/gotestyourself/gotestyourself/assert" 7 is "github.com/gotestyourself/gotestyourself/assert/cmp" 8 ) 9 10 func TestMaskSecretKeys(t *testing.T) { 11 tests := []struct { 12 path string 13 input map[string]interface{} 14 expected map[string]interface{} 15 }{ 16 { 17 path: "/v1.30/secrets/create", 18 input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}}, 19 expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}}, 20 }, 21 { 22 path: "/v1.30/secrets/create//", 23 input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}}, 24 expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}}, 25 }, 26 27 { 28 path: "/secrets/create?key=val", 29 input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}}, 30 expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}}, 31 }, 32 { 33 path: "/v1.30/some/other/path", 34 input: map[string]interface{}{ 35 "password": "pass", 36 "other": map[string]interface{}{ 37 "secret": "secret", 38 "jointoken": "jointoken", 39 "unlockkey": "unlockkey", 40 "signingcakey": "signingcakey", 41 }, 42 }, 43 expected: map[string]interface{}{ 44 "password": "*****", 45 "other": map[string]interface{}{ 46 "secret": "*****", 47 "jointoken": "*****", 48 "unlockkey": "*****", 49 "signingcakey": "*****", 50 }, 51 }, 52 }, 53 } 54 55 for _, testcase := range tests { 56 maskSecretKeys(testcase.input, testcase.path) 57 assert.Check(t, is.DeepEqual(testcase.expected, testcase.input)) 58 } 59 }