python:samba/tests: add simple 'samba-tool user syncpasswords' 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: Alexander Bokovoy <ab@samba.org>
python/samba/tests/samba_tool/user.py

index 0ecd51753d843156c31e5dbb075484f9965b70c2..a4bba2f6b7f2c0eaea3b2fc567cbc4450bc85ac2 100644 (file)
@@ -188,13 +188,41 @@ class UserCmdTestCase(SambaToolCmdTest):
             self.assertEquals(err,"","setpassword with url")
             self.assertMatch(out, "Changed password OK", "setpassword with url")
 
+        attributes = "sAMAccountName,unicodePwd,supplementalCredentials"
+        (result, out, err) = self.runsubcmd("user", "syncpasswords",
+                                            "--cache-ldb-initialize",
+                                            "--attributes=%s" % attributes)
+        self.assertCmdSuccess(result, "Ensure syncpasswords --cache-ldb-initialize runs")
+        self.assertEqual(err,"","getpassword without url")
+        cache_attrs = {
+            "objectClass": { "value": "userSyncPasswords" },
+            "samdbUrl": { },
+            "dirsyncFilter": { },
+            "dirsyncAttribute": { },
+            "dirsyncControl": { "value": "dirsync:1:0:0"},
+            "passwordAttribute": { },
+            "currentTime": { },
+        }
+        for a in cache_attrs.keys():
+            v = cache_attrs[a].get("value", "")
+            self.assertMatch(out, "%s: %s" % (a, v),
+                "syncpasswords --cache-ldb-initialize: %s: %s out[%s]" % (a, v, out))
+
+        (result, out, err) = self.runsubcmd("user", "syncpasswords", "--no-wait")
+        self.assertCmdSuccess(result, "Ensure syncpasswords --no-wait runs")
+        self.assertEqual(err,"","syncpasswords --no-wait")
+        self.assertMatch(out, "dirsync_loop(): results 0",
+            "syncpasswords --no-wait: 'dirsync_loop(): results 0': out[%s]" % (out))
+        for user in self.users:
+            self.assertMatch(out, "sAMAccountName: %s" % (user["name"]),
+                "syncpasswords --no-wait: 'sAMAccountName': %s out[%s]" % (user["name"], out))
+
         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",
@@ -204,6 +232,22 @@ class UserCmdTestCase(SambaToolCmdTest):
             self.assertEquals(err,"","setpassword without url")
             self.assertMatch(out, "Changed password OK", "setpassword without url")
 
+            (result, out, err) = self.runsubcmd("user", "syncpasswords", "--no-wait")
+            self.assertCmdSuccess(result, "Ensure syncpasswords --no-wait runs")
+            self.assertEqual(err,"","syncpasswords --no-wait")
+            self.assertMatch(out, "dirsync_loop(): results 0",
+                "syncpasswords --no-wait: 'dirsync_loop(): results 0': out[%s]" % (out))
+            self.assertMatch(out, "sAMAccountName: %s" % (user["name"]),
+                "syncpasswords --no-wait: 'sAMAccountName': %s out[%s]" % (user["name"], out))
+            self.assertMatch(out, "# unicodePwd::: REDACTED SECRET ATTRIBUTE",
+                    "getpassword '# unicodePwd::: REDACTED SECRET ATTRIBUTE': out[%s]" % out)
+            self.assertMatch(out, "unicodePwd:: %s" % unicodePwd,
+                    "getpassword unicodePwd: out[%s]" % out)
+            self.assertMatch(out, "# supplementalCredentials::: REDACTED SECRET ATTRIBUTE",
+                    "getpassword '# supplementalCredentials::: REDACTED SECRET ATTRIBUTE': out[%s]" % out)
+            self.assertMatch(out, "supplementalCredentials:: ",
+                    "getpassword supplementalCredentials: out[%s]" % out)
+
             (result, out, err) = self.runsubcmd("user", "getpassword",
                                                 user["name"],
                                                 "--attributes=%s" % attributes)