pytest: add tests using sshd

With either /usr/sbin/sshd found or configured via --with-test-sshd=path
add tests for SCP down- and uploads, insecure, with known hosts or not,
with authorized user key or unauthorized one.

Working now with libssh and libssh2, using a hashed known_hosts file.

Closes #19934
This commit is contained in:
Stefan Eissing 2025-12-11 16:02:41 +01:00 committed by Daniel Stenberg
parent 407d2f3d57
commit eb39fee40b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
12 changed files with 883 additions and 3 deletions

View file

@ -298,6 +298,35 @@ class EnvConfig:
except Exception:
self.danted = None
self.sshd = self.config['sshd']['sshd']
if self.sshd == '':
self.sshd = None
self._sshd_version = None
if self.sshd is not None:
try:
p = subprocess.run(args=[self.sshd, '-V'],
capture_output=True, text=True)
assert p.returncode == 0
if p.returncode != 0:
self.sshd = None
else:
m = re.match(r'^OpenSSH_(\d+\.\d+.*),.*', p.stderr)
assert m, f'version: {p.stderr}'
if m:
self._sshd_version = m.group(1)
else:
self.sshd = None
raise Exception(f'Unable to determine sshd version from: {p.stderr}')
except Exception:
self.sshd = None
if self.sshd:
self.sftpd = self.config['sshd']['sftpd']
if self.sftpd == '':
self.sftpd = None
else:
self.sftpd = None
self._tcpdump = shutil.which('tcpdump')
@property
@ -576,6 +605,14 @@ class Env:
def has_danted() -> bool:
return Env.CONFIG.danted is not None
@staticmethod
def has_sshd() -> bool:
return Env.CONFIG.sshd is not None
@staticmethod
def has_sftpd() -> bool:
return Env.has_sshd() and Env.CONFIG.sftpd is not None
@staticmethod
def tcpdump() -> Optional[str]:
return Env.CONFIG.tcpdmp