You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ta...@apache.org on 2015/03/30 12:36:59 UTC
[2/2] git commit: updated refs/heads/master to a05f1b2
cloudstack-8218
Signed-off-by: SrikanteswaraRao Talluri <ta...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a05f1b2f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a05f1b2f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a05f1b2f
Branch: refs/heads/master
Commit: a05f1b2fdbb52756d51f9e0fe99c1cd8977e94e2
Parents: 26123dd
Author: sadhu <su...@citrix.com>
Authored: Mon Mar 30 15:31:20 2015 +0530
Committer: SrikanteswaraRao Talluri <ta...@apache.org>
Committed: Mon Mar 30 16:06:20 2015 +0530
----------------------------------------------------------------------
test/integration/component/test_ldap.py | 107 ++++++++++++++++-----------
1 file changed, 63 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a05f1b2f/test/integration/component/test_ldap.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_ldap.py b/test/integration/component/test_ldap.py
index d7d20cc..2a5cf29 100644
--- a/test/integration/component/test_ldap.py
+++ b/test/integration/component/test_ldap.py
@@ -27,11 +27,13 @@ from marvin.cloudstackAPI import (updateConfiguration,
addLdapConfiguration,
deleteLdapConfiguration)
from marvin.cloudstackAPI import login
-from marvin.lib.utils import cleanup_resources,validateList
+from marvin.lib.utils import cleanup_resources
from nose.plugins.attrib import attr
import telnetlib
-import sys
+from ddt import ddt, data
+
+@ddt
class TestLdap(cloudstackTestCase):
"""
@@ -45,8 +47,8 @@ class TestLdap(cloudstackTestCase):
cls.api_client = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig()
cls._cleanup = []
- cls.delflag=0
- cls.reason=""
+ cls.delflag = 0
+ cls.reason = ""
@classmethod
def tearDownClass(cls):
@@ -75,30 +77,39 @@ class TestLdap(cloudstackTestCase):
self.acct.account = self.services[
"configurableData"]["ldap_account"]["username"]
self.acct.domainid = 1
- if self.acct.firstname == ""or self.acct.lastname == "" or self.acct.password == "" or self.acct.username == "" or \
- self.acct.username == ""or self.acct.account=="":
- self.debug("Please rerun the test by providing values in ldap configiration user details")
+
+ if self.acct.firstname == ""or self.acct.lastname == "" or self.acct.password == "" or self.acct.username == ""\
+ or self.services["configurableData"]["ldap_configuration"]["ldapUsername"] == "" or \
+ self.acct.account == "" or \
+ self.services["configurableData"]["ldap_configuration"]["ldapPassword"] == "":
+
+ self.debug("Please rerun the test by providing values in ldap configuration user details")
+ self.skipTest("Please rerun the test by providing proper values in configuration file")
+
else:
- self.delflag=1
+ self.delflag = 1
self.acctRes = self.apiClient.createAccount(self.acct)
- self.assertEquals(self.delflag,1,"LDAP account details are not provided,please check the configuration")
+ self.assertEquals(self.delflag, 1, "LDAP account details are not provided,please check the configuration")
return
def tearDown(self):
- try:
+ self.debug("In tear down%s" % self.delflag)
+ try:
deleteAcct = deleteAccount.deleteAccountCmd()
deleteAcct.id = self.acctRes.id
+
acct_name = self.acctRes.name
+
self.apiClient.deleteAccount(deleteAcct)
self.debug(
"Deleted the the following account name %s:" %
acct_name)
- if(self.ldapconfRes == 1):
- self._deleteLdapConfiguration(
+ if self.ldapconfRes == 1:
+ self._deleteldapconfiguration(
self.services["configurableData"]["ldap_configuration"])
except Exception as e:
@@ -107,25 +118,23 @@ class TestLdap(cloudstackTestCase):
return
@attr(tags=["advanced", "basic"], required_hardware="false")
-
def test_01_addLdapConfiguration(self):
"""
This test configures LDAP and attempts to authenticate as a user.
"""
- self.debug("start test")
self.ldapconfRes = self._addLdapConfiguration(
self.services["configurableData"]["ldap_configuration"])
- if(self.ldapconfRes == 1):
+ if self.ldapconfRes == 1:
self.debug("Ldap Configuration was succcessful")
- loginRes = self._checkLogin(
+ loginRes = self._checklogin(
self.services["configurableData"]["ldap_configuration"]["ldapUsername"],
self.services["configurableData"]["ldap_configuration"]["ldapPassword"])
self.debug(loginRes)
- self.assertEquals(loginRes, 1, "Ldap Authentication")
+ self.assertEquals(loginRes, 1, self.reason)
else:
@@ -136,19 +145,31 @@ class TestLdap(cloudstackTestCase):
1,
self.reason)
- self.debug("end test")
+ def test_02_validateldapsecuritypatch(self):
- def test_02_validateLdapSecurityPatch(self):
-
- self.debug("start test")
self.ldapconfRes = self._addLdapConfiguration(
self.services["configurableData"]["ldap_configuration"])
- self.assertEqual(self.ldapconfRes,1,"Ldap Configuration failed")
+ self.assertEqual(self.ldapconfRes, 1, "Ldap Configuration failed")
+ loginRes = self._checklogin(
+ self.services["configurableData"]["ldap_configuration"]["ldapUsername"], "")
+ self.assertNotEqual(loginRes, 1, "login API Successful with empty password")
- loginRes = self._checkLogin(
- self.services["configurableData"]["ldap_configuration"]["ldapUsername"],"")
- self.assertNotEqual(loginRes,1,"login API Successful with empty password")
- self.debug("end test")
+ @data("basedn", "ldapPassword")
+ def test_03_validateldapbindnobasedn(self, value):
+ """
+ This test is to verify ldapbind functionality without passing required bind parameters.
+ """
+ bindvalue = self.services["configurableData"]["ldap_configuration"][value]
+
+ if len(bindvalue) > 0:
+ self.services["configurableData"]["ldap_configuration"][value] = ""
+ self.ldapconfRes = self._addLdapConfiguration(self.services["configurableData"]["ldap_configuration"])
+ if self.reason.__contains__("addLdapConfiguration failed"):
+ self.assertEqual(self.ldapconfRes, 1, "Ldap Configuration not successful")
+ else:
+ self.assertNotEqual(self.ldapconfRes, 1, "Ldap Configuration successful with invalid values-i.e."
+ " allowing anonymous bind")
+ self.services["configurableData"]["ldap_configuration"][value] = value
def _addLdapConfiguration(self, ldapConfiguration):
"""
@@ -156,13 +177,12 @@ class TestLdap(cloudstackTestCase):
:param ldapConfiguration
"""
- self.chkConfig=self._checkLdapConfiguration(ldapConfiguration)
- if self.chkConfig==False:
+ self.chkConfig = self._checkLdapConfiguration(ldapConfiguration)
+ if not self.chkConfig:
return 0
# Setup Global settings
-
updateConfigurationCmd = updateConfiguration.updateConfigurationCmd()
updateConfigurationCmd.name = "ldap.basedn"
updateConfigurationCmd.value = ldapConfiguration['basedn']
@@ -216,32 +236,32 @@ class TestLdap(cloudstackTestCase):
return 1
except Exception as e:
self.debug("addLdapConfiguration failed %s Check the Passed passed ldap attributes" % e)
- self.reason="addLdapConfiguration failed %s Check the Passed passed ldap attributes" % e
+ self.reason = "addLdapConfiguration failed %s Check the Passed passed ldap attributes" % e
return 0
-
- def _checkLdapConfiguration(self,ldapConfiguration):
+ def _checkLdapConfiguration(self, ldapConfiguration):
""""
- This function checks the ldapconfiguration values
+ This function checks the passed ldap server in the configuration is up and running or not.
"""""
- flag=False
+ flag = False
try:
- tn=telnetlib.Telnet(ldapConfiguration['hostname'],ldapConfiguration['port'],timeout=15)
+ tn = telnetlib.Telnet(ldapConfiguration['hostname'], ldapConfiguration['port'], timeout=15)
if tn is not None:
tn.set_debuglevel(1)
print tn.msg("Connected to the server")
self.debug("Ldap Server is Up and listening on the port %s" % tn.msg("Connected to the server"))
- flag=True
+ flag = True
tn.close()
except Exception as e:
- self.debug(" Not able to reach the LDAP server ,please check the Services on LDAP %s and exception is %s" %((ldapConfiguration['hostname']), e))
- self.reason=" Not able to reach the LDAP server ,please check the Services on LDAP %s and exception is %s" %((ldapConfiguration['hostname']), e)
+ self.debug(" Not able to reach the LDAP server ,please check the Services on LDAP %s and exception is %s"
+ % ((ldapConfiguration['hostname']), e))
+ self.reason = "Not able to reach the LDAP server ,please check the Services on LDAP %s and exception is %s"\
+ % ((ldapConfiguration['hostname']), e)
return flag
-
- def _deleteLdapConfiguration(self, ldapConfiguration):
+ def _deleteldapconfiguration(self, ldapConfiguration):
"""
:param ldapConfiguration
@@ -259,7 +279,7 @@ class TestLdap(cloudstackTestCase):
self.debug("deleteLdapConfiguration failed %s" % e)
return 0
- def _checkLogin(self, username, password):
+ def _checklogin(self, username, password):
"""
:param username:
@@ -279,10 +299,9 @@ class TestLdap(cloudstackTestCase):
return 0
else:
self.debug("login successful")
- #self.reason="Login Successful"
return 1
except Exception as p:
self.debug("login operation failed %s" % p)
- #self.reason="Login operation Failed %s" %p
- self.debug("end of Login")
+ self.reason = "Login operation Failed %s" % p
+