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.

account_test.go 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. }