選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

signup_test.go 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/models/unittest"
  11. user_model "code.gitea.io/gitea/models/user"
  12. "code.gitea.io/gitea/modules/setting"
  13. "code.gitea.io/gitea/modules/translation/i18n"
  14. "github.com/stretchr/testify/assert"
  15. )
  16. func TestSignup(t *testing.T) {
  17. defer prepareTestEnv(t)()
  18. setting.Service.EnableCaptcha = false
  19. req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
  20. "user_name": "exampleUser",
  21. "email": "exampleUser@example.com",
  22. "password": "examplePassword!1",
  23. "retype": "examplePassword!1",
  24. })
  25. MakeRequest(t, req, http.StatusSeeOther)
  26. // should be able to view new user's page
  27. req = NewRequest(t, "GET", "/exampleUser")
  28. MakeRequest(t, req, http.StatusOK)
  29. }
  30. func TestSignupAsRestricted(t *testing.T) {
  31. defer prepareTestEnv(t)()
  32. setting.Service.EnableCaptcha = false
  33. setting.Service.DefaultUserIsRestricted = true
  34. req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
  35. "user_name": "restrictedUser",
  36. "email": "restrictedUser@example.com",
  37. "password": "examplePassword!1",
  38. "retype": "examplePassword!1",
  39. })
  40. MakeRequest(t, req, http.StatusSeeOther)
  41. // should be able to view new user's page
  42. req = NewRequest(t, "GET", "/restrictedUser")
  43. MakeRequest(t, req, http.StatusOK)
  44. user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "restrictedUser"}).(*user_model.User)
  45. assert.True(t, user2.IsRestricted)
  46. }
  47. func TestSignupEmail(t *testing.T) {
  48. defer prepareTestEnv(t)()
  49. setting.Service.EnableCaptcha = false
  50. tests := []struct {
  51. email string
  52. wantStatus int
  53. wantMsg string
  54. }{
  55. {"exampleUser@example.com\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
  56. {"exampleUser@example.com\r", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
  57. {"exampleUser@example.com\n", http.StatusOK, i18n.Tr("en", "form.email_invalid")},
  58. {"exampleUser@example.com", http.StatusSeeOther, ""},
  59. }
  60. for i, test := range tests {
  61. req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
  62. "user_name": fmt.Sprintf("exampleUser%d", i),
  63. "email": test.email,
  64. "password": "examplePassword!1",
  65. "retype": "examplePassword!1",
  66. })
  67. resp := MakeRequest(t, req, test.wantStatus)
  68. if test.wantMsg != "" {
  69. htmlDoc := NewHTMLParser(t, resp.Body)
  70. assert.Equal(t,
  71. test.wantMsg,
  72. strings.TrimSpace(htmlDoc.doc.Find(".ui.message").Text()),
  73. )
  74. }
  75. }
  76. }