Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

setting_test.go 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2017 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 user
  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. SettingsSecurityPost(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. }