Projet

Général

Profil

0002-auth_fc-set-fc-as-verification-source-for-custom-att.patch

Paul Marillonnet, 05 décembre 2022 17:24

Télécharger (2,38 ko)

Voir les différences:

Subject: [PATCH 2/3] auth_fc: set fc as verification source for custom
 attributes (#65612)

 src/authentic2_auth_fc/utils.py | 7 +++----
 tests/auth_fc/test_auth_fc.py   | 8 ++++++++
 2 files changed, 11 insertions(+), 4 deletions(-)
src/authentic2_auth_fc/utils.py
156 156
        elif hasattr(user.attributes, attribute):
157 157
            if mapping.get('if-empty') and getattr(user.attributes, attribute):
158 158
                continue
159
            if mapping.get('verified', False):
160
                setattr(user.verified_attributes, attribute, value)
161
            else:
162
                setattr(user.attributes, attribute, value)
159
            verified = mapping.get('verified', False)
160
            accessor = user.verified_attributes if verified else user.attributes
161
            accessor._set_sourced_attr(attribute, value, 'fc')
163 162
        elif hasattr(user, attribute):
164 163
            save_user = True
165 164
            if mapping.get('if-empty') and getattr(user, attribute):
tests/auth_fc/test_auth_fc.py
132 132

  
133 133
    assert user.verified_attributes.first_name == 'Ÿuñe'
134 134
    assert user.verified_attributes.last_name == 'Frédérique'
135
    first_name = Attribute.objects.get(name='first_name')
136
    last_name = Attribute.objects.get(name='last_name')
137
    first_name_value = AttributeValue.objects.with_owner(user).get(attribute=first_name)
138
    last_name_value = AttributeValue.objects.with_owner(user).get(attribute=last_name)
139
    assert first_name_value.last_verified_on
140
    assert last_name_value.last_verified_on
141
    assert first_name_value.verification_sources == ['fc']
142
    assert last_name_value.verification_sources == ['fc']
135 143
    assert path(response.location) == '/idp/'
136 144
    assert hooks.event[1]['kwargs']['name'] == 'login'
137 145
    assert hooks.event[1]['kwargs']['service'] == service
138
-