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.

68 lines
1.5 KiB

  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. for _, req := range []struct {
  18. OldPassword string
  19. NewPassword string
  20. Retype string
  21. Message string
  22. }{
  23. {
  24. OldPassword: oldPassword,
  25. NewPassword: "123456",
  26. Retype: "123456",
  27. Message: "",
  28. },
  29. {
  30. OldPassword: oldPassword,
  31. NewPassword: "12345",
  32. Retype: "12345",
  33. Message: "auth.password_too_short",
  34. },
  35. {
  36. OldPassword: "12334",
  37. NewPassword: "123456",
  38. Retype: "123456",
  39. Message: "settings.password_incorrect",
  40. },
  41. {
  42. OldPassword: oldPassword,
  43. NewPassword: "123456",
  44. Retype: "12345",
  45. Message: "form.password_not_match",
  46. },
  47. } {
  48. models.PrepareTestEnv(t)
  49. ctx := test.MockContext(t, "user/settings/security")
  50. test.LoadUser(t, ctx, 2)
  51. test.LoadRepo(t, ctx, 1)
  52. AccountPost(ctx, auth.ChangePasswordForm{
  53. OldPassword: req.OldPassword,
  54. Password: req.NewPassword,
  55. Retype: req.Retype,
  56. })
  57. assert.EqualValues(t, req.Message, ctx.Flash.ErrorMsg)
  58. assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
  59. }
  60. }