Projet

Général

Profil

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

Paul Marillonnet, 02 novembre 2022 10:45

Télécharger (3,67 ko)

Voir les différences:

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

 tests/test_saml_auth.py | 13 +++++++++++--
 wcs/qommon/saml2.py     |  9 +++++++++
 2 files changed, 20 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
39 39
from quixote.http_request import parse_header
40 40

  
41 41
from . import _, errors, force_str, misc
42
from .misc import try_e164_format
42 43
from .publisher import get_cfg, get_logger
43 44
from .template import QommonTemplateResponse, error_page, html_top
44 45

  
......
489 490

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

  
494
        users_cfg = get_cfg('users', {})
495
        field_phone = users_cfg.get('field_phone', 'phone')
492 496
        for key, field_id in attribute_mapping.items():
493 497
            if key not in d:
494 498
                continue
......
500 504
                except ValueError as e:
501 505
                    get_publisher().record_error(exception=e, context='[SAML]', notify=True)
502 506
                    continue
507

  
508
            # user phone
509
            if key == field_phone:
510
                field_value = try_e164_format(field_value)
511

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