debug_test.go 1.7 KB

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