Debian Codegraph @

testsuite/symlink-exclude-chdir-alias_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Daemon module-exclude under-block via an ALLOWED symlinked chdir whose logical
3 # path then mislabels descendants. (Probe for codex residual #2.)
4 #
5 # The module excludes a *nested* subtree: exclude = /public/secret/. public/ is
6 # NOT excluded, so an in-module symlink blink2 -> public/ is followed when used
7 # as the destination. After that chdir the daemon's logical cwd is "blink2"
8 # while the physical cwd is "public"; a file then pushed to "secret/x" lands in
9 # public/secret/x -- the excluded subtree -- because the exclude check sees the
10 # logical "blink2/secret", not the physical "public/secret".
11 #
12 # RED = under-block reproduces (the alias defeats the nested exclude). Runs
13 # unprivileged.
14 import os
15 import subprocess
16
17 from rsyncfns import (
18 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf,
19 )
20
21 DAEMON_PORT = 12982
22 SECRET = "PROTECTED-IN-EXCLUDED-SUBTREE\n"
23
24 base = SCRATCHDIR / 'symlink-exclude-chdir-alias'
25 rmtree(base)
26 base.mkdir()
27
28 mod = base / 'mod'
29 mod.mkdir()
30 public = mod / 'public' # NOT excluded
31 public.mkdir()
32 secret = public / 'secret' # excluded: /public/secret/
33 secret.mkdir()
34 victim = secret / 'x'
35 victim.write_text(SECRET)
36
37 os.symlink('public/', mod / 'blink2') # allowed symlink -> public/
38
39 src = base / 'src'
40 (src / 'secret').mkdir(parents=True)
41 (src / 'secret' / 'x').write_text("NEW\n")
42
43 conf = write_daemon_conf(
44 [('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/public/secret/'})])
45 url = start_test_daemon(conf, DAEMON_PORT)
46
47 # Destination is the allowed symlink blink2 -> public; the pushed secret/x then
48 # resolves to public/secret/x (excluded).
49 subprocess.run(
50 rsync_argv('-a', '--keep-dirlinks', f'{src}/', f'{url}mod/blink2/'),
51 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
52
53 after = victim.read_text() if victim.exists() else None
54 if after == SECRET:
55 test_fail(
56 "the daemon refused a symlinked-chdir push that stock rsync (3.2.7) "
57 f"follows: blink2/secret/x did not reach public/secret/ ({victim} is still "
58 f"{after!r}). The exclude is name-based (the logical alias path), not the "
59 "physical target; it must not block this.")
60 print("daemon exclude is name-based: a push via an allowed symlinked chdir reaches "
61 "the nested excluded subtree (3.2.7-equivalent)")