Commit 02efba12 authored by lukas.burgey's avatar lukas.burgey

Merge branch 'username'

parents 3303ccd8 8e55e459
Pipeline #109037 passed with stage
in 1 minute and 23 seconds
......@@ -222,3 +222,24 @@ def test_idp_deletion(deployed_deployment, idp, user, service, vo):
state.refresh_from_db()
assert state.is_pending
assert state.is_orphaned
def test_construct_from_userinfo(idp, userinfo):
test_value = 0
userinfo = {
'sub': 'foo',
'iss': idp.issuer_uri,
'test_value': test_value,
}
user = User.construct_from_userinfo(userinfo, idp)
assert user.userinfo['test_value'] == test_value
# change the test value and see if the userinfo actually gets changed
test_value = 1
userinfo = {
'sub': 'foo',
'iss': idp.issuer_uri,
'test_value': test_value,
}
user = User.construct_from_userinfo(userinfo, idp)
assert user.userinfo['test_value'] == test_value
......@@ -127,30 +127,20 @@ class User(AbstractUser):
if 'sub' not in userinfo:
raise ValueError('Missing attribute in userinfo: sub')
username = '{}@{}'.format(
userinfo['sub'],
idp.name.replace(' ', '_'),
)
if cls.objects.filter(
username=username,
idp=idp,
).exists():
return cls.objects.get(
username=username,
idp=idp,
)
user = cls(
user, created = cls.objects.get_or_create(
user_type=cls.TYPE_CHOICE_USER,
username=username,
sub=userinfo['sub'],
idp=idp,
defaults={
'username': '{}@{}'.format(userinfo['sub'], idp.id),
},
)
user.save()
user.update_userinfo(userinfo)
LOGGER.info('construct_from_userinfo: new user: %s', user)
if created:
LOGGER.info('construct_from_userinfo: new user: %s', user)
user.update_userinfo(userinfo)
user.save()
return user
@classmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment