-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add email validity check #13475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add email validity check #13475
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
df0bcef
Improve error feedback for duplicate deploy keys
c4341c2
API returns 422 error when key with name exists
f46c127
Merge branch 'master' into master
zeripath e8745e3
Merge remote-tracking branch 'upstream/master'
1a539ef
Add email validity checking
354f957
Merge remote-tracking branch 'upstream/master'
chrisshyi 2d2b60d
Merge remote-tracking branch 'upstream/master'
b400388
Add further tests
bfdb76c
Add signup email tests
chrisshyi fb476e2
Add email validity check for linking existing account
chrisshyi 3684d64
Address PR comments
chrisshyi 751c717
Merge branch 'master' into master
chrisshyi 19d3003
Remove unneeded DB session
chrisshyi 1df58a5
Merge branch 'master' of github.com:chrisshyi/gitea
chrisshyi 24ecaba
Move email check to updateUser
chrisshyi 9465ec3
Merge branch 'master' into master
lunny e9d284f
Merge branch 'master' into master
techknowlogick f0df7e6
Merge branch 'master' into master
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,3 +144,22 @@ func TestAPIListUsersNonAdmin(t *testing.T) { | |
req := NewRequestf(t, "GET", "/api/v1/admin/users?token=%s", token) | ||
session.MakeRequest(t, req, http.StatusForbidden) | ||
} | ||
|
||
func TestAPICreateUserInvalidEmail(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
adminUsername := "user1" | ||
session := loginUser(t, adminUsername) | ||
token := getTokenForLoggedInUser(t, session) | ||
urlStr := fmt.Sprintf("/api/v1/admin/users?token=%s", token) | ||
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{ | ||
"email": "[email protected]\r\n", | ||
"full_name": "invalid user", | ||
"login_name": "invalidUser", | ||
"must_change_password": "true", | ||
"password": "password", | ||
"send_notify": "true", | ||
"source_id": "0", | ||
"username": "invalidUser", | ||
}) | ||
session.MakeRequest(t, req, http.StatusUnprocessableEntity) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,14 @@ | |
package integrations | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/unknwon/i18n" | ||
) | ||
|
||
func TestSignup(t *testing.T) { | ||
|
@@ -28,3 +32,37 @@ func TestSignup(t *testing.T) { | |
req = NewRequest(t, "GET", "/exampleUser") | ||
MakeRequest(t, req, http.StatusOK) | ||
} | ||
|
||
func TestSignupEmail(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
|
||
setting.Service.EnableCaptcha = false | ||
|
||
tests := []struct { | ||
email string | ||
wantStatus int | ||
wantMsg string | ||
}{ | ||
{"[email protected]\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, | ||
{"[email protected]\r", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, | ||
{"[email protected]\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, | ||
{"[email protected]", http.StatusFound, ""}, | ||
} | ||
|
||
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()), | ||
) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,6 +329,21 @@ func TestCreateUser(t *testing.T) { | |
assert.NoError(t, DeleteUser(user)) | ||
} | ||
|
||
func TestCreateUserInvalidEmail(t *testing.T) { | ||
user := &User{ | ||
Name: "GiteaBot", | ||
Email: "[email protected]\r\n", | ||
Passwd: ";p['////..-++']", | ||
IsAdmin: false, | ||
Theme: setting.UI.DefaultTheme, | ||
MustChangePassword: false, | ||
} | ||
|
||
err := CreateUser(user) | ||
assert.Error(t, err) | ||
assert.True(t, IsErrEmailInvalid(err)) | ||
} | ||
|
||
func TestCreateUser_Issue5882(t *testing.T) { | ||
|
||
// Init settings | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,3 +87,33 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) { | |
assert.Equal(t, email, u.Email) | ||
assert.False(t, u.MustChangePassword) | ||
} | ||
|
||
func TestNewUserPost_InvalidEmail(t *testing.T) { | ||
|
||
models.PrepareTestEnv(t) | ||
ctx := test.MockContext(t, "admin/users/new") | ||
|
||
u := models.AssertExistsAndLoadBean(t, &models.User{ | ||
IsAdmin: true, | ||
ID: 2, | ||
}).(*models.User) | ||
|
||
ctx.User = u | ||
|
||
username := "gitea" | ||
email := "[email protected]\r\n" | ||
|
||
form := auth.AdminCreateUserForm{ | ||
LoginType: "local", | ||
LoginName: "local", | ||
UserName: username, | ||
Email: email, | ||
Password: "abc123ABC!=$", | ||
SendNotify: false, | ||
MustChangePassword: false, | ||
} | ||
|
||
NewUserPost(ctx, form) | ||
|
||
assert.NotEmpty(t, ctx.Flash.ErrorMsg) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.