From 9b919222ca18b985d51949b69d06b8d8fb7fa166 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 10 Oct 2026 08:19:14 +0100 Subject: [PATCH] wezterm-ssh: Skip e2e tests when sshd fixture cannot run properly This uses the system ssh client to validate the sshd fixture. Real client regressions will still fail the test rather than being skipped. --- wezterm-ssh/tests/sshd.rs | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/wezterm-ssh/tests/sshd.rs b/wezterm-ssh/tests/sshd.rs index 80e709ce3..f5f64c43b 100644 --- a/wezterm-ssh/tests/sshd.rs +++ b/wezterm-ssh/tests/sshd.rs @@ -2,6 +2,7 @@ use assert_fs::prelude::*; use assert_fs::TempDir; use rstest::*; use std::collections::HashMap; +use std::ffi::OsString; use std::io::Result as IoResult; use std::path::{Path, PathBuf}; use std::process::{Child, Command}; @@ -16,7 +17,50 @@ use std::os::unix::fs::PermissionsExt; const BIN_PATH_STR: &str = "/usr/sbin/sshd"; pub fn sshd_available() -> bool { - Path::new(BIN_PATH_STR).exists() + static AVAILABLE: LazyLock = LazyLock::new(probe_sshd); + *AVAILABLE +} + +/// Ensures that the system ssh client can talk to our sshd fixture. +/// If that doesn't work in this environment, none of our tests will +/// succeed. +fn probe_sshd() -> bool { + if !Path::new(BIN_PATH_STR).exists() { + return false; + } + + let sshd = match Sshd::spawn(SshdConfig::default()) { + Ok(sshd) => sshd, + Err(_) => return false, + }; + + let id_rsa = sshd.tmp.child("id_rsa"); + let known_hosts = sshd.tmp.child("known_hosts"); + + // Authenticate with the system ssh client, not wezterm-ssh, to make a + // wezterm-ssh bug show up as a failing test rather than a skipped one. + let args: Vec = vec![ + "-p".into(), + sshd.port.to_string().into(), + "-i".into(), + id_rsa.path().into(), + "-o".into(), + "IdentitiesOnly=yes".into(), + "-o".into(), + "BatchMode=yes".into(), + "-o".into(), + "StrictHostKeyChecking=no".into(), + "-o".into(), + format!("UserKnownHostsFile={}", known_hosts.path().display()).into(), + format!("{}@localhost", &*USERNAME).into(), + "true".into(), + ]; + + Command::new("ssh") + .args(&args) + .output() + .map(|out| out.status.success()) + .unwrap_or(false) } /// Ask the kernel to assign a free port.