Skip to content

Commit dc857cf

Browse files
committed
feat(ldap.dn): add ldap.dn.normalize()
1 parent 5237194 commit dc857cf

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,27 @@ def test_explode_rdn(self):
345345
['cn=äöüÄÖÜß']
346346
)
347347

348+
def test_normalize(self):
349+
"""
350+
test function normalize()
351+
"""
352+
self.assertEqual(
353+
ldap.dn.normalize('uid = test42 , ou = Testing , dc = example , dc = com', flags=ldap.DN_FORMAT_LDAPV3),
354+
'uid=test42,ou=Testing,dc=example,dc=com'
355+
)
356+
self.assertEqual(
357+
ldap.dn.normalize('cn=äöüÄÖÜß,dc=example,dc=com', flags=0),
358+
'cn=äöüÄÖÜß,dc=example,dc=com'
359+
)
360+
self.assertEqual(
361+
ldap.dn.normalize('cn=äöüÄÖÜß,dc=example,dc=com', flags=ldap.DN_FORMAT_LDAPV3),
362+
r'cn=\C3\A4\C3\B6\C3\BC\C3\84\C3\96\C3\9C\C3\9F,dc=example,dc=com'
363+
)
364+
self.assertEqual(
365+
ldap.dn.normalize('/ dc = com / dc = example / ou = Testing / uid = test42 , cn = test42', flags=ldap.DN_FORMAT_DCE),
366+
'/dc=com/dc=example/ou=Testing/uid=test42,cn=test42'
367+
)
368+
348369

349370
if __name__ == '__main__':
350371
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