| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
fleet_nonroot = True |
| 12 |
|
| 13 |
import os |
| 14 |
import subprocess |
| 15 |
|
| 16 |
from rsyncfns import ( |
| 17 |
CHKFILE, FROMDIR, OUTFILE, RSYNC, RSYNC_PEER, SCRATCHDIR, SRCDIR, TODIR, |
| 18 |
build_rsyncd_conf, get_rootuid, get_testuid, makepath, |
| 19 |
rsync_argv, run_rsync, start_test_daemon, test_fail, rsh_cmd, |
| 20 |
) |
| 21 |
|
| 22 |
|
| 23 |
DAEMON_PORT = 12877 |
| 24 |
|
| 25 |
|
| 26 |
SSH = rsh_cmd(None, '--no-cd') |
| 27 |
|
| 28 |
|
| 29 |
def listed_paths(text: str) -> set: |
| 30 |
"""The set of path names in an `rsync -r` listing. Each listing line is |
| 31 |
"<mode> <size> <date> <time> <path>"; pull out the trailing path. Comparing |
| 32 |
the whole set (not just checking individual paths are present) catches a |
| 33 |
listing that leaks EXTRA paths, not only one that omits expected ones.""" |
| 34 |
paths = set() |
| 35 |
for line in text.splitlines(): |
| 36 |
parts = line.split() |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
if len(parts) >= 5 and len(parts[0]) == 10 and parts[0][0] in '-dlbcps': |
| 41 |
paths.add(parts[-1]) |
| 42 |
return paths |
| 43 |
|
| 44 |
|
| 45 |
conf = build_rsyncd_conf() |
| 46 |
|
| 47 |
makepath(FROMDIR / 'foo', FROMDIR / 'bar' / 'baz', TODIR) |
| 48 |
(FROMDIR / 'foo' / 'one').write_text("one\n") |
| 49 |
(FROMDIR / 'bar' / 'two').write_text("two\n") |
| 50 |
(FROMDIR / 'bar' / 'baz' / 'three').write_text("three\n") |
| 51 |
|
| 52 |
os.chdir(SCRATCHDIR) |
| 53 |
if not (SCRATCHDIR / 'rsyncd.conf').exists(): |
| 54 |
os.symlink('test-rsyncd.conf', SCRATCHDIR / 'rsyncd.conf') |
| 55 |
|
| 56 |
confopt = [] |
| 57 |
if get_testuid() == get_rootuid(): |
| 58 |
|
| 59 |
print(f"Forcing --config={conf}") |
| 60 |
confopt = [f'--config={conf}'] |
| 61 |
|
| 62 |
expected_modules = ( |
| 63 |
"test-from \tr/o\n" |
| 64 |
"test-to \tr/w\n" |
| 65 |
"test-scratch \t\n" |
| 66 |
) |
| 67 |
|
| 68 |
|
| 69 |
def run_and_check(args, label, capture_stderr=False): |
| 70 |
proc = subprocess.run( |
| 71 |
rsync_argv(*args), |
| 72 |
capture_output=True, text=True, |
| 73 |
) |
| 74 |
out = proc.stdout |
| 75 |
if capture_stderr: |
| 76 |
out += proc.stderr |
| 77 |
print(f"--- {label} output:") |
| 78 |
print(out) |
| 79 |
if proc.returncode != 0 and not capture_stderr: |
| 80 |
test_fail(f"{label}: rsync exited {proc.returncode}\n{proc.stderr}") |
| 81 |
return out |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
rsync_path = f"{RSYNC_PEER}{(' ' + ' '.join(confopt)) if confopt else ''}" |
| 86 |
out = run_and_check( |
| 87 |
['-ve', SSH, f'--rsync-path={rsync_path}', 'localhost::'], |
| 88 |
"module list via lsh.sh", |
| 89 |
) |
| 90 |
if expected_modules not in out: |
| 91 |
test_fail("module list via lsh.sh did not contain the expected modules") |
| 92 |
|
| 93 |
if 'test-hidden' in out: |
| 94 |
print(out) |
| 95 |
test_fail("module list via lsh.sh leaked the `list = no` test-hidden module") |
| 96 |
print('====') |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
daemon_url = start_test_daemon(conf, DAEMON_PORT).rstrip('/') |
| 101 |
|
| 102 |
out = run_and_check(['-v', f'{daemon_url}/'], "module list via daemon") |
| 103 |
if expected_modules not in out: |
| 104 |
test_fail("module list via daemon did not contain the expected modules") |
| 105 |
|
| 106 |
if 'test-hidden' in out: |
| 107 |
print(out) |
| 108 |
test_fail("module list via daemon leaked the `list = no` test-hidden module") |
| 109 |
print('====') |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
out = run_and_check(['-r', f'{daemon_url}/test-hidden'], "test-hidden listing") |
| 115 |
got = listed_paths(out) |
| 116 |
want = {'.', 'bar', 'bar/two', 'bar/baz', 'bar/baz/three', 'foo', 'foo/one'} |
| 117 |
if got != want: |
| 118 |
print(out) |
| 119 |
test_fail(f"test-hidden listing paths {sorted(got)} != expected {sorted(want)}") |
| 120 |
|
| 121 |
|
| 122 |
out = run_and_check(['-r', f'{daemon_url}/test-from/f*'], "test-from glob") |
| 123 |
got = listed_paths(out) |
| 124 |
want = {'foo', 'foo/one'} |
| 125 |
if got != want: |
| 126 |
print(out) |
| 127 |
test_fail(f"test-from glob paths {sorted(got)} != expected {sorted(want)}") |
| 128 |
|
| 129 |
|
| 130 |
vv = run_rsync('-VV', check=True, capture_output=True) |
| 131 |
if '"atimes": true' in vv.stdout: |
| 132 |
out = run_and_check(['-rU', f'{daemon_url}/test-from/f*'], "test-from glob with -U") |
| 133 |
got = listed_paths(out) |
| 134 |
if got != want: |
| 135 |
print(out) |
| 136 |
test_fail(f"-U glob paths {sorted(got)} != expected {sorted(want)}") |