github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/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 "gotest.tools/v3/assert" 7 is "gotest.tools/v3/assert/cmp" 8 ) 9 10 func TestMaskSecretKeys(t *testing.T) { 11 tests := []struct { 12 doc string 13 input map[string]interface{} 14 expected map[string]interface{} 15 }{ 16 { 17 doc: "secret/config create and update requests", 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 doc: "masking other fields (recursively)", 23 input: map[string]interface{}{ 24 "password": "pass", 25 "secret": "secret", 26 "jointoken": "jointoken", 27 "unlockkey": "unlockkey", 28 "signingcakey": "signingcakey", 29 "other": map[string]interface{}{ 30 "password": "pass", 31 "secret": "secret", 32 "jointoken": "jointoken", 33 "unlockkey": "unlockkey", 34 "signingcakey": "signingcakey", 35 }, 36 }, 37 expected: map[string]interface{}{ 38 "password": "*****", 39 "secret": "*****", 40 "jointoken": "*****", 41 "unlockkey": "*****", 42 "signingcakey": "*****", 43 "other": map[string]interface{}{ 44 "password": "*****", 45 "secret": "*****", 46 "jointoken": "*****", 47 "unlockkey": "*****", 48 "signingcakey": "*****", 49 }, 50 }, 51 }, 52 { 53 doc: "case insensitive field matching", 54 input: map[string]interface{}{ 55 "PASSWORD": "pass", 56 "other": map[string]interface{}{ 57 "PASSWORD": "pass", 58 }, 59 }, 60 expected: map[string]interface{}{ 61 "PASSWORD": "*****", 62 "other": map[string]interface{}{ 63 "PASSWORD": "*****", 64 }, 65 }, 66 }, 67 } 68 69 for _, testcase := range tests { 70 t.Run(testcase.doc, func(t *testing.T) { 71 maskSecretKeys(testcase.input) 72 assert.Check(t, is.DeepEqual(testcase.expected, testcase.input)) 73 }) 74 } 75 }