Projet

Général

Profil

0001-ldap-test-the-multivalued-attribute-behavior-51453.patch

Loïc Dachary, 30 avril 2021 13:30

Télécharger (2,96 ko)

Voir les différences:

Subject: [PATCH] ldap: test the multivalued attribute behavior (#51453)

* get_attributes() returns all the values of the attribute
* only the first value is copied in User or LDAPUser

License: MIT
 tests/test_ldap.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
tests/test_ldap.py
53 53
UPASS = u'passé'
54 54
EMAIL = 'etienne.michu@example.net'
55 55
CARLICENSE = '123445ABC'
56
PHONE1 = '+3312345678'
57
PHONE2 = '+4912345678'
56 58

  
57 59
EO_O = "EO"
58 60
EO_STREET = "169 rue du Chateau"
......
132 134
mail: etienne.michu@example.net
133 135
jpegPhoto:: ACOE
134 136
carLicense: {cl}
137
mobile: {phone1}
138
mobile: {phone2}
135 139
o: EO
136 140
o: EE
137 141
# memberOf is not defined on OpenLDAP so we use street for storing DN like
......
162 166
            uid=UID,
163 167
            password=PASS,
164 168
            cl=CARLICENSE,
169
            phone1=PHONE1,
170
            phone2=PHONE2,
165 171
            eo_o=EO_O,
166 172
            eo_street=EO_STREET,
167 173
            eo_postalcode=EO_POSTALCODE,
......
1508 1514
        )
1509 1515

  
1510 1516

  
1517
def test_get_multivalued_attribute(slapd, settings, db, rf):
1518
    settings.LDAP_AUTH_SETTINGS = [
1519
        {
1520
            'url': [slapd.ldap_url],
1521
            'basedn': u'o=ôrga',
1522
            'use_tls': False,
1523
            'attributes': ['mobile'],
1524
            'user_attributes': [
1525
                {
1526
                    'from_ldap': 'mobile',
1527
                    'to_user': 'mobile',
1528
                }
1529
            ],
1530
        }
1531
    ]
1532

  
1533
    # create a mobile attribute
1534
    models.Attribute.objects.create(
1535
        label='mobile',
1536
        name='mobile',
1537
        kind='string',
1538
        required=False,
1539
        user_visible=True,
1540
        user_editable=False,
1541
        asked_on_registration=False,
1542
        multiple=False,
1543
    )
1544

  
1545
    #
1546
    # get_attributes() returns all the values of the attribute
1547
    #
1548
    user = authenticate(username=USERNAME, password=UPASS)
1549
    assert user
1550
    assert user.get_attributes(object(), {}) == {
1551
        'dn': 'cn=étienne michu,o=\xf4rga',
1552
        'givenname': [u'Étienne'],
1553
        'mail': [u'etienne.michu@example.net'],
1554
        'sn': [u'Michu'],
1555
        'uid': [u'etienne.michu'],
1556
        'mobile': [PHONE1, PHONE2],
1557
    }
1558

  
1559
    #
1560
    # Only the first value is copied in User or LDAPUser
1561
    #
1562
    assert user.attributes.mobile == PHONE1
1563

  
1564
    assert User.objects.count() == 1
1565
    user = User.objects.get()
1566
    assert user.username == u'%s@ldap' % USERNAME
1567
    assert user.attributes.mobile == PHONE1
1568

  
1569

  
1511 1570
def test_get_attributes(slapd, settings, db, rf):
1512 1571
    settings.LDAP_AUTH_SETTINGS = [
1513 1572
        {
1514
-