| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
import os |
| 11 |
import subprocess |
| 12 |
|
| 13 |
from rsyncfns import ( |
| 14 |
SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf, |
| 15 |
) |
| 16 |
|
| 17 |
DAEMON_PORT = 12962 |
| 18 |
|
| 19 |
base = SCRATCHDIR / 'symlink-exclude-daemon' |
| 20 |
rmtree(base) |
| 21 |
base.mkdir() |
| 22 |
|
| 23 |
mod = base / 'mod' |
| 24 |
mod.mkdir() |
| 25 |
|
| 26 |
secret = mod / 'secret' |
| 27 |
secret.mkdir(parents=True) |
| 28 |
victim = secret / 'f0' |
| 29 |
victim.write_text("OLD-EXCLUDED-CONTENT\n") |
| 30 |
src = mod / 'src' |
| 31 |
src.mkdir() |
| 32 |
(src / 'f0').write_text("NEW\n") |
| 33 |
|
| 34 |
blink = mod / 'blink' |
| 35 |
os.symlink('secret/', blink) |
| 36 |
|
| 37 |
conf = write_daemon_conf( |
| 38 |
[('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/secret/'})]) |
| 39 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 40 |
|
| 41 |
|
| 42 |
subprocess.run( |
| 43 |
rsync_argv('-a', f'{src}/', f'{url}mod/blink/'), |
| 44 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 45 |
|
| 46 |
after = victim.read_text() if victim.exists() else None |
| 47 |
if after != "NEW\n": |
| 48 |
test_fail( |
| 49 |
"the daemon refused a symlink that stock rsync (3.2.7) follows: " |
| 50 |
f"{secret / 'f0'} is {after!r}, expected 'NEW\\n'. The daemon exclude " |
| 51 |
"filter is name-based, not a symlink boundary -- it must not block this " |
| 52 |
"(use `munge symlinks` to defend a writable module).") |
| 53 |
print("daemon exclude is name-based: a symlink whose name is not excluded is " |
| 54 |
"followed (3.2.7-equivalent)") |