0002-auth_fc-set-fc-as-verification-source-for-custom-att.patch
src/authentic2_auth_fc/utils.py | ||
---|---|---|
147 | 147 |
elif hasattr(user.attributes, attribute): |
148 | 148 |
if mapping.get('if-empty') and getattr(user.attributes, attribute): |
149 | 149 |
continue |
150 |
if mapping.get('verified', False): |
|
151 |
setattr(user.verified_attributes, attribute, value) |
|
152 |
else: |
|
153 |
setattr(user.attributes, attribute, value) |
|
150 |
verified = mapping.get('verified', False) |
|
151 |
accessor = user.verified_attributes if verified else user.attributes |
|
152 |
accessor._set_sourced_attr(attribute, value, 'fc') |
|
154 | 153 |
elif hasattr(user, attribute): |
155 | 154 |
save_user = True |
156 | 155 |
if mapping.get('if-empty') and getattr(user, attribute): |
tests/auth_fc/test_auth_fc.py | ||
---|---|---|
33 | 33 |
from authentic2.apps.authenticators.models import LoginPasswordAuthenticator |
34 | 34 |
from authentic2.apps.journal.models import Event |
35 | 35 |
from authentic2.custom_user.models import DeletedUser |
36 |
from authentic2.models import Attribute |
|
36 |
from authentic2.models import Attribute, AttributeValue
|
|
37 | 37 |
from authentic2_auth_fc import models |
38 | 38 |
from authentic2_auth_fc.backends import FcBackend |
39 | 39 |
from authentic2_auth_fc.utils import requests_retry_session |
... | ... | |
115 | 115 | |
116 | 116 |
assert user.verified_attributes.first_name == 'Ÿuñe' |
117 | 117 |
assert user.verified_attributes.last_name == 'Frédérique' |
118 |
first_name = Attribute.objects.get(name='first_name') |
|
119 |
last_name = Attribute.objects.get(name='last_name') |
|
120 |
first_name_value = AttributeValue.objects.with_owner(user).get(attribute=first_name) |
|
121 |
last_name_value = AttributeValue.objects.with_owner(user).get(attribute=last_name) |
|
122 |
assert first_name_value.last_verified_on |
|
123 |
assert last_name_value.last_verified_on |
|
124 |
assert first_name_value.verification_sources == ['fc'] |
|
125 |
assert last_name_value.verification_sources == ['fc'] |
|
118 | 126 |
assert path(response.location) == '/idp/' |
119 | 127 |
assert hooks.event[1]['kwargs']['name'] == 'login' |
120 | 128 |
assert hooks.event[1]['kwargs']['service'] == service |
121 |
- |