2018-05-17 09:35:00 +05:30
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2017-12-02 22:41:22 +05:30
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-05-17 09:35:00 +05:30
|
|
|
package setting
|
2017-12-02 22:41:22 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/test"
|
2021-01-26 21:06:53 +05:30
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-04-07 01:14:05 +05:30
|
|
|
"code.gitea.io/gitea/services/forms"
|
2017-12-02 22:41:22 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestChangePassword(t *testing.T) {
|
|
|
|
oldPassword := "password"
|
|
|
|
setting.MinPasswordLength = 6
|
2019-10-16 08:39:58 +05:30
|
|
|
var pcALL = []string{"lower", "upper", "digit", "spec"}
|
|
|
|
var pcLUN = []string{"lower", "upper", "digit"}
|
|
|
|
var pcLU = []string{"lower", "upper"}
|
2017-12-02 22:41:22 +05:30
|
|
|
|
|
|
|
for _, req := range []struct {
|
2019-10-14 20:54:26 +05:30
|
|
|
OldPassword string
|
|
|
|
NewPassword string
|
|
|
|
Retype string
|
|
|
|
Message string
|
2019-10-16 08:39:58 +05:30
|
|
|
PasswordComplexity []string
|
2017-12-02 22:41:22 +05:30
|
|
|
}{
|
|
|
|
{
|
2019-10-14 20:54:26 +05:30
|
|
|
OldPassword: oldPassword,
|
|
|
|
NewPassword: "Qwerty123456-",
|
|
|
|
Retype: "Qwerty123456-",
|
|
|
|
Message: "",
|
2019-10-16 08:39:58 +05:30
|
|
|
PasswordComplexity: pcALL,
|
2019-10-14 20:54:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
OldPassword: oldPassword,
|
|
|
|
NewPassword: "12345",
|
|
|
|
Retype: "12345",
|
|
|
|
Message: "auth.password_too_short",
|
2019-10-16 08:39:58 +05:30
|
|
|
PasswordComplexity: pcALL,
|
2019-10-14 20:54:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
OldPassword: "12334",
|
|
|
|
NewPassword: "123456",
|
|
|
|
Retype: "123456",
|
|
|
|
Message: "settings.password_incorrect",
|
2019-10-16 08:39:58 +05:30
|
|
|
PasswordComplexity: pcALL,
|
2019-10-14 20:54:26 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
OldPassword: oldPassword,
|
|
|
|
NewPassword: "123456",
|
|
|
|
Retype: "12345",
|
|
|
|
Message: "form.password_not_match",
|
2019-10-16 08:39:58 +05:30
|
|
|
PasswordComplexity: pcALL,
|
2017-12-02 22:41:22 +05:30
|
|
|
},
|
|
|
|
{
|
2019-10-14 20:54:26 +05:30
|
|
|
OldPassword: oldPassword,
|
|
|
|
NewPassword: "Qwerty",
|
|
|
|
Retype: "Qwerty",
|
2019-10-16 08:39:58 +05:30
|
|
|
Message: "form.password_complexity",
|
|
|
|
PasswordComplexity: pcALL,
|
2017-12-02 22:41:22 +05:30
|
|
|
},
|
|
|
|
{
|
2019-10-14 20:54:26 +05:30
|
|
|
OldPassword: oldPassword,
|
|
|
|
NewPassword: "Qwerty",
|
|
|
|
Retype: "Qwerty",
|
2019-10-16 08:39:58 +05:30
|
|
|
Message: "form.password_complexity",
|
2019-10-14 20:54:26 +05:30
|
|
|
PasswordComplexity: pcLUN,
|
2017-12-02 22:41:22 +05:30
|
|
|
},
|
|
|
|
{
|
2019-10-14 20:54:26 +05:30
|
|
|
OldPassword: oldPassword,
|
|
|
|
NewPassword: "QWERTY",
|
|
|
|
Retype: "QWERTY",
|
2019-10-16 08:39:58 +05:30
|
|
|
Message: "form.password_complexity",
|
2019-10-14 20:54:26 +05:30
|
|
|
PasswordComplexity: pcLU,
|
2017-12-02 22:41:22 +05:30
|
|
|
},
|
|
|
|
} {
|
|
|
|
models.PrepareTestEnv(t)
|
|
|
|
ctx := test.MockContext(t, "user/settings/security")
|
|
|
|
test.LoadUser(t, ctx, 2)
|
|
|
|
test.LoadRepo(t, ctx, 1)
|
|
|
|
|
2021-04-07 01:14:05 +05:30
|
|
|
web.SetForm(ctx, &forms.ChangePasswordForm{
|
2017-12-02 22:41:22 +05:30
|
|
|
OldPassword: req.OldPassword,
|
|
|
|
Password: req.NewPassword,
|
|
|
|
Retype: req.Retype,
|
|
|
|
})
|
2021-01-26 21:06:53 +05:30
|
|
|
AccountPost(ctx)
|
2017-12-02 22:41:22 +05:30
|
|
|
|
2019-11-20 04:14:58 +05:30
|
|
|
assert.Contains(t, ctx.Flash.ErrorMsg, req.Message)
|
2017-12-02 22:41:22 +05:30
|
|
|
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
|
|
|
|
}
|
|
|
|
}
|