| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
import os |
| 11 |
import subprocess |
| 12 |
|
| 13 |
from rsyncfns import ( |
| 14 |
SCRATCHDIR, TOOLDIR, |
| 15 |
assert_exists, assert_not_exists, rmtree, test_fail, test_skipped, |
| 16 |
) |
| 17 |
|
| 18 |
|
| 19 |
mod = SCRATCHDIR / 'module' |
| 20 |
trap_outside = SCRATCHDIR / 'trap' |
| 21 |
rmtree(mod) |
| 22 |
rmtree(trap_outside) |
| 23 |
(mod / 'realdir').mkdir(parents=True) |
| 24 |
trap_outside.mkdir(parents=True) |
| 25 |
|
| 26 |
(mod / 'top-to-dir').write_text("top-to-dir\n") |
| 27 |
(mod / 'realdir' / 'dir-to-top').write_text("dir-to-top\n") |
| 28 |
(mod / 'top-to-escape').write_text("top-to-escape\n") |
| 29 |
(trap_outside / 'outside-source').write_text("outside-source\n") |
| 30 |
(mod / 'realdir' / 'same-old').write_text("same-old\n") |
| 31 |
(mod / 'top-old').write_text("top-old\n") |
| 32 |
os.symlink('../trap', mod / 'escape_link') |
| 33 |
|
| 34 |
proc = subprocess.run([str(TOOLDIR / 't_rename_secure'), str(mod)]) |
| 35 |
if proc.returncode == 77: |
| 36 |
test_skipped("t_rename_secure skipped") |
| 37 |
if proc.returncode != 0: |
| 38 |
test_fail("t_rename_secure reported failures (see stderr above)") |
| 39 |
|
| 40 |
assert_not_exists(trap_outside / 'new-outside', |
| 41 |
f"rename escaped the module and created {trap_outside}/new-outside") |
| 42 |
assert_exists(trap_outside / 'outside-source', |
| 43 |
f"rename escaped the module and moved {trap_outside}/outside-source") |