diff --git a/lib/libzfsacl/zfsacltests/test_nfsv4acl.py b/lib/libzfsacl/zfsacltests/test_nfsv4acl.py index ff1baac92c6d..0f599bbc22b5 100644 --- a/lib/libzfsacl/zfsacltests/test_nfsv4acl.py +++ b/lib/libzfsacl/zfsacltests/test_nfsv4acl.py @@ -3,6 +3,21 @@ import pwd import shutil import libzfsacl +from subprocess import run, PIPE + +def run_as_user(cmd, user): + command = ["/usr/bin/su", "-", user, "-c", cmd] + print(" ".join(command)) + proc = run(command, stdout=PIPE, stderr=PIPE, + universal_newlines=True, timeout=30) + output = proc.stdout + error = proc.stderr + if proc.returncode != 0: + return {"result": False, "output": output, "error": error, + "returncode": proc.returncode} + else: + return {"result": False, "output": output, "error": error, + "returncode": proc.returncode} class TestNFSAcl(unittest.TestCase): @@ -384,8 +399,31 @@ def test_flagset_no_propagate_dir(self): self.assertEqual(tdentry0.who, (libzfsacl.WHOTYPE_USER, self.ZFS_ACL_STAFF1_UID), "Inherited ACE who is not correct") self.assertEqual(tdentry0.flagset, libzfsacl.FLAG_INHERITED, "Flagset on inherited ACE are not correct") self.assertEqual(tdentry0.permset, libzfsacl.PERM_READ_DATA | libzfsacl.PERM_WRITE_DATA, "Permse of inherited ACE at index 0 are not correct") - os.rmdir(tddir) - + shutil.rmtree(self.TDIR) + def test_run_as_user(self): + os.makedirs(self.TDIR) + ls_path = shutil.which("ls") + cmd = f"{ls_path} -lh {self.MOUNTPT}" + res = run_as_user(cmd, self.ZFS_ACL_STAFF2) + os.rmdir(self.TDIR) + print(res["returncode"]) + print(res["output"]) + print(res["error"]) + + zfs_path = shutil.which("zfs") + cmd = f"{zfs_path} --version" + res = run_as_user(cmd, self.ZFS_ACL_STAFF1) + print(res["returncode"]) + print(res["output"]) + print(res["error"]) + + zpool_path = shutil.which("zfs") + cmd = f"{zpool_path} --version" + cmd = f"/usr/sbin/zpool --version" + res = run_as_user(cmd, self.ZFS_ACL_STAFF2) + print(res["returncode"]) + print(res["output"]) + print(res["error"]) diff --git a/tests/zfs-tests/tests/functional/acl/nfsv4/cleanup.ksh b/tests/zfs-tests/tests/functional/acl/nfsv4/cleanup.ksh index 699301a160e9..acde12e7bad6 100755 --- a/tests/zfs-tests/tests/functional/acl/nfsv4/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/acl/nfsv4/cleanup.ksh @@ -31,3 +31,7 @@ cleanup_user_group default_cleanup + +if is_freebsd; then + mv /usr/bin/fortune_bak /usr/bin/fortune +fi diff --git a/tests/zfs-tests/tests/functional/acl/nfsv4/setup.ksh b/tests/zfs-tests/tests/functional/acl/nfsv4/setup.ksh index 6c65f8ff607d..3a4261987c71 100755 --- a/tests/zfs-tests/tests/functional/acl/nfsv4/setup.ksh +++ b/tests/zfs-tests/tests/functional/acl/nfsv4/setup.ksh @@ -35,6 +35,11 @@ log_must add_group $ZFS_ACL_STAFF_GROUP log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF1 log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF2 +if is_freebsd; then + mv /usr/bin/fortune /usr/bin/fortune_bak + cp /usr/bin/true /usr/bin/fortune +fi + DISK=${DISKS%% *} default_setup_noexit $DISK log_must chmod 777 $TESTDIR