| 1 |
|
| 2 |
"""Daemon coverage: module path, read only, write only, list. |
| 3 |
|
| 4 |
Drives a loopback daemon (secure stdio-pipe transport by default) and checks |
| 5 |
the access-control parameters, transferring a >=3-deep tree through each module |
| 6 |
and pulling a deep sub-path to exercise in-module path resolution. |
| 7 |
""" |
| 8 |
|
| 9 |
import subprocess |
| 10 |
|
| 11 |
from rsyncfns import ( |
| 12 |
FROMDIR, SCRATCHDIR, TODIR, |
| 13 |
assert_same, make_tree, makepath, rmtree, rsync_argv, run_rsync, |
| 14 |
start_test_daemon, test_fail, verify_dirs, walk_files, write_daemon_conf, |
| 15 |
) |
| 16 |
|
| 17 |
DAEMON_PORT = 12886 |
| 18 |
|
| 19 |
src = FROMDIR |
| 20 |
rwdir = SCRATCHDIR / 'rwdest' |
| 21 |
wodir = SCRATCHDIR / 'wodest' |
| 22 |
pulld = SCRATCHDIR / 'pulled' |
| 23 |
for d in (rwdir, wodir, pulld, TODIR): |
| 24 |
rmtree(d) |
| 25 |
makepath(rwdir, wodir) |
| 26 |
rmtree(src) |
| 27 |
make_tree(src, depth=3) |
| 28 |
rels = [p.relative_to(src) for p in walk_files(src)] |
| 29 |
|
| 30 |
conf = write_daemon_conf([ |
| 31 |
('ro', {'path': src, 'read only': 'yes', 'comment': 'r/o'}), |
| 32 |
('rw', {'path': rwdir, 'read only': 'no', 'comment': 'r/w'}), |
| 33 |
('wo', {'path': wodir, 'read only': 'no', 'write only': 'yes'}), |
| 34 |
('hidden', {'path': src, 'list': 'no'}), |
| 35 |
]) |
| 36 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 37 |
|
| 38 |
|
| 39 |
def fails(args, what): |
| 40 |
proc = subprocess.run(rsync_argv(*args), |
| 41 |
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, |
| 42 |
text=True) |
| 43 |
if proc.returncode == 0: |
| 44 |
test_fail(f"{what} unexpectedly succeeded") |
| 45 |
return proc.stderr |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
run_rsync('-a', f'{url}ro/', f'{pulld}/', check=False) |
| 50 |
for rel in rels: |
| 51 |
assert_same(pulld / rel, src / rel, label=f'pull ro {rel}') |
| 52 |
|
| 53 |
rmtree(pulld) |
| 54 |
makepath(pulld) |
| 55 |
run_rsync('-a', f'{url}ro/d1/d2/', f'{pulld}/', check=False) |
| 56 |
assert_same(pulld / 'f2', src / 'd1' / 'd2' / 'f2', label='deep sub-path pull') |
| 57 |
fails(['-a', f'{src}/', f'{url}ro/'], "push to a read-only module") |
| 58 |
|
| 59 |
|
| 60 |
run_rsync('-a', f'{src}/', f'{url}rw/', check=False) |
| 61 |
verify_dirs(src, rwdir, label="push to rw module") |
| 62 |
|
| 63 |
|
| 64 |
run_rsync('-a', f'{src}/', f'{url}wo/', check=False) |
| 65 |
verify_dirs(src, wodir, label="push to wo module") |
| 66 |
fails(['-a', f'{url}wo/', f'{pulld}/'], "pull from a write-only module") |
| 67 |
|
| 68 |
|
| 69 |
proc = subprocess.run(rsync_argv(url), capture_output=True, text=True) |
| 70 |
listing = proc.stdout |
| 71 |
for m in ('ro', 'rw', 'wo'): |
| 72 |
if m not in listing: |
| 73 |
test_fail(f"module {m} missing from the daemon listing:\n{listing}") |
| 74 |
if 'hidden' in listing: |
| 75 |
test_fail(f"list=no module leaked into the listing:\n{listing}") |
| 76 |
|
| 77 |
rmtree(pulld) |
| 78 |
makepath(pulld) |
| 79 |
run_rsync('-a', f'{url}hidden/f0', f'{pulld}/', check=False) |
| 80 |
assert_same(pulld / 'f0', src / 'f0', label='hidden module usable by name') |
| 81 |
|
| 82 |
print("daemon-access: read only / write only / list / deep paths verified") |