Debian Codegraph @

testsuite/symlink-exclude-leaf_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Daemon module-exclude bypass on an excluded LEAF (file) reached through an
3 # in-tree directory symlink. (Reported by codex.)
4 #
5 # Unlike the subtree cases, the exclude here names a single leaf: /pub/blocked.
6 # pub/ itself is NOT excluded, so resolving the parent through the in-module
7 # symlink blink2 -> pub/ does not refuse it; only the final basename is
8 # excluded. A peer sends blink2/blocked under --keep-dirlinks: the held-dirfd
9 # resolves the parent to pub and the leaf create/rename writes pub/blocked --
10 # the excluded file -- because the leaf basename is never physically
11 # exclude-checked. Runs unprivileged.
12 import os
13 import subprocess
14
15 from rsyncfns import (
16 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf,
17 )
18
19 DAEMON_PORT = 12987
20
21 base = SCRATCHDIR / 'symlink-exclude-leaf'
22 rmtree(base)
23 base.mkdir()
24
25 mod = base / 'mod'
26 mod.mkdir()
27 pub = mod / 'pub' # NOT excluded
28 pub.mkdir()
29 os.symlink('pub/', mod / 'blink2') # in-tree dir symlink -> pub/
30
31 src = base / 'src'
32 (src / 'blink2').mkdir(parents=True)
33 (src / 'blink2' / 'blocked').write_text("SHOULD-NOT-LAND\n")
34
35 conf = write_daemon_conf(
36 [('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/pub/blocked'})])
37 url = start_test_daemon(conf, DAEMON_PORT)
38
39 subprocess.run(
40 rsync_argv('-a', '--keep-dirlinks', f'{src}/', f'{url}mod/'),
41 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
42
43 blocked = pub / 'blocked'
44 if not blocked.exists():
45 test_fail(
46 "the daemon refused an excluded leaf that stock rsync (3.2.7) writes: "
47 f"{blocked} was not created through the in-tree symlink. The exclude is "
48 "name-based (it sees 'blink2/blocked', not the physical 'pub/blocked'); it "
49 "must not block this.")
50 print("daemon exclude is name-based: an excluded leaf reached through an in-tree "
51 "dir symlink is written (3.2.7-equivalent)")