Debian Codegraph @

testsuite/operator-path-backup-dir_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # --backup-dir symlink policy matrix. An operator --backup-dir must follow a
3 # symlink only when owned by uid 0 or the euid, refusing an attacker's plant --
4 # absolute AND relative, leaf and parent, with --insecure-links as the local
5 # opt-out. See run_symlink_matrix() in rsyncfns. RED on this branch: absolute
6 # cross-uid follows the attacker symlink (escape); relative refuses even the
7 # operator's own symlink (diverges from the uniform policy).
8
9 import subprocess
10
11 from rsyncfns import rsync_argv, run_symlink_matrix, plant_operator_symlink
12
13 NFILES = 6
14
15
16 def case(ctx):
17 src = ctx.base / 'src'
18 dest = ctx.base / 'dest'
19 src.mkdir()
20 dest.mkdir()
21 for i in range(NFILES):
22 (src / f'f{i}').write_text("NEW-PUSHED-CONTENT\n") # distinct -> overwrite -> backup
23 (dest / f'f{i}').write_text("OLD\n")
24 opt, _escape = plant_operator_symlink(ctx, dest) # rel --backup-dir anchors at dest
25 extra = ['--insecure-links'] if ctx.insecure else []
26 subprocess.run(
27 rsync_argv('-a', '--backup', f'--backup-dir={opt}', *extra, 'src/', 'dest/'),
28 cwd=str(ctx.base), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
29 return any(p.is_file() for p in ctx.outside.rglob('*')) # backup escaped?
30
31
32 run_symlink_matrix('--backup-dir', case)
33 print("--backup-dir symlink policy matrix: enforced")