Debian Codegraph @

testsuite/rrsync-archive-mode_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # A subdir-restricted rrsync must accept a normal `rsync -a` transfer.
3 #
4 # A/B-discovered regression (abdiff: 3.5 rrsync vs 3.4.4 rrsync). 3.5 added 'D'
5 # to rrsync's short_disabled_subdir ('KLk' -> 'DKLk') to deny device/special
6 # CREATION in a restricted upload dir. But `-a` is `-rlptgoD`: the client always
7 # sends a bundled short-option string containing 'D' (e.g. -logDtpre.iLsfxCIvu),
8 # so a subdir-restricted rrsync now REJECTS plain `rsync -a` outright:
9 # <rrsync> error: option -D has been disabled on this server. (exit 1)
10 # -- in BOTH directions (push and pull). 3.4.4's rrsync accepted it. This
11 # breaks the canonical "rsync -a ... rrsync-host:dir/" backup for every restricted
12 # (non-"/") rrsync, on every platform. The deny should strip device/special
13 # semantics (e.g. force --no-D), not reject the whole transfer.
14 #
15 # Stub test (RSYNC -> true): we only check rrsync's option ACCEPTANCE, not a real
16 # transfer. Runs anywhere python3 + true exist; no root.
17
18 import os
19 import shutil
20 import subprocess
21
22 from rsyncfns import SCRATCHDIR, patched_rrsync, test_fail, test_skipped
23
24 true = shutil.which('true') or '/usr/bin/true'
25 if not os.path.exists(true):
26 test_skipped("no true(1) to stub rsync")
27
28 base = SCRATCHDIR / 'rrsync_a'
29 restricted = base / 'restricted'
30 restricted.mkdir(parents=True, exist_ok=True)
31 # The pull (--sender) command reads `inbox/`; rrsync inode-pins an existing
32 # --sender source before exec (a non-existent one is treated as a race and
33 # refused), so the source must exist for this option-acceptance check.
34 (restricted / 'inbox').mkdir(exist_ok=True)
35 rrsync = patched_rrsync(base, rsync_path=true)
36
37 # What a stock `rsync -a` sends as the server command (bundled short opts incl D):
38 for direction, cmd in (("push", 'rsync --server -logDtpre.iLsfxCIvu . inbox/'),
39 ("pull", 'rsync --server --sender -logDtpre.iLsfxCIvu . inbox/')):
40 env = {**os.environ, 'SSH_ORIGINAL_COMMAND': cmd}
41 r = subprocess.run([str(rrsync), str(restricted)], env=env,
42 capture_output=True, text=True)
43 if r.returncode != 0:
44 test_fail(f"subdir-restricted rrsync rejected `rsync -a` ({direction}, "
45 f"exit {r.returncode}): {r.stderr.strip()}")
46
47 print("rrsync-archive-mode: subdir-restricted rrsync accepts `rsync -a` (push & pull)")