Debian Codegraph @

testsuite/daemon-refuse_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Daemon coverage: refuse options (a named option, a wildcard, and the
3 allow-list negation form).
4
5 daemon-refuse-compress_test.py covers the basic case; this widens it to a
6 different named option, a wildcard pattern, and the "* !a !v" allow-list idiom
7 documented in rsyncd.conf.5.
8 """
9
10 import subprocess
11
12 from rsyncfns import (
13 FROMDIR, SCRATCHDIR,
14 make_tree, makepath, rmtree, rsync_argv, run_rsync, start_test_daemon,
15 test_fail, verify_dirs, write_daemon_conf,
16 )
17
18 DAEMON_PORT = 12891
19
20 src = FROMDIR
21 rmtree(src)
22 make_tree(src, depth=3)
23
24 deldir = SCRATCHDIR / 'deldest'
25 makepath(deldir)
26
27 conf = write_daemon_conf([
28 ('refuse-delete', {'path': deldir, 'read only': 'no',
29 'refuse options': 'delete'}),
30 ('refuse-wild', {'path': src, 'read only': 'yes',
31 'refuse options': 'checksum*'}),
32 ('only-av', {'path': src, 'read only': 'yes',
33 'refuse options': '* !a !v'}),
34 ])
35 url = start_test_daemon(conf, DAEMON_PORT)
36
37
38 def refused(args, what):
39 proc = subprocess.run(rsync_argv(*args),
40 stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
41 text=True)
42 if proc.returncode == 0:
43 test_fail(f"{what} was not refused")
44 return proc.stderr
45
46
47 def allowed(args, what, expected=None, actual=None):
48 proc = subprocess.run(rsync_argv(*args),
49 stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
50 text=True)
51 if proc.returncode not in (0, 23):
52 test_fail(f"{what} was unexpectedly refused: {proc.stderr}")
53 # A 0/23 exit alone doesn't prove the transfer happened; verify the data
54 # actually landed for the allowed cases.
55 if expected is not None:
56 verify_dirs(expected, actual, label=what)
57
58
59 # --- a named refused option (delete) ----------------------------------------
60 refused(['-a', '--delete', f'{src}/', f'{url}refuse-delete/'],
61 "--delete on a refuse=delete module")
62 allowed(['-a', f'{src}/', f'{url}refuse-delete/'],
63 "plain push to a refuse=delete module", src, deldir)
64
65 # --- a wildcard refused option (checksum*) ----------------------------------
66 dest = SCRATCHDIR / 'wilddest'
67 makepath(dest)
68 refused(['-a', '--checksum', f'{url}refuse-wild/', f'{dest}/'],
69 "--checksum on a refuse=checksum* module")
70
71 # --- the "* !a !v" allow-list: -av allowed, -z refused ----------------------
72 rmtree(dest)
73 makepath(dest)
74 allowed(['-av', f'{url}only-av/', f'{dest}/'], "-av on an allow-list module",
75 src, dest)
76 refused(['-avz', f'{url}only-av/', f'{dest}/'],
77 "-z on an allow-list module")
78
79 print("daemon-refuse: named / wildcard / allow-list refuse options verified")