debug_test.go 1.9 KB

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