Debian Codegraph @

testsuite/daemon-exclude-namebased_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # The daemon exclude/filter matches the LOGICAL module-relative NAME, anchored at
3 # the module root -- it is a visibility/tamper filter, not a physical-path
4 # boundary. rsyncd.conf(5) (filter parameter) says a subtree must be excluded
5 # with a trailing-slash or "/***" pattern; a bare anchored name protects only an
6 # entry literally of that name, not paths under it. This test makes that
7 # documented, name-based behaviour executable (it matches stock rsync 3.2.7).
8 #
9 # A direct push of a FILE to <excluded>/x2.tx:
10 # exclude = /excluded (bare name) -> LANDS (subtree not protected)
11 # exclude = /excluded/ (dir form) -> refused
12 # exclude = /excluded/*** (subtree) -> refused
13 # One daemon serves three modules (one per pattern) so a single rsyncd handles
14 # all cases -- avoids multi-daemon port/pid churn on some platforms. Unprivileged.
15
16 import subprocess
17
18 from rsyncfns import (
19 SCRATCHDIR, rmtree, rsync_argv, start_test_daemon, test_fail, write_daemon_conf,
20 )
21
22 DAEMON_PORT = 13010
23
24 # (module name, exclude pattern, expect the pushed file to land)
25 CASES = [
26 ('bare', '/excluded', True), # bare name: does NOT protect the subtree
27 ('dir', '/excluded/', False), # dir form: protects the subtree
28 ('triple', '/excluded/***', False), # documented subtree form: protects
29 ]
30
31 base = SCRATCHDIR / 'daemon-exclude-namebased'
32 rmtree(base)
33 base.mkdir()
34 src = base / 'hosts'
35 src.write_text("127.0.0.1 localhost\n")
36
37 modules = []
38 for name, pattern, _ in CASES:
39 mod = base / name
40 (mod / 'excluded').mkdir(parents=True)
41 modules.append((name, {'path': str(mod), 'read only': 'no', 'exclude': pattern}))
42
43 url = start_test_daemon(write_daemon_conf(modules), DAEMON_PORT)
44
45 for name, pattern, expect_landed in CASES:
46 subprocess.run(
47 rsync_argv('-a', str(src), f'{url}{name}/excluded/x2.tx'),
48 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
49 landed = (base / name / 'excluded' / 'x2.tx').exists()
50 if landed != expect_landed:
51 verb = "did not land" if expect_landed else "landed"
52 test_fail(
53 f"exclude={pattern!r}: a file push to excluded/x2.tx {verb} "
54 f"(landed={landed}, expected {expect_landed}). A bare anchored name "
55 "protects only an entry of that exact name; a subtree needs a "
56 "trailing-slash or /*** pattern (rsyncd.conf(5)).")
57
58 print("daemon exclude is name-based: a bare-name pattern does not protect the "
59 "subtree; a /dir/ or /dir/*** pattern does (3.2.7-equivalent)")