Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

signup_test.go 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. "fmt"
  7. "net/http"
  8. "strings"
  9. "testing"
  10. "code.gitea.io/gitea/modules/setting"
  11. "github.com/stretchr/testify/assert"
  12. "github.com/unknwon/i18n"
  13. )
  14. func TestSignup(t *testing.T) {
  15. defer prepareTestEnv(t)()
  16. setting.Service.EnableCaptcha = false
  17. req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
  18. "user_name": "exampleUser",
  19. "email": "exampleUser@example.com",
  20. "password": "examplePassword!1",
  21. "retype": "examplePassword!1",
  22. })
  23. MakeRequest(t, req, http.StatusFound)
  24. // should be able to view new user's page
  25. req = NewRequest(t, "GET", "/exampleUser")
  26. MakeRequest(t, req, http.StatusOK)
  27. }
  28. func TestSignupEmail(t *testing.T) {
  29. defer prepareTestEnv(t)()
  30. setting.Service.EnableCaptcha = false
  31. tests := []struct {
  32. email string
  33. wantStatus int
  34. wantMsg string
  35. }{
  36. {"exampleUser@example.com\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
  37. {"exampleUser@example.com\r", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
  38. {"exampleUser@example.com\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
  39. {"exampleUser@example.com", http.StatusFound, ""},
  40. }
  41. for i, test := range tests {
  42. req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
  43. "user_name": fmt.Sprintf("exampleUser%d", i),
  44. "email": test.email,
  45. "password": "examplePassword!1",
  46. "retype": "examplePassword!1",
  47. })
  48. resp := MakeRequest(t, req, test.wantStatus)
  49. if test.wantMsg != "" {
  50. htmlDoc := NewHTMLParser(t, resp.Body)
  51. assert.Equal(t,
  52. test.wantMsg,
  53. strings.TrimSpace(htmlDoc.doc.Find(".ui.message").Text()),
  54. )
  55. }
  56. }
  57. }