Debian Codegraph @

testsuite/operator-path-copy-dest_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # --copy-dest symlink policy matrix. A followed --copy-dest symlink lets the
3 # basis lookup read an out-of-tree directory and COPY a matching file from it
4 # into dest. The basis here has the same size+mtime but DISTINCT content, so a
5 # followed symlink yields the basis content (proving the out-of-tree read); a
6 # confined one transfers the real source content. --insecure-links opts out.
7
8 import os
9 import subprocess
10
11 from rsyncfns import rsync_argv, run_symlink_matrix, plant_operator_symlink
12
13 T = 1234567890
14
15
16 def case(ctx):
17 src = ctx.base / 'src'
18 dest = ctx.base / 'dest'
19 src.mkdir()
20 dest.mkdir()
21 (src / 'f0').write_text("SRC1234\n")
22 opt, escape = plant_operator_symlink(ctx, dest)
23 escape.mkdir(parents=True, exist_ok=True)
24 (escape / 'f0').write_text("OUT5678\n") # same length, DISTINCT content
25 os.utime(src / 'f0', (T, T))
26 os.utime(escape / 'f0', (T, T))
27 extra = ['--insecure-links'] if ctx.insecure else []
28 subprocess.run(
29 rsync_argv('-a', f'--copy-dest={opt}', *extra, 'src/', 'dest/'),
30 cwd=str(ctx.base), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
31 df = dest / 'f0'
32 # Followed == dest got the out-of-tree basis content (copied), not the source.
33 return df.exists() and df.read_text() == "OUT5678\n"
34
35
36 run_symlink_matrix('--copy-dest', case)
37 print("--copy-dest symlink policy matrix: enforced")