| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
import os |
| 20 |
import subprocess |
| 21 |
|
| 22 |
from rsyncfns import ( |
| 23 |
SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf, |
| 24 |
) |
| 25 |
|
| 26 |
DAEMON_PORT = 12983 |
| 27 |
SECRET = "PROTECTED-IN-EXCLUDED-SUBTREE\n" |
| 28 |
|
| 29 |
base = SCRATCHDIR / 'symlink-exclude-deep' |
| 30 |
rmtree(base) |
| 31 |
base.mkdir() |
| 32 |
|
| 33 |
mod = base / 'mod' |
| 34 |
mod.mkdir() |
| 35 |
pub = mod / 'pub' |
| 36 |
pub.mkdir() |
| 37 |
secret = pub / 'secret' |
| 38 |
secret.mkdir() |
| 39 |
victim = secret / 'x' |
| 40 |
victim.write_text(SECRET) |
| 41 |
|
| 42 |
os.symlink('pub/', mod / 'dir2') |
| 43 |
|
| 44 |
src = base / 'src' |
| 45 |
(src / 'dir2' / 'secret').mkdir(parents=True) |
| 46 |
(src / 'dir2' / 'secret' / 'x').write_text("NEW\n") |
| 47 |
|
| 48 |
conf = write_daemon_conf( |
| 49 |
[('mod', {'path': str(mod), 'read only': 'no', 'exclude': '/pub/secret/'})]) |
| 50 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 51 |
|
| 52 |
subprocess.run( |
| 53 |
rsync_argv('-a', '--keep-dirlinks', f'{src}/', f'{url}mod/'), |
| 54 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 55 |
|
| 56 |
after = victim.read_text() if victim.exists() else None |
| 57 |
if after == SECRET: |
| 58 |
test_fail( |
| 59 |
"the daemon refused a deeper in-tree dir symlink that stock rsync (3.2.7) " |
| 60 |
f"follows: a push to dir2/secret/x did not reach pub/secret/ ({victim} is " |
| 61 |
f"still {after!r}). The exclude is name-based ('dir2/secret', not the " |
| 62 |
"physical 'pub/secret'); it must not block this.") |
| 63 |
print("daemon exclude is name-based: a deeper in-tree dir symlink reaches the " |
| 64 |
"nested excluded subtree (3.2.7-equivalent)") |