mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-05 19:30:58 +00:00
fix: ensure GetUserByEmail only considers validated emails (#9075)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9075 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
48e29ff861
2 changed files with 24 additions and 2 deletions
|
@ -1202,8 +1202,8 @@ func GetUserByEmail(ctx context.Context, email string) (*User, error) {
|
||||||
|
|
||||||
email = strings.ToLower(email)
|
email = strings.ToLower(email)
|
||||||
// Otherwise, check in alternative list for activated email addresses
|
// Otherwise, check in alternative list for activated email addresses
|
||||||
emailAddress := &EmailAddress{LowerEmail: email, IsActivated: true}
|
emailAddress := &EmailAddress{}
|
||||||
has, err := db.GetEngine(ctx).Get(emailAddress)
|
has, err := db.GetEngine(ctx).Where("lower_email = ? AND is_activated = ?", email, true).Get(emailAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -996,3 +996,25 @@ func TestPronounsPrivacy(t *testing.T) {
|
||||||
assert.Equal(t, "any", user.GetPronouns(true))
|
assert.Equal(t, "any", user.GetPronouns(true))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetUserByEmail(t *testing.T) {
|
||||||
|
require.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
|
t.Run("Normal", func(t *testing.T) {
|
||||||
|
u, err := user_model.GetUserByEmail(t.Context(), "user2@example.com")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 2, u.ID)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Not activated", func(t *testing.T) {
|
||||||
|
u, err := user_model.GetUserByEmail(t.Context(), "user11@example.com")
|
||||||
|
require.ErrorIs(t, err, user_model.ErrUserNotExist{Name: "user11@example.com"})
|
||||||
|
assert.Nil(t, u)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Not primary", func(t *testing.T) {
|
||||||
|
u, err := user_model.GetUserByEmail(t.Context(), "user1-3@example.com")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 1, u.ID)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue