mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-06-08 06:05:57 -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>
94 lines
3.0 KiB
Python
94 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
# Python rewrite of testsuite/acls.test.
|
|
#
|
|
# Test that rsync -A preserves POSIX ACLs across a transfer. Skips on
|
|
# binaries built without ACL support, on filesystems with ACLs disabled,
|
|
# and on hosts that lack both setfacl(1) and a chmod that understands "+a".
|
|
|
|
import os
|
|
import platform
|
|
import subprocess
|
|
|
|
from rsyncfns import FROMDIR, SCRATCHDIR, TODIR, makepath, run_rsync, test_fail, test_skipped
|
|
|
|
|
|
vv = run_rsync('-VV', check=True, capture_output=True)
|
|
if '"ACLs": true' not in vv.stdout:
|
|
test_skipped("Rsync is configured without ACL support")
|
|
|
|
makepath(FROMDIR / 'foo')
|
|
(FROMDIR / 'file1').write_text("something\n")
|
|
(FROMDIR / 'file2').write_text("else\n")
|
|
|
|
files = ['foo', 'file1', 'file2']
|
|
|
|
# Decide which ACL command surface to use. Mirrors the shell test's
|
|
# branching on $setfacl_nodef (set by runtests.py).
|
|
setfacl_nodef = os.environ.get('setfacl_nodef', 'true')
|
|
|
|
|
|
def _chmod_plus_a_supported() -> bool:
|
|
"""macOS-style: chmod +a 'user allow ...'."""
|
|
out = subprocess.run(['chmod', '--help'], capture_output=True, text=True)
|
|
return '+a' in (out.stdout + out.stderr)
|
|
|
|
|
|
use_chmod_plus_a = setfacl_nodef == 'true' and _chmod_plus_a_supported()
|
|
|
|
if setfacl_nodef == 'true' and not use_chmod_plus_a:
|
|
test_skipped("I don't know how to use setfacl or chmod for ACLs")
|
|
|
|
|
|
def _setfacl(*args) -> int:
|
|
return subprocess.run(['setfacl', *args]).returncode
|
|
|
|
|
|
def _chmod_acl(*args) -> int:
|
|
return subprocess.run(['chmod', *args]).returncode
|
|
|
|
|
|
if use_chmod_plus_a:
|
|
if _chmod_acl('+a', 'root allow read,write,execute',
|
|
str(FROMDIR / 'foo')) != 0:
|
|
test_skipped("Your filesystem has ACLs disabled")
|
|
_chmod_acl('+a', 'root allow read,execute', str(FROMDIR / 'file1'))
|
|
_chmod_acl('+a', 'admin allow read', str(FROMDIR / 'file1'))
|
|
_chmod_acl('+a', 'daemon allow read,write', str(FROMDIR / 'file1'))
|
|
_chmod_acl('+a', 'root allow read,execute', str(FROMDIR / 'file2'))
|
|
|
|
def see_acls(paths):
|
|
return subprocess.check_output(['ls', '-le', *paths], text=True)
|
|
else:
|
|
if _setfacl('-m', 'u:0:7', str(FROMDIR / 'foo')) != 0:
|
|
test_skipped("Your filesystem has ACLs disabled")
|
|
_setfacl('-m', 'g:1:5', str(FROMDIR / 'foo'))
|
|
_setfacl('-m', 'g:2:1', str(FROMDIR / 'foo'))
|
|
_setfacl('-m', 'g:0:7', str(FROMDIR / 'foo'))
|
|
_setfacl('-m', 'u:2:1', str(FROMDIR / 'foo'))
|
|
_setfacl('-m', 'u:1:5', str(FROMDIR / 'foo'))
|
|
|
|
_setfacl('-m', 'u:0:5', str(FROMDIR / 'file1'))
|
|
_setfacl('-m', 'g:0:4', str(FROMDIR / 'file1'))
|
|
_setfacl('-m', 'u:1:6', str(FROMDIR / 'file1'))
|
|
|
|
_setfacl('-m', 'u:0:5', str(FROMDIR / 'file2'))
|
|
|
|
def see_acls(paths):
|
|
return subprocess.check_output(['getfacl', *paths], text=True)
|
|
|
|
|
|
os.chdir(FROMDIR)
|
|
run_rsync('-avvA', *files, f'{TODIR}/')
|
|
|
|
before = see_acls(files)
|
|
(SCRATCHDIR / 'acls.txt').write_text(before)
|
|
|
|
os.chdir(TODIR)
|
|
after = see_acls(files)
|
|
if before != after:
|
|
print("--- expected (from) ---")
|
|
print(before)
|
|
print("--- got (to) ---")
|
|
print(after)
|
|
test_fail("ACL listing differs between source and destination")
|