From 3cc2f5e1fb70159473eefe4e5141db4eab8c92b0 Mon Sep 17 00:00:00 2001 From: Al Bailey Date: Mon, 28 Jan 2019 09:50:25 -0600 Subject: [PATCH] Change version of python-ldap to work with new setuptools setuptools 40.7.0 does not work with python-ldap 2.5.2 Added unit tests to verify the code calling the python-ldap functions. Closes-Bug: 1813668 Change-Id: I1e5c0bb7ec603d4d2e03032282e268cb2189775d Signed-off-by: Al Bailey --- .../sysinv/sysinv/sysinv/tests/test_utils.py | 43 +++++++++++++++++++ sysinv/sysinv/sysinv/test-requirements.txt | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/sysinv/sysinv/sysinv/sysinv/tests/test_utils.py b/sysinv/sysinv/sysinv/sysinv/tests/test_utils.py index 90e8bcdfb7..8961d365ac 100644 --- a/sysinv/sysinv/sysinv/sysinv/tests/test_utils.py +++ b/sysinv/sysinv/sysinv/sysinv/tests/test_utils.py @@ -20,6 +20,7 @@ import hashlib import os import os.path import tempfile +import wsme import mox import netaddr @@ -28,6 +29,7 @@ from oslo_config import cfg from six import StringIO from six.moves import builtins from sysinv.common import exception +from sysinv.common import service_parameter from sysinv.common import utils from sysinv.tests import base @@ -367,3 +369,44 @@ class IntLikeTestCase(base.TestCase): self.assertFalse( utils.is_int_like("0cc3346e-9fef-4445-abe6-5d2b2690ec64")) self.assertFalse(utils.is_int_like("a1")) + + +class LDAPTestCase(base.TestCase): + + def test_ldapurl(self): + # Bad Network address is not acceptable as ldap url + ldap_url = 'ldap://127' + self.assertRaises(wsme.exc.ClientSideError, + service_parameter._validate_ldap_url, + 'foo', + ldap_url) + + # loopback is not acceptable as ldap url + ldap_url = 'ldap://127.0.0.1' + self.assertRaises(wsme.exc.ClientSideError, + service_parameter._validate_ldap_url, + 'foo', + ldap_url) + + # localhost is not acceptable as ldap url + ldap_url = 'ldap://localhost:1234' + self.assertRaises(wsme.exc.ClientSideError, + service_parameter._validate_ldap_url, + 'foo', + ldap_url) + + # A valid ldap URL should not raise an exception + ldap_url = 'ldap://dns.example.com:389' + service_parameter._validate_ldap_url('foo', ldap_url) + + def test_ldap_dn(self): + # A poorly formatted ldap DN will raise a ClientSideError + ldap_dn = 'this is not a valid ldap dn' + self.assertRaises(wsme.exc.ClientSideError, + service_parameter._validate_ldap_dn, + 'foo', + ldap_dn) + + # A valid DN will not raise a ClientSideError + ldap_dn = 'uid=john.doe,ou=People,dc=example,dc=com' + service_parameter._validate_ldap_dn('foo', ldap_dn) diff --git a/sysinv/sysinv/sysinv/test-requirements.txt b/sysinv/sysinv/sysinv/test-requirements.txt index 4990bf5ab3..92eb395efb 100644 --- a/sysinv/sysinv/sysinv/test-requirements.txt +++ b/sysinv/sysinv/sysinv/test-requirements.txt @@ -28,7 +28,7 @@ libvirt-python>=1.2.5 migrate python-novaclient!=2.33.0,>=2.29.0 # Apache-2.0 python-cephclient -python-ldap>=2.4.22,<3.0.0 +python-ldap>=3.1.0 markupsafe docker # Babel>=0.9.6