mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-08-01 16:27:00 -04:00
Replace the entire shell-based testsuite with Python. runtests.py
already drove the suite (it had replaced runtests.sh earlier); this
converts all 60 test scripts from *.test shell to *_test.py and adds
testsuite/rsyncfns.py as the shared helper module -- the Python
counterpart of the now-removed rsync.fns.
runtests.py:
* Discovers and runs both *.test and *_test.py; dispatches the
Python tests via the same python3 that runs the harness.
* Extends PYTHONPATH so tests can `import rsyncfns`.
testsuite/rsyncfns.py provides everything the ports need:
* environment wiring (scratchdir / srcdir / TOOLDIR / RSYNC /
TLS_ARGS, and HOME pointed at the per-test scratch dir);
* result reporting -- test_fail / test_skipped / test_xfail mapping
to the 0 / 1 / 77 / 78 exit-code convention;
* the transfer-and-verify helpers checkit, checkdiff, verify_dirs,
rsync_ls_lR, check_perms and the v_filt output filter;
* fixture builders hands_setup, build_symlinks, build_rsyncd_conf,
make_data_file, cp_p / cp_touch, makepath / rmtree.
All 60 tests are converted, including the four split-variant tests
that share one source via a Makefile-built symlink (chown/chown-fake,
devices/devices-fake, xattrs/xattrs-hlink, exclude/exclude-lsh);
Makefile.in's CHECK_SYMLINKS now points at the *_test.py names.
The dead rsync.fns shell library is removed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
# Python rewrite of testsuite/dir-sgid.test.
|
|
#
|
|
# Check that rsync obeys the setgid bit on the destination's parent
|
|
# directory when creating a new directory to hold the transferred files,
|
|
# even though that parent directory is outside the transfer itself.
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
from rsyncfns import (
|
|
SCRATCHDIR, check_perms, run_rsync, test_skipped,
|
|
)
|
|
|
|
|
|
old_umask = os.umask(0o077)
|
|
|
|
|
|
def testit(dirname, dirperms, file_expected, prog_expected, dir_expected):
|
|
"""Mirror shell `testit dirname dirperms file_expected prog_expected dir_expected`."""
|
|
todir = SCRATCHDIR / dirname
|
|
todir.mkdir()
|
|
# dirperms is either an octal int or the symbolic shell form we translate.
|
|
if isinstance(dirperms, int):
|
|
os.chmod(todir, dirperms)
|
|
else:
|
|
subprocess.run(['chmod', dirperms, str(todir)], check=True)
|
|
|
|
run_rsync('-rvv', str(SCRATCHDIR / 'dir'),
|
|
str(SCRATCHDIR / 'file'),
|
|
str(SCRATCHDIR / 'program'),
|
|
f'{todir}/to/')
|
|
|
|
check_perms(todir / 'to', dir_expected)
|
|
check_perms(todir / 'to' / 'dir', dir_expected)
|
|
check_perms(todir / 'to' / 'file', file_expected)
|
|
check_perms(todir / 'to' / 'program', prog_expected)
|
|
|
|
|
|
# Cygwin's default dir ACL ruins this test; mimic the shell's getfacl skip.
|
|
src_dir = SCRATCHDIR / 'dir'
|
|
src_dir.mkdir()
|
|
try:
|
|
out = subprocess.run(['getfacl', str(src_dir)],
|
|
capture_output=True, text=True)
|
|
if 'default:user::' in out.stdout:
|
|
test_skipped("The default ACL mode interferes with this test")
|
|
except FileNotFoundError:
|
|
pass # No getfacl -- proceed.
|
|
|
|
(SCRATCHDIR / 'file').write_text("File!\n")
|
|
(SCRATCHDIR / 'program').write_text("#!/bin/sh\n")
|
|
|
|
try:
|
|
subprocess.run(['chmod', 'u=rwx,g=rw,g+s,o=r', str(src_dir)], check=True)
|
|
except subprocess.CalledProcessError:
|
|
test_skipped("Can't chmod")
|
|
os.chmod(SCRATCHDIR / 'file', 0o664)
|
|
os.chmod(SCRATCHDIR / 'program', 0o775)
|
|
|
|
if not (os.stat(src_dir).st_mode & 0o2000):
|
|
test_skipped("The directory setgid bit vanished!")
|
|
|
|
(src_dir / 'blah').mkdir()
|
|
if not (os.stat(src_dir / 'blah').st_mode & 0o2000):
|
|
test_skipped("Your filesystem doesn't use directory setgid; maybe it's BSD.")
|
|
|
|
testit('setgid-off', 0o700, 'rw-------', 'rwx------', 'rwx------')
|
|
testit('setgid-on', 'u=rwx,g=rw,g+s,o-rwx', 'rw-------', 'rwx------', 'rwx--S---')
|
|
|
|
os.umask(old_umask)
|