Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

signin_test.go 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 integrations
  5. import (
  6. "net/http"
  7. "strings"
  8. "testing"
  9. "code.gitea.io/gitea/models/unittest"
  10. user_model "code.gitea.io/gitea/models/user"
  11. "code.gitea.io/gitea/modules/translation/i18n"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func testLoginFailed(t *testing.T, username, password, message string) {
  15. session := emptyTestSession(t)
  16. req := NewRequestWithValues(t, "POST", "/user/login", map[string]string{
  17. "_csrf": GetCSRF(t, session, "/user/login"),
  18. "user_name": username,
  19. "password": password,
  20. })
  21. resp := session.MakeRequest(t, req, http.StatusOK)
  22. htmlDoc := NewHTMLParser(t, resp.Body)
  23. resultMsg := htmlDoc.doc.Find(".ui.message>p").Text()
  24. assert.EqualValues(t, message, resultMsg)
  25. }
  26. func TestSignin(t *testing.T) {
  27. defer prepareTestEnv(t)()
  28. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
  29. // add new user with user2's email
  30. user.Name = "testuser"
  31. user.LowerName = strings.ToLower(user.Name)
  32. user.ID = 0
  33. unittest.AssertSuccessfulInsert(t, user)
  34. samples := []struct {
  35. username string
  36. password string
  37. message string
  38. }{
  39. {username: "wrongUsername", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
  40. {username: "wrongUsername", password: "password", message: i18n.Tr("en", "form.username_password_incorrect")},
  41. {username: "user15", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
  42. {username: "user1@example.com", password: "wrongPassword", message: i18n.Tr("en", "form.username_password_incorrect")},
  43. }
  44. for _, s := range samples {
  45. testLoginFailed(t, s.username, s.password, s.message)
  46. }
  47. }