aboutsummaryrefslogtreecommitdiff
path: root/tests/machine_setup.rs
diff options
context:
space:
mode:
authorakbash <akbash@herdr.dev>2026-09-08 03:34:54 +0300
committerGitHub <noreply@github.com>2026-09-08 03:34:54 +0300
commit9e01168b140ce8e3821131345dc82bc2bf9994eb (patch)
tree482832a0af8e79ea30f2ea4dcadbd874ac7fdb1d /tests/machine_setup.rs
parent792b2baa447a3ed413cc755ea3d76582021c648a (diff)
fix: show ssh errors during machine setup (#3733)
refs #3731 Co-authored-by: akbash-bot <300245827+akbash-bot@users.noreply.github.com>
Diffstat (limited to 'tests/machine_setup.rs')
-rw-r--r--tests/machine_setup.rs59
1 files changed, 55 insertions, 4 deletions
diff --git a/tests/machine_setup.rs b/tests/machine_setup.rs
index 752126fc..da763d98 100644
--- a/tests/machine_setup.rs
+++ b/tests/machine_setup.rs
@@ -11,7 +11,15 @@ use portable_pty::{native_pty_system, CommandBuilder, PtySize};
// No real SSH connection or server is started. Stop at startup after recording setup actions.
const SSH: &str = r#"#!/bin/sh
-for arg do last=$arg; done
+for arg do
+ last=$arg
+ if [ "$arg" = 'StrictHostKeyChecking=yes' ]; then strict_host_key_check=yes; fi
+done
+if [ "$FAKE_STRICT_HOST_KEY_FAILURE" = yes ] && [ "$strict_host_key_check" = yes ]; then
+ echo 'No RSA host key is known for fake-host and you have requested strict checking.' >&2
+ echo 'Host key verification failed.' >&2
+ exit 255
+fi
if [ "$last" = 'command -v herdr' ]; then
echo /home/remote/.local/bin/herdr
exit 0
@@ -32,6 +40,8 @@ case "$script" in
*'status server --json'*)
if [ -f "$FAKE_ROOT/stopped" ]; then
echo '{"running":false}'
+ elif [ "$FAKE_STRICT_HOST_KEY_FAILURE" = yes ]; then
+ echo '{"running":true,"version":"0.8.2","capabilities":{"live_handoff":true,"detached_server_daemon":true,"endpoint_protocol_generation":1,"surface_interest":true,"health_check":true}}'
else
echo '{"running":true,"version":"0.8.2","capabilities":{"live_handoff":true,"detached_server_daemon":true}}'
fi ;;
@@ -49,15 +59,26 @@ struct SetupResult {
output: String,
actions: String,
prompts: usize,
+ success: bool,
}
fn setup(installed: &str, answer: &str, handoff: bool) -> SetupResult {
+ setup_with_strict_host_key_failure(installed, answer, handoff, false)
+}
+
+fn setup_with_strict_host_key_failure(
+ installed: &str,
+ answer: &str,
+ handoff: bool,
+ strict_host_key_failure: bool,
+) -> SetupResult {
let root = std::path::PathBuf::from(format!(
- "/var/tmp/herdr-machine-setup-{}-{}-{}-{}",
+ "/var/tmp/herdr-machine-setup-{}-{}-{}-{}-{}",
std::process::id(),
installed,
answer.trim().is_empty(),
- handoff
+ handoff,
+ strict_host_key_failure
));
let app = if cfg!(debug_assertions) {
"herdr-dev"
@@ -97,6 +118,10 @@ fn setup(installed: &str, answer: &str, handoff: bool) -> SetupResult {
command.env("FAKE_ROOT", &root);
command.env("FAKE_INSTALLED", installed);
command.env(
+ "FAKE_STRICT_HOST_KEY_FAILURE",
+ if strict_host_key_failure { "yes" } else { "no" },
+ );
+ command.env(
"FAKE_CLIENT_STATUS",
String::from_utf8(status.stdout).unwrap(),
);
@@ -151,7 +176,7 @@ fn setup(installed: &str, answer: &str, handoff: bool) -> SetupResult {
}
}
}
- child.wait().unwrap();
+ let status = child.wait().unwrap();
drop(writer);
drop(pair.master);
reading.join().unwrap();
@@ -172,10 +197,36 @@ fn setup(installed: &str, answer: &str, handoff: bool) -> SetupResult {
output,
actions,
prompts,
+ success: status.success(),
}
}
#[test]
+fn machine_add_reports_strict_host_key_failure() {
+ let result = setup_with_strict_host_key_failure("new", "", false, true);
+ assert!(!result.success, "{}", result.output);
+ assert_eq!(result.prompts, 0, "{}", result.output);
+ assert!(result.actions.is_empty(), "{}", result.output);
+ assert!(
+ result.output.contains("Host key verification failed"),
+ "{}",
+ result.output
+ );
+ assert!(
+ result
+ .output
+ .contains("saved machines use strict host-key checking"),
+ "{}",
+ result.output
+ );
+ assert!(
+ !result.output.contains("lost connection to server"),
+ "{}",
+ result.output
+ );
+}
+
+#[test]
fn machine_setup_old_install_requires_one_explicit_stop_approval() {
let result = setup("old", "y\n", false);
assert_eq!(result.prompts, 1, "{}", result.output);