]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pytest: samba-tool ntacl should report errors better
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 31 Aug 2022 22:29:59 +0000 (10:29 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Wed, 7 Sep 2022 05:01:37 +0000 (05:01 +0000)
We want `samba-tool ntacl sysvolreset` and `samba-tool ntacl
sysvolcheck` to fail when the Policies folder is not in place, but not
to produce an inscrutable stacktrace.

https://bugzilla.samba.org/show_bug.cgi?id=14937

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/samba_tool/ntacl.py
selftest/knownfail.d/samba-tool-ntacl [new file with mode: 0644]

index c9a14ec0ec8c79c21fab4e2a64b2bb43916bd9ca..d0e315456e8dab8deefe064915ff98cc45243621 100644 (file)
@@ -22,6 +22,7 @@ import os
 import time
 import ldb
 from samba.tests.samba_tool.base import SambaToolCmdTest
+from samba.tests import env_loadparm
 import random
 
 
@@ -69,6 +70,32 @@ class NtACLCmdSysvolTestCase(SambaToolCmdTest):
         self.assertEqual(err, "", "Shouldn't be any error messages")
         self.assertEqual(out, "", "Shouldn't be any output messages")
 
+    def test_with_missing_files(self):
+        lp = env_loadparm()
+        sysvol = lp.get('path', 'sysvol')
+        realm = lp.get('realm').lower()
+
+        src = os.path.join(sysvol, realm, 'Policies')
+        dest = os.path.join(sysvol, realm, 'Policies-NOT-IN-THE-EXPECTED-PLACE')
+        try:
+            os.rename(src, dest)
+
+            for args in (["sysvolreset", "--use-s3fs"],
+                         ["sysvolreset", "--use-ntvfs"],
+                         ["sysvolreset"],
+                         ["sysvolcheck"]
+            ):
+
+                (result, out, err) = self.runsubcmd("ntacl", *args)
+                self.assertCmdFail(result, f"succeeded with {args} with missing dir")
+                self.assertNotIn("uncaught exception", err,
+                                 "Shouldn't be uncaught exception")
+                self.assertNotRegex(err, '^\s*File [^,]+, line \d+, in',
+                                    "Shouldn't be lines of traceback")
+                self.assertEqual(out, "", "Shouldn't be any output messages")
+        finally:
+            os.rename(dest, src)
+
 
 class NtACLCmdGetSetTestCase(SambaToolCmdTest):
     """Tests for samba-tool ntacl get/set subcommands"""
diff --git a/selftest/knownfail.d/samba-tool-ntacl b/selftest/knownfail.d/samba-tool-ntacl
new file mode 100644 (file)
index 0000000..cffdcd1
--- /dev/null
@@ -0,0 +1 @@
+^samba.tests.samba_tool.ntacl.+test_with_missing_files