2017-08-23 09:30:33 +02:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-16 09:53:21 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-06-26 16:19:22 +02:00
|
|
|
"code.gitea.io/gitea/modules/translation"
|
2017-08-23 09:30:33 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testLoginFailed(t *testing.T, username, password, message string) {
|
|
|
|
session := emptyTestSession(t)
|
|
|
|
req := NewRequestWithValues(t, "POST", "/user/login", map[string]string{
|
|
|
|
"_csrf": GetCSRF(t, session, "/user/login"),
|
|
|
|
"user_name": username,
|
|
|
|
"password": password,
|
|
|
|
})
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
resultMsg := htmlDoc.doc.Find(".ui.message>p").Text()
|
|
|
|
|
|
|
|
assert.EqualValues(t, message, resultMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSignin(t *testing.T) {
|
2019-11-26 00:21:37 +01:00
|
|
|
defer prepareTestEnv(t)()
|
2017-08-23 09:30:33 +02:00
|
|
|
|
2021-11-24 10:49:20 +01:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
2017-08-23 09:30:33 +02:00
|
|
|
|
|
|
|
// add new user with user2's email
|
|
|
|
user.Name = "testuser"
|
|
|
|
user.LowerName = strings.ToLower(user.Name)
|
|
|
|
user.ID = 0
|
2021-11-16 09:53:21 +01:00
|
|
|
unittest.AssertSuccessfulInsert(t, user)
|
2017-08-23 09:30:33 +02:00
|
|
|
|
|
|
|
samples := []struct {
|
|
|
|
username string
|
|
|
|
password string
|
|
|
|
message string
|
|
|
|
}{
|
2022-06-26 16:19:22 +02:00
|
|
|
{username: "wrongUsername", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
|
|
|
{username: "wrongUsername", password: "password", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
|
|
|
{username: "user15", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
|
|
|
{username: "user1@example.com", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
2017-08-23 09:30:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range samples {
|
|
|
|
testLoginFailed(t, s.username, s.password, s.message)
|
|
|
|
}
|
|
|
|
}
|