From 8df9fdc551a2bf2feca24f2d80fc20825441cecc Mon Sep 17 00:00:00 2001 From: Douglas Bagnall Date: Thu, 1 Sep 2022 10:29:59 +1200 Subject: [PATCH] pytest: samba-tool ntacl should report errors better 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 Reviewed-by: Andrew Bartlett --- python/samba/tests/samba_tool/ntacl.py | 27 ++++++++++++++++++++++++++ selftest/knownfail.d/samba-tool-ntacl | 1 + 2 files changed, 28 insertions(+) create mode 100644 selftest/knownfail.d/samba-tool-ntacl diff --git a/python/samba/tests/samba_tool/ntacl.py b/python/samba/tests/samba_tool/ntacl.py index c9a14ec0ec8..d0e315456e8 100644 --- a/python/samba/tests/samba_tool/ntacl.py +++ b/python/samba/tests/samba_tool/ntacl.py @@ -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 index 00000000000..cffdcd1788a --- /dev/null +++ b/selftest/knownfail.d/samba-tool-ntacl @@ -0,0 +1 @@ +^samba.tests.samba_tool.ntacl.+test_with_missing_files