debug_test.go 1.7 KB

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