本站源代码
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

98 行
2.5KB

  1. // Copyright 2018 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 setting
  5. import (
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/auth"
  10. "code.gitea.io/gitea/modules/setting"
  11. "code.gitea.io/gitea/modules/test"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestChangePassword(t *testing.T) {
  15. oldPassword := "password"
  16. setting.MinPasswordLength = 6
  17. var pcALL = []string{"lower", "upper", "digit", "spec"}
  18. var pcLUN = []string{"lower", "upper", "digit"}
  19. var pcLU = []string{"lower", "upper"}
  20. for _, req := range []struct {
  21. OldPassword string
  22. NewPassword string
  23. Retype string
  24. Message string
  25. PasswordComplexity []string
  26. }{
  27. {
  28. OldPassword: oldPassword,
  29. NewPassword: "Qwerty123456-",
  30. Retype: "Qwerty123456-",
  31. Message: "",
  32. PasswordComplexity: pcALL,
  33. },
  34. {
  35. OldPassword: oldPassword,
  36. NewPassword: "12345",
  37. Retype: "12345",
  38. Message: "auth.password_too_short",
  39. PasswordComplexity: pcALL,
  40. },
  41. {
  42. OldPassword: "12334",
  43. NewPassword: "123456",
  44. Retype: "123456",
  45. Message: "settings.password_incorrect",
  46. PasswordComplexity: pcALL,
  47. },
  48. {
  49. OldPassword: oldPassword,
  50. NewPassword: "123456",
  51. Retype: "12345",
  52. Message: "form.password_not_match",
  53. PasswordComplexity: pcALL,
  54. },
  55. {
  56. OldPassword: oldPassword,
  57. NewPassword: "Qwerty",
  58. Retype: "Qwerty",
  59. Message: "form.password_complexity",
  60. PasswordComplexity: pcALL,
  61. },
  62. {
  63. OldPassword: oldPassword,
  64. NewPassword: "Qwerty",
  65. Retype: "Qwerty",
  66. Message: "form.password_complexity",
  67. PasswordComplexity: pcLUN,
  68. },
  69. {
  70. OldPassword: oldPassword,
  71. NewPassword: "QWERTY",
  72. Retype: "QWERTY",
  73. Message: "form.password_complexity",
  74. PasswordComplexity: pcLU,
  75. },
  76. } {
  77. models.PrepareTestEnv(t)
  78. ctx := test.MockContext(t, "user/settings/security")
  79. test.LoadUser(t, ctx, 2)
  80. test.LoadRepo(t, ctx, 1)
  81. AccountPost(ctx, auth.ChangePasswordForm{
  82. OldPassword: req.OldPassword,
  83. Password: req.NewPassword,
  84. Retype: req.Retype,
  85. })
  86. assert.EqualValues(t, req.Message, ctx.Flash.ErrorMsg)
  87. assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
  88. }
  89. }
上海开阖软件有限公司 沪ICP备12045867号-1