Skip to content

Commit 3411d7c

Browse files
committed
feat(ldap.dn): add ldap.dn.normalize()
1 parent b070418 commit 3411d7c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Lib/ldap/dn.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,8 @@ def is_dn(s,flags=0):
122122
return False
123123
else:
124124
return True
125+
126+
127+
def normalize(s, flags=0):
128+
"""Returns a normalized distinguished name (DN)"""
129+
return dn2str(str2dn(s, flags), flags)

Tests/t_ldap_dn.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ def test_dn2str(self):
222222
], ldap.DN_FORMAT_DCE),
223223
'/dc=com/dc=example/ou=Testing/uid=test42,cn=test42'
224224
)
225-
226225
self.assertEqual(
227226
ldap.dn.dn2str([
228227
[('cn', 'äöüÄÖÜß', ldap.AVA_BINARY)],
@@ -378,6 +377,35 @@ def test_explode_rdn(self):
378377
['cn=äöüÄÖÜß']
379378
)
380379

380+
def test_normalize(self):
381+
"""
382+
test function normalize()
383+
"""
384+
self.assertEqual(
385+
ldap.dn.normalize('uid = test42 , ou = Testing , dc = example , dc = com', flags=ldap.DN_FORMAT_LDAPV3),
386+
'uid=test42,ou=Testing,dc=example,dc=com'
387+
)
388+
self.assertEqual(
389+
ldap.dn.normalize('cn=äöüÄÖÜß,dc=example,dc=com', flags=0),
390+
'cn=äöüÄÖÜß,dc=example,dc=com'
391+
)
392+
self.assertEqual(
393+
ldap.dn.normalize('cn=#C3A4C3B6C3BCC384C396C39CC39F,dc=example,dc=com', flags=0),
394+
'cn=äöüÄÖÜß,dc=example,dc=com'
395+
)
396+
self.assertEqual(
397+
ldap.dn.normalize('cn=#C3A4C3B6C3BCC384C396C39CC39F,dc=example,dc=com', flags=ldap.DN_FORMAT_LDAPV3),
398+
'cn=#C3A4C3B6C3BCC384C396C39CC39F,dc=example,dc=com'
399+
)
400+
self.assertEqual(
401+
ldap.dn.normalize('cn=äöüÄÖÜß,dc=example,dc=com', flags=ldap.DN_FORMAT_LDAPV3),
402+
r'cn=\C3\A4\C3\B6\C3\BC\C3\84\C3\96\C3\9C\C3\9F,dc=example,dc=com'
403+
)
404+
self.assertEqual(
405+
ldap.dn.normalize('/ dc = com / dc = example / ou = Testing / uid = test42 , cn = test42', flags=ldap.DN_FORMAT_DCE),
406+
'/dc=com/dc=example/ou=Testing/uid=test42,cn=test42'
407+
)
408+
381409

382410
if __name__ == '__main__':
383411
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy