Debian Codegraph @

testsuite/operator-path-inplace-backup-dir_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # --inplace --backup-dir symlink policy matrix.
3 #
4 # With --inplace the generator makes the backup itself (it bypasses
5 # make_backup(), creating/opening the backup file directly via copy_file() /
6 # do_open_at() on the --backup-dir path), a separate code path from the plain
7 # --backup case in operator-path-backup-dir. The same operator-path policy must
8 # hold: a --backup-dir symlink is followed only when owned by uid 0 or the euid,
9 # an attacker's plant is refused -- absolute and relative, leaf and parent, with
10 # --insecure-links as the local opt-out.
11
12 import subprocess
13
14 from rsyncfns import rsync_argv, run_symlink_matrix, plant_operator_symlink
15
16 NFILES = 6
17
18
19 def case(ctx):
20 src = ctx.base / 'src'
21 dest = ctx.base / 'dest'
22 src.mkdir()
23 dest.mkdir()
24 for i in range(NFILES):
25 (src / f'f{i}').write_text("NEW-PUSHED-CONTENT\n") # distinct -> overwrite -> backup
26 (dest / f'f{i}').write_text("OLD\n")
27 opt, _escape = plant_operator_symlink(ctx, dest) # rel --backup-dir anchors at dest
28 extra = ['--insecure-links'] if ctx.insecure else []
29 subprocess.run(
30 rsync_argv('-a', '--inplace', '--backup', f'--backup-dir={opt}', *extra,
31 'src/', 'dest/'),
32 cwd=str(ctx.base), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
33 return any(p.is_file() for p in ctx.outside.rglob('*')) # backup escaped?
34
35
36 run_symlink_matrix('--inplace --backup-dir', case)
37 print("--inplace --backup-dir symlink policy matrix: enforced")