mirror of
https://github.com/go-gitea/gitea
synced 2024-10-31 23:34:25 +00:00
f5a3c0dd6c
* Use email_address table to check user's email when login with email adress * Update services/auth/signin.go * Fix test * Fix test * Fix logging in with ldap username != loginname * Fix if user does not exist yet * Make more clear this is loginName * Fix formatting Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Johan Van de Wauw <johan@gisky.be> Co-authored-by: zeripath <art27@cantab.net>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
// 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"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/unknwon/i18n"
|
|
)
|
|
|
|
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) {
|
|
defer prepareTestEnv(t)()
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
|
|
|
// add new user with user2's email
|
|
user.Name = "testuser"
|
|
user.LowerName = strings.ToLower(user.Name)
|
|
user.ID = 0
|
|
unittest.AssertSuccessfulInsert(t, user)
|
|
|
|
samples := []struct {
|
|
username string
|
|
password string
|
|
message string
|
|
}{
|
|
{username: "wrongUsername", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
|
|
{username: "wrongUsername", password: "password", message: i18n.Tr("en", "form.username_password_incorrect")},
|
|
{username: "user15", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
|
|
{username: "user1@example.com", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
|
|
}
|
|
|
|
for _, s := range samples {
|
|
testLoginFailed(t, s.username, s.password, s.message)
|
|
}
|
|
}
|