Debian Codegraph @

testsuite/symlink-exclude-deep_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Daemon module-exclude bypass via a DEEPER in-tree directory symlink (not the
3 # destination argument). (Probe for codex's "per-chdir physical tracking"
4 # concern.)
5 #
6 # The module excludes a nested subtree exclude = /pub/secret/. pub/ is NOT
7 # excluded. An in-module dir symlink dir2 -> pub/ sits inside the dest tree
8 # (a level below the dest root). A peer pushes a tree whose file list contains
9 # dir2/secret/x and runs with --keep-dirlinks, so the receiver follows dir2 into
10 # pub while descending, then writes secret/x into pub/secret/x -- the excluded
11 # subtree -- if the exclude is checked on the logical "dir2/secret" rather than
12 # the physical "pub/secret".
13 #
14 # This differs from symlink-exclude-component (one level, leaf parent) and
15 # symlink-exclude-chdir-alias (the symlink IS the dest arg): here the followed
16 # symlink is a deeper subdirectory reached as the transfer descends. RED here
17 # means the held-dirfd seed alone is NOT enough and per-chdir physical tracking
18 # is required. Runs unprivileged.
19 import os
20 import subprocess
21
22 from rsyncfns import (
23 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf,
24 )
25
26 DAEMON_PORT = 12983
27 SECRET = "PROTECTED-IN-EXCLUDED-SUBTREE\n"
28
29 base = SCRATCHDIR / 'symlink-exclude-deep'
30 rmtree(base)
31 base.mkdir()
32
33 mod = base / 'mod'
34 mod.mkdir()
35 pub = mod / 'pub' # NOT excluded
36 pub.mkdir()
37 secret = pub / 'secret' # excluded: /pub/secret/
38 secret.mkdir()
39 victim = secret / 'x'
40 victim.write_text(SECRET)
41
42 os.symlink('pub/', mod / 'dir2') # in-tree dir symlink -> pub/
43
44 src = base / 'src'
45 (src / 'dir2' / 'secret').mkdir(parents=True)
46 (src / 'dir2' / 'secret' / 'x').write_text("NEW\n")
47
48 conf = write_daemon_conf(
49 [('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/pub/secret/'})])
50 url = start_test_daemon(conf, DAEMON_PORT)
51
52 subprocess.run(
53 rsync_argv('-a', '--keep-dirlinks', f'{src}/', f'{url}mod/'),
54 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
55
56 after = victim.read_text() if victim.exists() else None
57 if after == SECRET:
58 test_fail(
59 "the daemon refused a deeper in-tree dir symlink that stock rsync (3.2.7) "
60 f"follows: a push to dir2/secret/x did not reach pub/secret/ ({victim} is "
61 f"still {after!r}). The exclude is name-based ('dir2/secret', not the "
62 "physical 'pub/secret'); it must not block this.")
63 print("daemon exclude is name-based: a deeper in-tree dir symlink reaches the "
64 "nested excluded subtree (3.2.7-equivalent)")