-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6595241
commit 4e99776
Showing
7 changed files
with
90 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -45,31 +45,22 @@ func TestIsEmailUsed(t *testing.T) { | |
func TestMakeEmailPrimary(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
||
email := &user_model.EmailAddress{ | ||
Email: "[email protected]", | ||
} | ||
err := user_model.MakeEmailPrimary(db.DefaultContext, email) | ||
err := user_model.MakeActiveEmailPrimary(db.DefaultContext, 9999999) | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, user_model.ErrEmailAddressNotExist{Email: email.Email}.Error()) | ||
assert.ErrorIs(t, err, user_model.ErrEmailAddressNotExist{}) | ||
|
||
email = &user_model.EmailAddress{ | ||
Email: "[email protected]", | ||
} | ||
err = user_model.MakeEmailPrimary(db.DefaultContext, email) | ||
email := unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "[email protected]"}) | ||
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID) | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, user_model.ErrEmailNotActivated.Error()) | ||
|
||
email = &user_model.EmailAddress{ | ||
Email: "[email protected]", | ||
} | ||
err = user_model.MakeEmailPrimary(db.DefaultContext, email) | ||
email = unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "[email protected]"}) | ||
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID) | ||
assert.Error(t, err) | ||
assert.True(t, user_model.IsErrUserNotExist(err)) | ||
|
||
email = &user_model.EmailAddress{ | ||
Email: "[email protected]", | ||
} | ||
err = user_model.MakeEmailPrimary(db.DefaultContext, email) | ||
email = unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "[email protected]"}) | ||
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID) | ||
assert.NoError(t, err) | ||
|
||
user, _ := user_model.GetUserByID(db.DefaultContext, int64(10)) | ||
|
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -107,13 +107,25 @@ func TestSignupEmailActive(t *testing.T) { | |
resp := MakeRequest(t, req, http.StatusOK) | ||
assert.Contains(t, resp.Body.String(), `A new confirmation email has been sent to <b>[email protected]</b>.`) | ||
|
||
// access "user/active" means trying to re-send the activation email | ||
// access "user/activate" means trying to re-send the activation email | ||
session := loginUserWithPassword(t, "test-user-1", "password1") | ||
resp = session.MakeRequest(t, NewRequest(t, "GET", "/user/activate"), http.StatusOK) | ||
assert.Contains(t, resp.Body.String(), "You have already requested an activation email recently") | ||
|
||
// access "user/active" with a valid activation code, then get the "verify password" page | ||
// access anywhere else will see a "Activate Your Account" prompt, and there is a chance to change email | ||
resp = session.MakeRequest(t, NewRequest(t, "GET", "/user/issues"), http.StatusOK) | ||
assert.Contains(t, resp.Body.String(), `<input id="change-email" name="change_email" `) | ||
|
||
// post to "user/activate" with a new email | ||
session.MakeRequest(t, NewRequestWithValues(t, "POST", "/user/activate", map[string]string{"change_email": "[email protected]"}), http.StatusSeeOther) | ||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "test-user-1"}) | ||
assert.Equal(t, "[email protected]", user.Email) | ||
email := unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "[email protected]"}) | ||
assert.False(t, email.IsActivated) | ||
assert.True(t, email.IsPrimary) | ||
|
||
// access "user/activate" with a valid activation code, then get the "verify password" page | ||
user = unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "test-user-1"}) | ||
activationCode := user.GenerateEmailActivateCode(user.Email) | ||
resp = session.MakeRequest(t, NewRequest(t, "GET", "/user/activate?code="+activationCode), http.StatusOK) | ||
assert.Contains(t, resp.Body.String(), `<input id="verify-password"`) | ||
|