mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-07-11 22:49:17 +02:00
[v11.0/forgejo] fix: user activation with uppercase email address (#8385)
Some checks failed
/ release (push) Has been cancelled
testing / backend-checks (push) Has been cancelled
testing / frontend-checks (push) Has been cancelled
testing / test-unit (push) Has been cancelled
testing / test-e2e (push) Has been cancelled
testing / test-remote-cacher (redis) (push) Has been cancelled
testing / test-remote-cacher (valkey) (push) Has been cancelled
testing / test-remote-cacher (garnet) (push) Has been cancelled
testing / test-remote-cacher (redict) (push) Has been cancelled
testing / test-mysql (push) Has been cancelled
testing / test-pgsql (push) Has been cancelled
testing / test-sqlite (push) Has been cancelled
testing / security-check (push) Has been cancelled
Some checks failed
/ release (push) Has been cancelled
testing / backend-checks (push) Has been cancelled
testing / frontend-checks (push) Has been cancelled
testing / test-unit (push) Has been cancelled
testing / test-e2e (push) Has been cancelled
testing / test-remote-cacher (redis) (push) Has been cancelled
testing / test-remote-cacher (valkey) (push) Has been cancelled
testing / test-remote-cacher (garnet) (push) Has been cancelled
testing / test-remote-cacher (redict) (push) Has been cancelled
testing / test-mysql (push) Has been cancelled
testing / test-pgsql (push) Has been cancelled
testing / test-sqlite (push) Has been cancelled
testing / security-check (push) Has been cancelled
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/8367
- Right before the call to user email activation, the user is updated [^1]. This causes the email to be lowered, which in turn makes the call to activate the user activation fail (on database where collation is case sensitive, which is the recommend collation by Forgejo).
- The code in `BeforeUpdate` is quite confusing, the comment has become slightly out of date and was reworded to reflect reality and its purpose. The code is also slightly reworked to only lower the email for the `AvatarEmail` field to avoid causing side-effect.
- Added unit test.
- Resolves forgejo/forgejo#8354
[^1]: 4927d4ee3d/routers/web/auth/auth.go (L785)
Co-authored-by: Gusted <postmaster@gusted.xyz>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8385
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
parent
f71e5ac323
commit
c0d11a365f
4 changed files with 39 additions and 3 deletions
7
models/fixtures/TestActivateUserEmail/email_address.yml
Normal file
7
models/fixtures/TestActivateUserEmail/email_address.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
-
|
||||
id: 1001
|
||||
uid: 1001
|
||||
email: AnotherTestUserWithUpperCaseEmail@otto.splvs.net
|
||||
lower_email: anothertestuserwithuppercaseemail@otto.splvs.net
|
||||
is_activated: false
|
||||
is_primary: true
|
12
models/fixtures/TestActivateUserEmail/user.yml
Normal file
12
models/fixtures/TestActivateUserEmail/user.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
-
|
||||
id: 1001
|
||||
lower_name: user1001
|
||||
name: user1001
|
||||
full_name: User That loves Upper Cases
|
||||
email: AnotherTestUserWithUpperCaseEmail@otto.splvs.net
|
||||
passwd: ZogKvWdyEx:password
|
||||
passwd_hash_algo: dummy
|
||||
avatar: ''
|
||||
avatar_email: anothertestuserwithuppercaseemail@otto.splvs.net
|
||||
login_name: user1
|
||||
created_unix: 1672578000
|
|
@ -181,3 +181,20 @@ func TestDeletePrimaryEmailAddressOfUser(t *testing.T) {
|
|||
assert.True(t, user_model.IsErrEmailAddressNotExist(err))
|
||||
assert.Nil(t, email)
|
||||
}
|
||||
|
||||
func TestActivateUserEmail(t *testing.T) {
|
||||
defer unittest.OverrideFixtures("models/fixtures/TestActivateUserEmail")()
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
t.Run("Activate email", func(t *testing.T) {
|
||||
require.NoError(t, user_model.ActivateUserEmail(t.Context(), 1001, "AnotherTestUserWithUpperCaseEmail@otto.splvs.net", true))
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{UID: 1001}, "is_activated = true")
|
||||
})
|
||||
|
||||
t.Run("Deactivate email", func(t *testing.T) {
|
||||
require.NoError(t, user_model.ActivateUserEmail(t.Context(), 1001, "AnotherTestUserWithUpperCaseEmail@otto.splvs.net", false))
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{UID: 1001}, "is_activated = false")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -181,11 +181,11 @@ func (u *User) BeforeUpdate() {
|
|||
u.MaxRepoCreation = -1
|
||||
}
|
||||
|
||||
// Organization does not need email
|
||||
u.Email = strings.ToLower(u.Email)
|
||||
// Ensure AvatarEmail is set for non-organization users, because organization
|
||||
// are not required to have a email set.
|
||||
if !u.IsOrganization() {
|
||||
if len(u.AvatarEmail) == 0 {
|
||||
u.AvatarEmail = u.Email
|
||||
u.AvatarEmail = strings.ToLower(u.Email)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue