Skip to content

Commit

Permalink
misc: Add test for supplementary groups
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Prabhu <[email protected]>
  • Loading branch information
spuiuk committed Feb 1, 2024
1 parent 8090f4e commit 8f845a8
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions testcases/misc/test_supplemantary_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This test is to check writes as part of a supplementary group.
# The following is required to run this test:
# 1. user1 exists
# 2. user1 is part of supplementary group sg

import testhelper
import pytest
import shutil
import pwd
import grp
import os
from pathlib import Path

test_info_file = os.getenv("TEST_INFO_FILE")
test_info = testhelper.read_yaml(test_info_file)
test_string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
test_subdir = Path("supplementary_group")
test_sgroup = "sg"


def check_reqs():
try:
pwd.getpwnam("test1")
grp.getgrnam(test_sgroup)
except KeyError:
return False
return True


def setup_local_testdir(root: Path, group: str) -> Path:
testdir = root / test_subdir
testdir.mkdir(exist_ok=True)
shutil.chown(testdir, group=group)
testdir.chmod(0o770)
return testdir


def write_file_remote(
mount_point: Path,
ipaddr: str,
share_name: str,
) -> None:
mount_params = testhelper.get_mount_parameters(test_info, share_name)
mount_params["host"] = ipaddr
try:
test_file = testhelper.get_tmp_file(mount_point)
test_file_remote = test_subdir / Path("test-cp")
with open(test_file, "w") as f:
f.write(test_string)
put_cmds = "put %s %s" % (test_file, test_file_remote)
(ret, output) = testhelper.smbclient(mount_params, put_cmds)
assert ret == 0, "Failed to copy file to server: " + output
finally:
if test_file.exists():
test_file.unlink()


def gen_supplementary_group_param(test_info: dict) -> list:
if not check_reqs():
return []
if not test_info:
return []
arr = []
for ipaddr in test_info["public_interfaces"]:
for share in testhelper.get_shares_with_directmnt(test_info):
arr.append((ipaddr, share["name"]))
return arr


@pytest.mark.parametrize(
"ipaddr,share_name", gen_supplementary_group_param(test_info)
)
def test_supplementary_group(
ipaddr: str, share_name: str
) -> None:
share = testhelper.get_share(test_info, share_name)
fs_path = Path(share["directmnt"])
testdir = setup_local_testdir(fs_path, test_sgroup)
try:
tmp_root = testhelper.get_tmp_root()
mount_point = testhelper.get_tmp_mount_point(tmp_root)
write_file_remote(mount_point, ipaddr, share_name)
finally:
shutil.rmtree(testdir)

0 comments on commit 8f845a8

Please sign in to comment.