provisionning: integrate changes to UserSAMLIdentifier (#57084)
Cf. #56819
This commit is contained in:
parent
be9d312fc0
commit
44fc912ab4
|
@ -62,7 +62,7 @@ class NotificationProcessing:
|
|||
@classmethod
|
||||
def provision_user(cls, issuer, action, data, full=False):
|
||||
from django.contrib.auth import get_user_model
|
||||
from mellon.models import UserSAMLIdentifier
|
||||
from mellon.models import Issuer, UserSAMLIdentifier
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
@ -74,7 +74,9 @@ class NotificationProcessing:
|
|||
if action == 'provision':
|
||||
assert cls.check_valid_user(o)
|
||||
try:
|
||||
mellon_user = UserSAMLIdentifier.objects.get(issuer=issuer, name_id=o['uuid'])
|
||||
mellon_user = UserSAMLIdentifier.objects.get(
|
||||
issuer__entity_id=issuer, name_id=o['uuid']
|
||||
)
|
||||
user = mellon_user.user
|
||||
except UserSAMLIdentifier.DoesNotExist:
|
||||
try:
|
||||
|
@ -85,8 +87,9 @@ class NotificationProcessing:
|
|||
# temp user object
|
||||
random_uid = str(random.randint(1, 10000000000000))
|
||||
user = User.objects.create(username=random_uid)
|
||||
saml_issuer, created = Issuer.objects.get_or_create(entity_id=issuer)
|
||||
mellon_user = UserSAMLIdentifier.objects.create(
|
||||
user=user, issuer=issuer, name_id=o['uuid']
|
||||
user=user, issuer=saml_issuer, name_id=o['uuid']
|
||||
)
|
||||
user.first_name = o['first_name'][:30]
|
||||
user.last_name = o['last_name'][:150]
|
||||
|
|
|
@ -286,7 +286,7 @@ def test_provision_users(tenants):
|
|||
assert user.is_staff is False
|
||||
assert user.saml_identifiers.count() == 1
|
||||
usi = user.saml_identifiers.get()
|
||||
assert usi.issuer == 'http://idp.example.net/idp/saml/metadata'
|
||||
assert usi.issuer.entity_id == 'http://idp.example.net/idp/saml/metadata'
|
||||
assert usi.name_id == 'a' * 32
|
||||
assert user.groups.count() == 1
|
||||
group = user.groups.get()
|
||||
|
@ -339,7 +339,7 @@ def test_provision_users(tenants):
|
|||
assert user.is_staff is True
|
||||
assert user.saml_identifiers.count() == 1
|
||||
usi = user.saml_identifiers.get()
|
||||
assert usi.issuer == 'http://idp.example.net/idp/saml/metadata'
|
||||
assert usi.issuer.entity_id == 'http://idp.example.net/idp/saml/metadata'
|
||||
assert usi.name_id == 'a' * 32
|
||||
assert user.groups.count() == 1
|
||||
group = user.groups.get()
|
||||
|
|
|
@ -4,6 +4,7 @@ import pytest
|
|||
from _pytest.logging import LogCaptureHandler
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import override_settings
|
||||
from mellon.models import Issuer
|
||||
from tenant_schemas.utils import tenant_context
|
||||
|
||||
from hobo.journal import JournalHandler
|
||||
|
@ -34,7 +35,8 @@ def test_request_context_filter(caplog, settings, tenants, client):
|
|||
)
|
||||
user.set_password('john.doe')
|
||||
user.save()
|
||||
user.saml_identifiers.create(name_id='ab' * 16, issuer='https://idp.example.com')
|
||||
issuer, created = Issuer.objects.get_or_create(entity_id='https://idp.example.com')
|
||||
user.saml_identifiers.create(name_id='ab' * 16, issuer=issuer)
|
||||
|
||||
for tenant in tenants:
|
||||
settings.ALLOWED_HOSTS.append(tenant.domain_url)
|
||||
|
@ -97,7 +99,8 @@ def test_systemd(settings, tenants, client, journald_handler, sender):
|
|||
)
|
||||
user.set_password('john.doe')
|
||||
user.save()
|
||||
user.saml_identifiers.create(name_id='ab' * 16, issuer='https://idp.example.com')
|
||||
issuer, created = Issuer.objects.get_or_create(entity_id='https://idp.example.com')
|
||||
user.saml_identifiers.create(name_id='ab' * 16, issuer=issuer)
|
||||
|
||||
for tenant in tenants:
|
||||
settings.ALLOWED_HOSTS.append(tenant.domain_url)
|
||||
|
|
Loading…
Reference in New Issue