python:samba/tests: add simple 'samba-tool user getpassword' test
authorStefan Metzmacher <metze@samba.org>
Tue, 16 Feb 2016 02:19:58 +0000 (03:19 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 22 Jul 2016 14:03:26 +0000 (16:03 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/samba_tool/user.py

index 645eb402c64a8976a5ccb83901174c64364a5c02..0ce7f19a8427be8d1a3d43b9ec9669ec15692f7e 100644 (file)
 
 import os
 import time
+import base64
 import ldb
 from samba.tests.samba_tool.base import SambaToolCmdTest
 from samba import (
+        credentials,
         nttime2unix,
         dsdb
         )
@@ -114,13 +116,33 @@ class UserCmdTestCase(SambaToolCmdTest):
 
         for user in self.users:
             newpasswd = self.randomPass()
+            creds = credentials.Credentials()
+            creds.set_anonymous()
+            creds.set_password(newpasswd)
+            nthash = creds.get_nt_hash()
+            attributes = "sAMAccountName,unicodePwd,supplementalCredentials"
+            unicodePwd = base64.b64encode(creds.get_nt_hash())
+
             (result, out, err) = self.runsubcmd("user", "setpassword",
                                                 user["name"],
                                                 "--newpassword=%s" % newpasswd)
-            self.assertCmdSuccess(result, "Ensure setpassword runs")
+            self.assertCmdSuccess(result, "Ensure setpassword runs")
             self.assertEquals(err,"","setpassword without url")
             self.assertMatch(out, "Changed password OK", "setpassword without url")
 
+            (result, out, err) = self.runsubcmd("user", "getpassword",
+                                                user["name"],
+                                                "--attributes=%s" % attributes)
+            self.assertCmdSuccess(result, "Ensure getpassword runs")
+            self.assertEqual(err,"","getpassword without url")
+            self.assertMatch(out, "Got password OK", "getpassword without url")
+            self.assertMatch(out, "sAMAccountName: %s" % (user["name"]),
+                    "getpassword: 'sAMAccountName': %s out[%s]" % (user["name"], out))
+            self.assertMatch(out, "unicodePwd:: %s" % unicodePwd,
+                    "getpassword unicodePwd: out[%s]" % out)
+            self.assertMatch(out, "supplementalCredentials:: ",
+                    "getpassword supplementalCredentials: out[%s]" % out)
+
         for user in self.users:
             newpasswd = self.randomPass()
             (result, out, err) = self.runsubcmd("user", "setpassword",