Debian Codegraph @

testsuite/delete-missing-args-files-from_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Functional regression: --delete-missing-args with --files-from aborts the
3 # transfer with "invalid file mode 00 ... protocol incompatibility (code 2)"
4 # instead of deleting the entries that are missing on the sender.
5 #
6 # Reported as #910 ("Security fix in flist.c breaks --delete-missing-args with
7 # --files-from").
8 #
9 # Root cause: for a --files-from entry that does not exist on the sender,
10 # --delete-missing-args==2 deliberately sends a "missing" file entry with
11 # mode == 0 (the generator's signal to delete it on the receiver). The 3.4.x
12 # security mode-validation added to recv_file_entry() (flist.c) rejects mode 0
13 # as an invalid file type BEFORE the generator can act on it, so the receiver
14 # bails out with a protocol error and nothing is deleted. Works in 3.4.1.
15 #
16 # Two scenarios, since a missing FILE and a missing DIRECTORY are sent as
17 # distinct mode-0 entries:
18 # * a regular file present on the receiver but absent on the sender, and
19 # * a directory present on the receiver but absent on the sender,
20 # both named in --files-from. Both must be deleted on the receiver.
21 #
22 # XFAIL until recv_file_entry() accepts the missing-args mode-0 entry again
23 # (the accompanying flist.c fix). Runs at any uid.
24
25 import subprocess
26
27 from rsyncfns import (
28 SCRATCHDIR, makepath, rmtree, rsync_argv, start_test_daemon, test_fail,
29 test_xfail, write_daemon_conf,
30 )
31
32 DAEMON_PORT = 12910
33
34 mod = SCRATCHDIR / 'recvmod910' # daemon receive module
35 src = SCRATCHDIR / 'src910'
36 rmtree(mod)
37 rmtree(src)
38 makepath(mod / 'ghostdir', src)
39 (src / 'keep.txt').write_text("keep-me\n") # present on sender
40 (mod / 'keep.txt').write_text("stale\n") # will be updated
41 (mod / 'ghost.txt').write_text("delete-me-file\n") # absent on sender -> delete
42 (mod / 'ghostdir' / 'inner').write_text("delete-me-dir\n") # absent on sender -> delete
43
44 # --files-from lists one present file plus the two entries that are missing on
45 # the sender (a file and a directory) -- those become mode-0 "missing" entries.
46 flist = SCRATCHDIR / 'files910.lst'
47 flist.write_text("keep.txt\nghost.txt\nghostdir\n")
48
49 conf = write_daemon_conf([
50 ('recv', {'path': str(mod), 'read only': 'no'}),
51 ])
52 url = start_test_daemon(conf, DAEMON_PORT)
53
54 proc = subprocess.run(
55 rsync_argv('-a', '--delete', '--delete-missing-args',
56 f'--files-from={flist}', f'{src}/', f'{url}recv/'),
57 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
58 out = proc.stdout or ''
59 print(out)
60
61 # Bug present: the receiver rejects the mode-0 missing-args entry.
62 if 'invalid file mode' in out or (proc.returncode == 2 and (mod / 'ghost.txt').exists()):
63 test_xfail(
64 "#910: --delete-missing-args with --files-from aborts with "
65 "`invalid file mode 00 ... protocol incompatibility (code 2)`. The "
66 "sender sends mode-0 entries for the missing args (the delete signal), "
67 "but recv_file_entry()'s 3.4.x mode-validation rejects mode 0 before the "
68 "generator can delete them. To be closed by accepting the "
69 "missing-args mode-0 entry in recv_file_entry().")
70
71 # Bug fixed (or absent): both missing args were deleted, the present file kept.
72 if proc.returncode != 0:
73 test_fail(f"transfer failed unexpectedly (rc={proc.returncode}); "
74 f"not the #910 mode-00 symptom:\n{out}")
75 if (mod / 'ghost.txt').exists():
76 test_fail("missing-arg file ghost.txt was not deleted on the receiver")
77 if (mod / 'ghostdir').exists():
78 test_fail("missing-arg directory ghostdir was not deleted on the receiver")
79 if not (mod / 'keep.txt').is_file() or (mod / 'keep.txt').read_text() != "keep-me\n":
80 test_fail("present file keep.txt was not delivered/updated correctly")