Debian Codegraph @

testsuite/operator-path-backup-dir-daemon_test.py

raw symbols SCIP
1 import os
2 import subprocess
3
4 from rsyncfns import (
5 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf,
6 )
7
8 DAEMON_PORT = 12960
9 SECRET = "PROTECTED-IN-EXCLUDED-SUBTREE\n"
10
11 base = SCRATCHDIR / 'backupdirdaemon'
12 rmtree(base)
13 base.mkdir()
14
15 mod = base / 'mod'
16 secret = base / 'secret'
17 if secret.exists():
18 rmtree(secret)# excluded subtree (exclude = /secret/)
19 secret.mkdir(parents=True)
20
21 victim = secret / 'f0'
22 victim.write_text(SECRET) # a file the backup must not clobber
23 mod.mkdir()
24 (mod / 'f0').write_text("OLD-DESTINATION-FILE-CONTENT\n")
25
26 blink = mod / 'blink' # euid-owned symlink -> excluded subtree
27 os.symlink(f'{secret}', blink)
28
29 src = base / 'src'
30 src.mkdir()
31 (src / 'f0').write_text("NEW\n")
32
33 conf = write_daemon_conf(
34 [('mod', {'path': str(mod), 'read only': 'no'})])
35 url = start_test_daemon(conf, DAEMON_PORT)
36
37 subprocess.run(
38 rsync_argv('-a', '--backup', '--backup-dir=/blink', f'{src}/', f'{url}mod/'),
39 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
40
41 after = victim.read_text() if victim.exists() else None
42 if after != SECRET:
43 test_fail(
44 "the daemon followed a --backup-dir symlink outside the module: "
45 f"{victim} is now {after!r} (a peer backed up over a file the module "
46 "does not serve).")
47 print("daemon confines a peer-supplied --backup-dir symlink to the served set")