Files
rsync/testsuite/ssh-basic_test.py
Andrew Tridgell f884cfe689 testsuite: ssh-basic: split the quoted rsh command before exec'ing it
rsh_cmd() returns the lsh.sh path quoted for rsync's own --rsh tokenizer,
so a build directory containing a character shlex.quote() will not pass
bare -- the '~' in a Debian snapshot version such as
rsync-3.5.1~git20260921 -- comes back wrapped in quotes.  The ssh-basic
probe passed that string straight to subprocess.run() as argv[0], where
no shell strips the quotes, and failed with FileNotFoundError.  Split it
with shlex first.

Found via the rsync-latest PPA, where every snapshot build fails
`make check` on exactly this test while the release builds pass.
2026-09-21 16:48:04 +10:00

60 lines
1.8 KiB
Python

#!/usr/bin/env python3
# Python rewrite of testsuite/ssh-basic.test.
#
# Basic two-step "remote shell" transfer via lsh.sh (or real ssh if
# rsync_enable_ssh_tests=yes is set in shconfig). Confirms that an -e
# RSH transfer reproduces the source tree on the destination, and that
# a follow-up --delete pass cleans up after a destination-side rename.
import os
import shlex
import shutil
import subprocess
from rsyncfns import (
FROMDIR, SRCDIR, TODIR,
checkit, hands_setup, runtest, test_skipped, rsync_path_arg, rsh_cmd,
)
SSH = rsh_cmd()
# Allow opting into real ssh via the shconfig variable, like the shell test.
if os.environ.get('rsync_enable_ssh_tests') == 'yes':
real_ssh = shutil.which('ssh')
if real_ssh:
SSH = real_ssh
# SSH is quoted for rsync's own tokenizer (a build path with '~' or a space
# comes out in quotes), so split it the same way before exec'ing it directly.
probe = subprocess.run(
[*shlex.split(SSH), '-oBatchMode yes', 'localhost', 'echo', 'yes'],
capture_output=True, text=True,
)
if probe.stdout.strip() != 'yes':
test_skipped(
"Skipping SSH tests because ssh connection to localhost not authorised"
)
print(f"Using remote shell: {SSH}")
hands_setup()
# RSYNC may be a multi-word command line; pass it through --rsync-path.
from rsyncfns import RSYNC, RSYNC_PEER
def _basic():
checkit(['-avH', '-e', SSH, f'--rsync-path={rsync_path_arg()}',
f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR)
def _delete_after_rename():
shutil.move(str(TODIR / 'text'), str(TODIR / 'ThisShouldGo'))
checkit(['--delete', '-avH', '-e', SSH, f'--rsync-path={rsync_path_arg()}',
f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR)
runtest("ssh: basic test", _basic)
runtest("ssh: renamed file", _delete_after_rename)