Debian Codegraph @

testsuite/daemon-refuse-compress_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/daemon-refuse-compress.test.
3 #
4 # A daemon module configured with "refuse options = compress" must
5 # reject clients that ask for compression, and still serve the same
6 # transfer when the client does not.
7
8 import subprocess
9
10 from rsyncfns import (
11 CHKDIR, FROMDIR, SCRATCHDIR, TODIR,
12 build_rsyncd_conf, checkit, hands_setup, rmtree,
13 rsync_argv, run_rsync, start_test_daemon, test_fail,
14 )
15
16
17 DAEMON_PORT = 12876
18
19 conf = build_rsyncd_conf()
20 # Append an extra module that refuses --compress (-z).
21 with open(conf, 'a') as f:
22 f.write(f"""
23 [no-compress]
24 \tpath = {FROMDIR}
25 \tread only = yes
26 \trefuse options = compress
27 """)
28
29 hands_setup()
30 run_rsync('-av', '--exclude=foobar.baz', f'{FROMDIR}/', f'{CHKDIR}/')
31
32 url = start_test_daemon(conf, DAEMON_PORT) + 'no-compress/'
33
34 # A compressed transfer must be refused.
35 errlog = SCRATCHDIR / 'refuse.err'
36 proc = subprocess.run(
37 rsync_argv('-avz', url, f'{TODIR}/'),
38 stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True,
39 )
40 errlog.write_text(proc.stderr)
41 if proc.returncode == 0:
42 print(proc.stderr)
43 test_fail("compressed transfer was not refused")
44 if '--compress' not in proc.stderr:
45 print(proc.stderr)
46 test_fail("expected refuse error mentioning --compress")
47
48 # The same transfer without -z must succeed.
49 rmtree(TODIR)
50 TODIR.mkdir()
51 checkit(['-av', url, f'{TODIR}/'], CHKDIR, TODIR,
52 allowed_codes=(0, 23))