Skip to content

LDAPUrl now treats urlscheme cases insensitive #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/reference/ldapurl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ A :py:class:`LDAPUrl` object represents a complete LDAP URL.
.. autoclass:: ldapurl.LDAPUrl
:members:

.. versionchanged:: 3.4.0

The urlscheme is now case insensitive and always converted to lower
case. ``LDAP://localhost`` is equivalent to ``ldap://localhost``.


LDAP URL extensions
^^^^^^^^^^^^^^^^^^^
Expand Down
15 changes: 4 additions & 11 deletions Lib/ldapurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@


def isLDAPUrl(s):
"""Returns True if s is a LDAP URL, else False
"""
Returns 1 if s is a LDAP URL, 0 else
"""
s_lower = s.lower()
return \
s_lower.startswith('ldap://') or \
s_lower.startswith('ldaps://') or \
s_lower.startswith('ldapi://')
return s.lower().startswith(('ldap://', 'ldaps://', 'ldapi://'))


def ldapUrlEscape(s):
Expand Down Expand Up @@ -235,7 +230,7 @@ def __init__(
extensions=None,
who=None,cred=None
):
self.urlscheme=urlscheme
self.urlscheme=urlscheme.lower()
self.hostport=hostport
self.dn=dn
self.attrs=attrs
Expand Down Expand Up @@ -270,9 +265,7 @@ def _parse(self,ldap_url):
if not isLDAPUrl(ldap_url):
raise ValueError('Value %s for ldap_url does not seem to be a LDAP URL.' % (repr(ldap_url)))
scheme,rest = ldap_url.split('://',1)
self.urlscheme = scheme.strip()
if not self.urlscheme in ['ldap','ldaps','ldapi']:
raise ValueError('LDAP URL contains unsupported URL scheme %s.' % (self.urlscheme))
self.urlscheme = scheme.lower()
slash_pos = rest.find('/')
qemark_pos = rest.find('?')
if (slash_pos==-1) and (qemark_pos==-1):
Expand Down
30 changes: 28 additions & 2 deletions Tests/t_ldapurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@ class TestIsLDAPUrl(unittest.TestCase):
'ldap://host.com:6666/o=University%20of%20Michigan,':1,
'ldap://ldap.itd.umich.edu/c=GB?objectClass?one':1,
'ldap://ldap.question.com/o=Question%3f,c=US?mail':1,
'ldap://ldap.netscape.com/o=Babsco,c=US??(int=%5c00%5c00%5c00%5c04)':1,
'ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)':1,
'ldap:///??sub??bindname=cn=Manager%2co=Foo':1,
'ldap:///??sub??!bindname=cn=Manager%2co=Foo':1,
# More examples from various sources
'ldap://ldap.nameflow.net:1389/c%3dDE':1,
'ldap://root.openldap.org/dc=openldap,dc=org':1,
'ldap://root.openldap.org/dc=openldap,dc=org':1,
'ldaps://root.openldap.org/dc=openldap,dc=org':1,
'ldap://x500.mh.se/o=Mitthogskolan,c=se????1.2.752.58.10.2=T.61':1,
'ldp://root.openldap.org/dc=openldap,dc=org':0,
'ldap://localhost:1389/ou%3DUnstructured%20testing%20tree%2Cdc%3Dstroeder%2Cdc%3Dcom??one':1,
'ldaps://ldap.example.com/c%3dDE':1,
'ldapi:///dc=stroeder,dc=de????x-saslmech=EXTERNAL':1,
'LDAP://localhost': True,
'LDAPS://localhost': True,
'LDAPI://%2Frun%2Fldap.sock': True,
' ldap://space.example': False,
'ldap ://space.example': False,
}

def test_isLDAPUrl(self):
Expand All @@ -57,6 +62,11 @@ def test_isLDAPUrl(self):
ldap_url, result, expected,
)
)
if expected:
LDAPUrl(ldapUrl=ldap_url)
else:
with self.assertRaises(ValueError):
LDAPUrl(ldapUrl=ldap_url)


class TestParseLDAPUrl(unittest.TestCase):
Expand Down Expand Up @@ -145,6 +155,22 @@ class TestParseLDAPUrl(unittest.TestCase):
dn='dc=stroeder,dc=com',
),
),
(
'LDAPS://localhost:12345/dc=stroeder,dc=com',
LDAPUrl(
urlscheme='ldaps',
hostport='localhost:12345',
dn='dc=stroeder,dc=com',
),
),
(
'ldaps://localhost:12345/dc=stroeder,dc=com',
LDAPUrl(
urlscheme='LDAPS',
hostport='localhost:12345',
dn='dc=stroeder,dc=com',
),
),
(
'ldapi://%2ftmp%2fopenldap2-1389/dc=stroeder,dc=com',
LDAPUrl(
Expand Down
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