Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gitlint/gitlint_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re

import requests

from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation


Expand Down
3 changes: 2 additions & 1 deletion src/lasuite/oidc_login/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ def update_user_if_needed(self, user, claims):

claim_value = claims.get(key)
if claim_value and claim_value != getattr(user, key):
setattr(user, key, claim_value)
updated_claims[key] = claim_value

if updated_claims:
self.UserModel.objects.filter(sub=user.sub).update(**updated_claims)
user.save(update_fields=tuple(updated_claims.keys()))
22 changes: 22 additions & 0 deletions tests/oidc_login/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,25 @@ def test_user_sub_field_for_get_existing_user(settings):

User.objects.create(email="test@example.com")
assert OIDCAuthenticationBackend().get_existing_user("test@example.com", None)


def test_authentication_update_existing_user_without_sub_with_other_user_without_sub(monkeypatch):
"""
If an existing user has an empty sub but matches the email,
the user should be updated with the new sub.
The other sub-less users should be ignored.
"""
klass = OIDCAuthenticationBackend()
db_user = factories.UserFactory(sub=None)
# Create another user without a sub
factories.UserFactory(sub=None)

def get_userinfo_mocked(*args):
return {"sub": "123", "email": db_user.email}

monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)

user = klass.get_or_create_user(access_token="test-token", id_token=None, payload=None)

assert user == db_user
assert user.sub == "123"
2 changes: 1 addition & 1 deletion tests/test_project/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class User(AbstractBaseUser):
"""User model for the application."""

sub = models.CharField("sub", max_length=255, unique=True)
sub = models.CharField("sub", max_length=255, unique=True, null=True) # noqa: DJ001
name = models.CharField("name", max_length=255, blank=True, null=True) # noqa: DJ001
email = models.EmailField("email address", blank=True, null=True) # noqa: DJ001
is_active = models.BooleanField("active", default=True)
Expand Down