Debian Codegraph @

testsuite/daemon-config_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Daemon coverage: the &include config directive (params.c include_config /
3 parse_directives) and a module whose path doesn't exist (clientserver.c
4 path_failure).
5
6 Uses a hand-written rsyncd.conf because &include is a directive line, not a
7 `name = value` parameter.
8 """
9
10 import subprocess
11
12 from rsyncfns import (
13 FROMDIR, SCRATCHDIR,
14 make_tree, rmtree, rsync_argv, start_test_daemon, test_fail,
15 )
16
17 DAEMON_PORT = 12893
18
19 src = FROMDIR
20 rmtree(src)
21 make_tree(src, depth=2)
22
23 inc = SCRATCHDIR / 'included.conf'
24 inc.write_text(f"[inc-mod]\n\tpath = {src}\n\tread only = yes\n\tcomment = via-include\n")
25
26 conf = SCRATCHDIR / 'daemon-config.conf'
27 conf.write_text(
28 f"pid file = {SCRATCHDIR}/rsyncd.pid\n"
29 "use chroot = no\n"
30 "hosts allow = localhost 127.0.0.0/8\n"
31 f"log file = {SCRATCHDIR}/rsyncd.log\n"
32 f"&include {inc}\n"
33 f"\n[badpath]\n\tpath = {SCRATCHDIR}/no-such-dir\n\tread only = yes\n"
34 )
35 url = start_test_daemon(conf, DAEMON_PORT)
36
37 # &include pulled in inc-mod: it must be listable and present in the module list.
38 proc = subprocess.run(rsync_argv('-r', f'{url}inc-mod/'),
39 stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
40 if proc.returncode != 0:
41 test_fail(f"&include-defined module not reachable: {proc.stderr}")
42 proc = subprocess.run(rsync_argv(url), capture_output=True, text=True)
43 if 'inc-mod' not in proc.stdout:
44 test_fail(f"&include-defined module absent from the listing:\n{proc.stdout}")
45
46 # A module whose path does not exist must fail the connection (path_failure).
47 proc = subprocess.run(rsync_argv('-r', f'{url}badpath/'),
48 stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True)
49 if proc.returncode == 0:
50 test_fail("a module with a non-existent path unexpectedly served a connection")
51
52 print("daemon-config: &include directive + bad-path failure verified")