You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.7 KiB
95 lines
2.7 KiB
8 years ago
|
// 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.
|
||
|
|
||
2 years ago
|
package integration
|
||
8 years ago
|
|
||
|
import (
|
||
4 years ago
|
"fmt"
|
||
8 years ago
|
"net/http"
|
||
4 years ago
|
"strings"
|
||
8 years ago
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
user_model "code.gitea.io/gitea/models/user"
|
||
8 years ago
|
"code.gitea.io/gitea/modules/setting"
|
||
3 years ago
|
"code.gitea.io/gitea/modules/translation"
|
||
2 years ago
|
"code.gitea.io/gitea/tests"
|
||
3 years ago
|
|
||
4 years ago
|
"github.com/stretchr/testify/assert"
|
||
8 years ago
|
)
|
||
8 years ago
|
|
||
|
func TestSignup(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
8 years ago
|
|
||
8 years ago
|
setting.Service.EnableCaptcha = false
|
||
|
|
||
8 years ago
|
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
|
||
|
"user_name": "exampleUser",
|
||
|
"email": "exampleUser@example.com",
|
||
5 years ago
|
"password": "examplePassword!1",
|
||
|
"retype": "examplePassword!1",
|
||
8 years ago
|
})
|
||
3 years ago
|
MakeRequest(t, req, http.StatusSeeOther)
|
||
8 years ago
|
|
||
8 years ago
|
// should be able to view new user's page
|
||
8 years ago
|
req = NewRequest(t, "GET", "/exampleUser")
|
||
8 years ago
|
MakeRequest(t, req, http.StatusOK)
|
||
8 years ago
|
}
|
||
4 years ago
|
|
||
3 years ago
|
func TestSignupAsRestricted(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
3 years ago
|
|
||
|
setting.Service.EnableCaptcha = false
|
||
|
setting.Service.DefaultUserIsRestricted = true
|
||
|
|
||
|
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
|
||
|
"user_name": "restrictedUser",
|
||
|
"email": "restrictedUser@example.com",
|
||
|
"password": "examplePassword!1",
|
||
|
"retype": "examplePassword!1",
|
||
|
})
|
||
3 years ago
|
MakeRequest(t, req, http.StatusSeeOther)
|
||
3 years ago
|
|
||
|
// should be able to view new user's page
|
||
|
req = NewRequest(t, "GET", "/restrictedUser")
|
||
|
MakeRequest(t, req, http.StatusOK)
|
||
|
|
||
2 years ago
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "restrictedUser"})
|
||
3 years ago
|
assert.True(t, user2.IsRestricted)
|
||
|
}
|
||
|
|
||
4 years ago
|
func TestSignupEmail(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
4 years ago
|
|
||
|
setting.Service.EnableCaptcha = false
|
||
|
|
||
|
tests := []struct {
|
||
|
email string
|
||
|
wantStatus int
|
||
|
wantMsg string
|
||
|
}{
|
||
3 years ago
|
{"exampleUser@example.com\r\n", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||
|
{"exampleUser@example.com\r", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||
|
{"exampleUser@example.com\n", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||
3 years ago
|
{"exampleUser@example.com", http.StatusSeeOther, ""},
|
||
4 years ago
|
}
|
||
|
|
||
|
for i, test := range tests {
|
||
|
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
|
||
|
"user_name": fmt.Sprintf("exampleUser%d", i),
|
||
|
"email": test.email,
|
||
|
"password": "examplePassword!1",
|
||
|
"retype": "examplePassword!1",
|
||
|
})
|
||
|
resp := MakeRequest(t, req, test.wantStatus)
|
||
|
if test.wantMsg != "" {
|
||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||
|
assert.Equal(t,
|
||
|
test.wantMsg,
|
||
|
strings.TrimSpace(htmlDoc.doc.Find(".ui.message").Text()),
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
}
|