debug_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. "secret": "secret",
  33. "jointoken": "jointoken",
  34. "unlockkey": "unlockkey",
  35. "signingcakey": "signingcakey",
  36. "other": map[string]interface{}{
  37. "password": "pass",
  38. "secret": "secret",
  39. "jointoken": "jointoken",
  40. "unlockkey": "unlockkey",
  41. "signingcakey": "signingcakey",
  42. },
  43. },
  44. expected: map[string]interface{}{
  45. "password": "*****",
  46. "secret": "*****",
  47. "jointoken": "*****",
  48. "unlockkey": "*****",
  49. "signingcakey": "*****",
  50. "other": map[string]interface{}{
  51. "password": "*****",
  52. "secret": "*****",
  53. "jointoken": "*****",
  54. "unlockkey": "*****",
  55. "signingcakey": "*****",
  56. },
  57. },
  58. },
  59. {
  60. path: "/v1.30/some/other/path",
  61. input: map[string]interface{}{
  62. "PASSWORD": "pass",
  63. "other": map[string]interface{}{
  64. "PASSWORD": "pass",
  65. },
  66. },
  67. expected: map[string]interface{}{
  68. "PASSWORD": "*****",
  69. "other": map[string]interface{}{
  70. "PASSWORD": "*****",
  71. },
  72. },
  73. },
  74. }
  75. for _, testcase := range tests {
  76. maskSecretKeys(testcase.input, testcase.path)
  77. assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
  78. }
  79. }