Debian Codegraph @

testsuite/rrsync-logfile-symlink_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 import os
3 import subprocess
4
5 from rsyncfns import SCRATCHDIR, test_fail
6 from rsyncfns import patched_rrsync
7
8 base = SCRATCHDIR / 'rrsync-logfile'
9 restricted = base / 'restricted'
10 outside = base / 'outside.log'
11 base.mkdir(parents=True, exist_ok=True)
12 restricted.mkdir(exist_ok=True)
13 outside.write_text('ORIGINAL\n')
14 os.symlink(outside, base / 'rrsync.log')
15 rrsync = patched_rrsync(base)
16
17 env = {**os.environ, 'SSH_ORIGINAL_COMMAND': 'rsync --server --sender . .'}
18 proc = subprocess.run([str(rrsync), '-ro', '-no-lock', str(restricted)],
19 cwd=base, env=env, stdout=subprocess.PIPE,
20 stderr=subprocess.PIPE, text=True)
21 if proc.returncode != 0:
22 test_fail(f"patched rrsync command failed unexpectedly:\n{proc.stderr}")
23 if outside.read_text() != 'ORIGINAL\n':
24 test_fail("rrsync followed a symlinked LOGFILE and appended outside the restricted policy")
25
26 print("rrsync-logfile-symlink: LOGFILE symlink is not followed")