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:58 UTC

[1/2] git commit: updated refs/heads/master to a05f1b2

Repository: cloudstack
Updated Branches:
  refs/heads/master 2de12b50f -> a05f1b2fd


CLOUDSTACK-8218:added missing scenrio and additional checks for betterdebugging

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/26123dd0
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/26123dd0
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/26123dd0

Branch: refs/heads/master
Commit: 26123dd079242cb57661df730d3a59f148ddcc32
Parents: 2de12b5
Author: sadhu <su...@citrix.com>
Authored: Thu Feb 19 17:00:22 2015 +0530
Committer: SrikanteswaraRao Talluri <ta...@apache.org>
Committed: Mon Mar 30 16:06:19 2015 +0530

----------------------------------------------------------------------
 test/integration/component/test_ldap.py | 89 +++++++++++++++++++++-------
 1 file changed, 68 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/26123dd0/test/integration/component/test_ldap.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_ldap.py b/test/integration/component/test_ldap.py
index 3464022..d7d20cc 100644
--- a/test/integration/component/test_ldap.py
+++ b/test/integration/component/test_ldap.py
@@ -27,9 +27,10 @@ from marvin.cloudstackAPI import (updateConfiguration,
                                   addLdapConfiguration,
                                   deleteLdapConfiguration)
 from marvin.cloudstackAPI import login
-from marvin.lib.utils import cleanup_resources
+from marvin.lib.utils import cleanup_resources,validateList
 from nose.plugins.attrib import attr
-
+import telnetlib
+import sys
 
 class TestLdap(cloudstackTestCase):
 
@@ -44,6 +45,8 @@ class TestLdap(cloudstackTestCase):
         cls.api_client = testClient.getApiClient()
         cls.services = testClient.getParsedTestDataConfig()
         cls._cleanup = []
+        cls.delflag=0
+        cls.reason=""
 
     @classmethod
     def tearDownClass(cls):
@@ -57,7 +60,6 @@ class TestLdap(cloudstackTestCase):
     def setUp(self):
 
         self.apiClient = self.testClient.getApiClient()
-
         self.acct = createAccount.createAccountCmd()
         self.acct.accounttype = 0
         self.acct.firstname = self.services[
@@ -73,39 +75,43 @@ class TestLdap(cloudstackTestCase):
         self.acct.account = self.services[
             "configurableData"]["ldap_account"]["username"]
         self.acct.domainid = 1
-
-        self.acctRes = self.apiClient.createAccount(self.acct)
-
+        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")
+        else:
+            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")
         return
 
     def tearDown(self):
 
         try:
-            deleteAcct = deleteAccount.deleteAccountCmd()
-            deleteAcct.id = self.acctRes.id
-
-            acct_name = self.acctRes.name
 
-            self.apiClient.deleteAccount(deleteAcct)
+                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)
+                self.debug(
+                    "Deleted the the following account name %s:" %
+                    acct_name)
 
-            if(self.ldapconfRes == 1):
-                self._deleteLdapConfiguration(
-                    self.services["configurableData"]["ldap_configuration"])
+                if(self.ldapconfRes == 1):
+                    self._deleteLdapConfiguration(
+                        self.services["configurableData"]["ldap_configuration"])
 
         except Exception as e:
-            raise Exception("Warning: Exception during cleanup : %s" % e)
+                raise Exception("Warning: Exception during cleanup : %s" % e)
+
         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(
@@ -128,19 +134,35 @@ class TestLdap(cloudstackTestCase):
             self.assertEquals(
                 self.ldapconfRes,
                 1,
-                "addLdapConfiguration failed")
+                self.reason)
 
         self.debug("end test")
 
+    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")
+
+        loginRes = self._checkLogin(
+                self.services["configurableData"]["ldap_configuration"]["ldapUsername"],"")
+        self.assertNotEqual(loginRes,1,"login API Successful with empty password")
+        self.debug("end test")
+
     def _addLdapConfiguration(self, ldapConfiguration):
         """
 
         :param ldapConfiguration
 
         """
+        self.chkConfig=self._checkLdapConfiguration(ldapConfiguration)
+        if self.chkConfig==False:
+            return 0
 
         # Setup Global settings
 
+
         updateConfigurationCmd = updateConfiguration.updateConfigurationCmd()
         updateConfigurationCmd.name = "ldap.basedn"
         updateConfigurationCmd.value = ldapConfiguration['basedn']
@@ -193,9 +215,32 @@ class TestLdap(cloudstackTestCase):
             self.debug("addLdapConfiguration was successful")
             return 1
         except Exception as e:
-            self.debug("addLdapConfiguration failed %s" % 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
             return 0
 
+
+    def _checkLdapConfiguration(self,ldapConfiguration):
+
+        """"
+            This function checks the ldapconfiguration values
+             """""
+
+        flag=False
+        try:
+            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
+                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)
+        return flag
+
+
     def _deleteLdapConfiguration(self, ldapConfiguration):
         """
 
@@ -234,8 +279,10 @@ 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")


[2/2] git commit: updated refs/heads/master to a05f1b2

Posted by ta...@apache.org.
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
+