Projet

Général

Profil

0008-saml2-retrieve-and-store-user-phone-at-sso-time-6983.patch

Paul Marillonnet, 16 novembre 2022 13:50

Télécharger (3,14 ko)

Voir les différences:

Subject: [PATCH 8/8] saml2: retrieve and store user phone at sso time (#69838)

 tests/test_saml_auth.py | 13 +++++++++++--
 wcs/qommon/saml2.py     |  2 ++
 2 files changed, 13 insertions(+), 2 deletions(-)
tests/test_saml_auth.py
54 54
        'saml2_base_url': 'http://example.net/saml',
55 55
        'saml2_providerid': 'http://example.net/saml/metadata',
56 56
    }
57
    pub.cfg['users'] = {
58
        'field_phone': '_phone',
59
    }
57 60
    MethodAdminDirectory().generate_rsa_keypair()
58 61
    setup_idps(pub)
59 62
    pub.user_class.wipe()
......
150 153
    value = lasso.MiscTextNode.newWithString('john.doe@example.com')
151 154
    value.textChild = True
152 155
    login.assertion.addAttributeWithNode('email', lasso.SAML2_ATTRIBUTE_NAME_FORMAT_BASIC, value)
156
    value = lasso.MiscTextNode.newWithString('+33123456789')
157
    value.textChild = True
158
    login.assertion.addAttributeWithNode('phone', lasso.SAML2_ATTRIBUTE_NAME_FORMAT_BASIC, value)
153 159
    value = lasso.MiscTextNode.newWithString('2000-01-01')
154 160
    value.textChild = True
155 161
    login.assertion.addAttributeWithNode('birthdate', lasso.SAML2_ATTRIBUTE_NAME_FORMAT_BASIC, value)
156
    for a_name in ['first_name', 'last_name', 'email']:
162
    for a_name in ['first_name', 'last_name', 'email', 'phone']:
157 163
        value = lasso.MiscTextNode.newWithString(a_name)
158 164
        value.textChild = True
159 165
        login.assertion.addAttributeWithNode(
......
279 285
    assert pub.user_class.count() == 1
280 286
    user = pub.user_class.select()[0]
281 287
    assert user.verified_fields
282
    assert len(user.verified_fields) == 3
288
    assert len(user.verified_fields) == 4
283 289
    assert user.form_data['_birthdate'].tm_year == 2000
290
    assert user.form_data['_phone'] == '+33123456789'
291
    assert user.email == 'john.doe@example.com'
292
    assert user.phone == '+33123456789'
284 293
    assert user.roles == [role.id]  # other uuid is ignored as unknown
285 294

  
286 295
    assert ('enrolling user %s in Foo' % user.id) in [x.message for x in caplog.records]
wcs/qommon/saml2.py
489 489

  
490 490
        if user.form_data is None:
491 491
            user.form_data = {}
492

  
492 493
        for key, field_id in attribute_mapping.items():
493 494
            if key not in d:
494 495
                continue
......
500 501
                except ValueError as e:
501 502
                    get_publisher().record_error(exception=e, context='[SAML]', notify=True)
502 503
                    continue
504

  
503 505
            if user.form_data.get(field_id) != field_value:
504 506
                user.form_data[field_id] = field_value
505 507
                logger.info('setting field %s of user %s to value %r', field_id, user.id, field_value)
506
-