summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-12-19 14:45:26 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-12-19 14:45:26 +0100
commit2633cccdd1dfd02205e9d81858d5fcdf571a3179 (patch)
tree4fdf61e72c266356fac4044f014f7bd184e09b82
parent05e22e2a6a219462164e919aa26541e3a59a177c (diff)
downloadpykolab-2633cccdd1dfd02205e9d81858d5fcdf571a3179.tar.gz
Adjust utils.parse_ldap_uri()
-rwxr-xr-xbin/kolab_smtp_access_policy.py2
-rw-r--r--pykolab/utils.py28
-rw-r--r--tests/unit/test-009-parse_ldap_uri.py17
3 files changed, 41 insertions, 6 deletions
diff --git a/bin/kolab_smtp_access_policy.py b/bin/kolab_smtp_access_policy.py
index 52ce566..151cc4c 100755
--- a/bin/kolab_smtp_access_policy.py
+++ b/bin/kolab_smtp_access_policy.py
@@ -269,7 +269,7 @@ class PolicyRequest(object):
if parsed_uri == None:
return None
- (_protocol, _server, _base_dn, _attrs, _scope, _filter) = \
+ (_protocol, _server, _port, _base_dn, _attrs, _scope, _filter) = \
parsed_uri
if len(_attrs) == 0:
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 4fca016..dc2b088 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -333,11 +333,29 @@ def parse_ldap_uri(uri):
or None on failure
"""
+ _protocol = uri.split(':')[0]
+
try:
- _protocol = uri.split(':')[0]
- _ldap_uri, _attr, _scope, _filter = uri.split('?')
- _server = _ldap_uri.split('//')[1].split('/')[0]
- _base_dn = _ldap_uri.split('//')[1].split('/')[1]
+ try:
+ _ldap_uri, _attr, _scope, _filter = uri.split('?')
+ _server = _ldap_uri.split('//')[1].split('/')[0]
+ _base_dn = _ldap_uri.split('//')[1].split('/')[1]
+
+ except:
+ _server = uri.split('//')[1].split('/')[0]
+ _attr = None
+ _scope = None
+ _filter = None
+ _base_dn = None
+
+ if len(_server.split(':')) > 1:
+ _port = _server.split(':')[1]
+ _server = _server.split(':')[0]
+ else:
+ if _protocol == 'ldaps':
+ _port = "636"
+ else:
+ _port = "389"
if _server == '':
_server = None
@@ -352,7 +370,7 @@ def parse_ldap_uri(uri):
if _filter == '':
_filter = "(objectclass=*)"
- return (_protocol, _server, _base_dn, _attr, _scope, _filter)
+ return (_protocol, _server, _port, _base_dn, _attr, _scope, _filter)
except:
return None
diff --git a/tests/unit/test-009-parse_ldap_uri.py b/tests/unit/test-009-parse_ldap_uri.py
new file mode 100644
index 0000000..d020f8d
--- /dev/null
+++ b/tests/unit/test-009-parse_ldap_uri.py
@@ -0,0 +1,17 @@
+import unittest
+
+from pykolab import utils
+
+class TestParseLdapUri(unittest.TestCase):
+
+ def test_001_ldap_uri(self):
+ ldap_uri = "ldap://localhost"
+ result = utils.parse_ldap_uri(ldap_uri)
+ self.assertEqual(result, ("ldap", "localhost", "389", None, None, None, None))
+
+ def test_002_ldap_uri_port(self):
+ ldap_uri = "ldap://localhost:389"
+ result = utils.parse_ldap_uri(ldap_uri)
+ self.assertEqual(result, ("ldap", "localhost", "389", None, None, None, None))
+
+