Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
Signed-off-by: Umer Saleem <[email protected]>
  • Loading branch information
usaleem-ix committed Jul 27, 2023
1 parent b16eae9 commit 7779eab
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
57 changes: 55 additions & 2 deletions lib/libzfsacl/zfsacltests/test_nfsv4acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,43 @@
import os
import pwd
import shutil
import socket
import libzfsacl
from subprocess import run, PIPE


def ssh_run(cmd, user, passwd):
host = socket.gethostname()
command = [] if passwd is None else ["/usr/bin/sshpass", "-p", passwd]
command += ["ssh", "-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "VerifyHostKeyDNS=no", f"{user}@{host}", cmd]
print(" ".join(command))
proc = run(command, stdout=PIPE, stderr=PIPE,
universal_newlines=True, timeout=120)
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}

def run_as_user(cmd, user):
host = socket.gethostname()
command = ["/usr/bin/su", "-", user, "-c", cmd]
print(" ".join(command))
proc = run(command, stdout=PIPE, stderr=PIPE,
universal_newlines=True, timeout=120)
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):
Expand Down Expand Up @@ -384,8 +420,25 @@ 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)
cmd = f"/usr/bin/ls -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"])
cmd = f"/usr/sbin/zfs --version"
res = run_as_user(cmd, self.ZFS_ACL_STAFF1)
print(res["returncode"])
print(res["output"])
print(res["error"])
cmd = f"/usr/sbin/zpool --version"
res = run_as_user(cmd, self.ZFS_ACL_STAFF2)
print(res["returncode"])
print(res["output"])
print(res["error"])


2 changes: 2 additions & 0 deletions tests/zfs-tests/tests/functional/acl/nfsv4/setup.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ cleanup_user_group
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
log_must /usr/bin/passwd -d $ZFS_ACL_STAFF1
log_must /usr/bin/passwd -d $ZFS_ACL_STAFF2

DISK=${DISKS%% *}
default_setup_noexit $DISK
Expand Down

0 comments on commit 7779eab

Please sign in to comment.