Debian Codegraph @

testsuite/operator-path-insecure-links-refused_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # A daemon must DROP the connection if a client passes --insecure-links over the
3 # protocol. --insecure-links is a local-only opt-out; a client must never be
4 # able to disable the daemon's symlink confinement, so even attempting it is a
5 # hard error that ends the connection (the daemon's own opt-out is the
6 # "insecure links" module parameter, never the client flag). No root needed.
7
8 import subprocess
9
10 from rsyncfns import (
11 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail,
12 write_daemon_conf,
13 )
14
15 DAEMON_PORT = 12902
16
17 base = SCRATCHDIR / 'insecure-refused'
18 rmtree(base)
19 base.mkdir()
20 mod = base / 'mod'
21 mod.mkdir()
22 (mod / 'f').write_text("data\n")
23
24 conf = write_daemon_conf([('mod', {'path': mod, 'read only': 'yes'})])
25 url = start_test_daemon(conf, DAEMON_PORT)
26
27 # Control: a normal listing works.
28 ok = subprocess.run(rsync_argv(f'{url}mod/'),
29 stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
30 if ok.returncode != 0:
31 test_fail(f"control listing failed (daemon broken?): {ok.stderr}")
32
33 # A client forwarding --insecure-links must be refused and the connection dropped.
34 proc = subprocess.run(rsync_argv('-M--insecure-links', f'{url}mod/'),
35 stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
36 out = (proc.stdout or '') + (proc.stderr or '')
37 if proc.returncode == 0:
38 test_fail("the daemon accepted a client-sent --insecure-links instead of "
39 f"dropping the connection: {out!r}")
40 if 'insecure-links' not in out and 'not allowed' not in out:
41 test_fail("the connection ended but without the expected refusal message "
42 f"(@ERROR: --insecure-links is not allowed from a client): {out!r}")
43 print("daemon drops the connection on a client-sent --insecure-links")