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