本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.8KB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package admin
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestShadowPassword(t *testing.T) {
  10. var kases = []struct {
  11. Provider string
  12. CfgItem string
  13. Result string
  14. }{
  15. {
  16. Provider: "redis",
  17. CfgItem: "network=tcp,addr=:6379,password=gitea,db=0,pool_size=100,idle_timeout=180",
  18. Result: "network=tcp,addr=:6379,password=******,db=0,pool_size=100,idle_timeout=180",
  19. },
  20. {
  21. Provider: "mysql",
  22. CfgItem: "root:@tcp(localhost:3306)/gitea?charset=utf8",
  23. Result: "root:******@tcp(localhost:3306)/gitea?charset=utf8",
  24. },
  25. {
  26. Provider: "mysql",
  27. CfgItem: "/gitea?charset=utf8",
  28. Result: "/gitea?charset=utf8",
  29. },
  30. {
  31. Provider: "mysql",
  32. CfgItem: "user:mypassword@/dbname",
  33. Result: "user:******@/dbname",
  34. },
  35. {
  36. Provider: "postgres",
  37. CfgItem: "user=pqgotest dbname=pqgotest sslmode=verify-full",
  38. Result: "user=pqgotest dbname=pqgotest sslmode=verify-full",
  39. },
  40. {
  41. Provider: "postgres",
  42. CfgItem: "user=pqgotest password= dbname=pqgotest sslmode=verify-full",
  43. Result: "user=pqgotest password=****** dbname=pqgotest sslmode=verify-full",
  44. },
  45. {
  46. Provider: "postgres",
  47. CfgItem: "postgres://user:pass@hostname/dbname",
  48. Result: "postgres://user:******@hostname/dbname",
  49. },
  50. {
  51. Provider: "couchbase",
  52. CfgItem: "http://dev-couchbase.example.com:8091/",
  53. Result: "http://dev-couchbase.example.com:8091/",
  54. },
  55. {
  56. Provider: "couchbase",
  57. CfgItem: "http://user:the_password@dev-couchbase.example.com:8091/",
  58. Result: "http://user:******@dev-couchbase.example.com:8091/",
  59. },
  60. }
  61. for _, k := range kases {
  62. assert.EqualValues(t, k.Result, shadowPassword(k.Provider, k.CfgItem))
  63. }
  64. }
上海开阖软件有限公司 沪ICP备12045867号-1