39 |
39 |
from authentic2.custom_user.models import DeletedUser
|
40 |
40 |
from authentic2.models import Attribute, AttributeValue
|
41 |
41 |
from authentic2.utils.misc import last_authentication_event
|
|
42 |
from authentic2_auth_oidc.backends import OIDCBackend
|
42 |
43 |
from authentic2_auth_oidc.models import OIDCAccount, OIDCClaimMapping, OIDCProvider
|
43 |
44 |
from authentic2_auth_oidc.utils import (
|
44 |
45 |
IDToken,
|
... | ... | |
944 |
945 |
with utils.check_log(caplog, 'found user using username'):
|
945 |
946 |
with oidc_provider_mock(oidc_provider, oidc_provider_jwkset, code, nonce=nonce):
|
946 |
947 |
response = app.get(login_callback_url(oidc_provider), params={'code': code, 'state': state})
|
|
948 |
|
|
949 |
|
|
950 |
def test_link_by_email(app, caplog, code):
|
|
951 |
oidc_provider = make_oidc_provider(idtoken_algo=OIDCProvider.ALGO_HMAC)
|
|
952 |
ou = get_default_ou()
|
|
953 |
ou.email_is_unique = True
|
|
954 |
ou.save()
|
|
955 |
|
|
956 |
user = User.objects.create(ou=ou, email='john.doe@example.com')
|
|
957 |
assert User.objects.count() == 1
|
|
958 |
assert OIDCAccount.objects.count() == 0
|
|
959 |
|
|
960 |
response = app.get('/').maybe_follow()
|
|
961 |
assert oidc_provider.name in response.text
|
|
962 |
response = response.click(oidc_provider.name)
|
|
963 |
location = urllib.parse.urlparse(response.location)
|
|
964 |
query = QueryDict(location.query)
|
|
965 |
state = query['state']
|
|
966 |
nonce = query['nonce']
|
|
967 |
|
|
968 |
with oidc_provider_mock(
|
|
969 |
oidc_provider,
|
|
970 |
oidc_provider_jwkset,
|
|
971 |
code,
|
|
972 |
nonce=nonce,
|
|
973 |
extra_user_info={'email': 'JOHN.DOE@examplE.COM'},
|
|
974 |
):
|
|
975 |
response = app.get(login_callback_url(oidc_provider), params={'code': code, 'state': state})
|
|
976 |
|
|
977 |
assert app.session['_auth_user_id'] == str(user.id)
|
|
978 |
assert User.objects.count() == 1
|
|
979 |
assert OIDCAccount.objects.count() == 1
|
947 |
|
-
|