password_lockout tests: add assertLoginFailure()
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 22 Oct 2015 03:54:19 +0000 (16:54 +1300)
committerGarming Sam <garming@samba.org>
Mon, 14 Dec 2015 23:08:57 +0000 (00:08 +0100)
In a few places where a login should fail in a particular way, an
actual login success would not have triggered a test failure -- only
the wrong kind of login failure was caught.

This makes a helper function to deal with them all.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Ralph Boehme <slow@samba.org>
source4/dsdb/tests/python/password_lockout.py

index 133b40b9369c7595505136fe2542e1d56b3bb7a5..fddbb8f24c80d3aa2d932c1c87e24a47d346eaf9 100755 (executable)
@@ -233,6 +233,16 @@ userAccountControl: %d
         time.sleep(0.01)
         return res
 
+    def assertLoginFailure(self, url, creds, lp, errno=ERR_INVALID_CREDENTIALS):
+        try:
+            ldb = SamDB(url=url, credentials=creds, lp=lp)
+            self.fail("Login unexpectedly succeeded")
+        except LdbError, (num, msg):
+            if errno is not None:
+                self.assertEquals(num, errno, ("Login failed in the wrong way"
+                                               "(got err %d, expected %d)" %
+                                               (num, errno)))
+
     def setUp(self):
         super(PasswordTests, self).setUp()
 
@@ -1230,11 +1240,7 @@ unicodePwd:: """ + base64.b64encode("\"thatsAcomplPASS2\"".encode('utf-16-le'))
         # The wrong password
         creds_lockout.set_password("thatsAcomplPASS1x")
 
-        try:
-            ldb_lockout = SamDB(url=host_url, credentials=creds_lockout, lp=lp)
-
-        except LdbError, (num, msg):
-            self.assertEquals(num, ERR_INVALID_CREDENTIALS)
+        self.assertLoginFailure(host_url, creds_lockout, lp)
 
         res = self._check_account("cn=testuser,cn=users," + self.base_dn,
                                   badPwdCount=1,
@@ -1259,11 +1265,7 @@ unicodePwd:: """ + base64.b64encode("\"thatsAcomplPASS2\"".encode('utf-16-le'))
         # The wrong password
         creds_lockout.set_password("thatsAcomplPASS1x")
 
-        try:
-            ldb_lockout = SamDB(url=host_url, credentials=creds_lockout, lp=lp)
-
-        except LdbError, (num, msg):
-            self.assertEquals(num, ERR_INVALID_CREDENTIALS)
+        self.assertLoginFailure(host_url, creds_lockout, lp)
 
         res = self._check_account("cn=testuser,cn=users," + self.base_dn,
                                   badPwdCount=1,