diff options
| author | tv <tv@krebsco.de> | 2026-11-18 11:15:24 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-18 12:23:30 +0100 |
| commit | 2ac20de00d0535dcb2a0d327f73c0b61fbbe4749 (patch) | |
| tree | 81edbf51f2688877167cdc8e75006dd55c1113d1 /src/federation/keys.rs | |
| parent | ecfed5d7e344c617f582d1d91c7395a210a70192 (diff) | |
keys: signing through an ssh-agent tested wherever tests run
The test fails without OpenSSH on the machine testing, rather than
passing without asking anything. Its directory is a scratch directory,
removed when the test ends, the agent stopped before it.
Diffstat (limited to 'src/federation/keys.rs')
| -rw-r--r-- | src/federation/keys.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/federation/keys.rs b/src/federation/keys.rs index fa13ec4..ed47b9b 100644 --- a/src/federation/keys.rs +++ b/src/federation/keys.rs @@ -421,47 +421,47 @@ mod tests { /// A signature through a running `ssh-agent` checks here and with `ssh-keygen -Y /// verify`, of an ECDSA key the agent alone holds and of an Ed25519 one; of ECDSA, also - /// one the agent gave with a high `s`. Where OpenSSH isn't installed, nothing is asked. + /// one the agent gave with a high `s`. The machine testing needs OpenSSH (`ssh-agent`, + /// `ssh-add`, `ssh-keygen`): without it, the test fails. #[test] fn signs_through_an_ssh_agent() { use std::process::{Command, Stdio}; - let dir = std::env::temp_dir().join(format!("continuum-agent-{}", std::process::id())); - std::fs::create_dir_all(&dir).expect("a directory"); + let dir = crate::files::scratch_dir("agent"); let socket = dir.join("agent"); - let agent = match Command::new("ssh-agent") - .arg("-D") - .arg("-a") - .arg(&socket) - .stdout(Stdio::null()) - .spawn() - { - Ok(agent) => agent, - Err(error) if error.kind() == std::io::ErrorKind::NotFound => { - eprintln!("no ssh-agent: skipped"); - return; - } - Err(error) => panic!("ssh-agent: {error}"), - }; - struct Stop(std::process::Child, std::path::PathBuf); + // The agent, stopped when the test ends: dropped before its directory, declared + // after it. + struct Stop(std::process::Child); impl Drop for Stop { fn drop(&mut self) { let _ = self.0.kill(); let _ = self.0.wait(); - let _ = std::fs::remove_dir_all(&self.1); } } - let _stop = Stop(agent, dir.clone()); + let _agent = Stop( + Command::new("ssh-agent") + .arg("-D") + .arg("-a") + .arg(&socket) + .stdout(Stdio::null()) + .spawn() + .expect("ssh-agent, of OpenSSH, which this test needs"), + ); for _ in 0..100 { if socket.exists() { break; } std::thread::sleep(std::time::Duration::from_millis(50)); } + assert!( + socket.exists(), + "ssh-agent made no socket at {}", + socket.display() + ); let run = |command: &mut Command| { let out = command .env("SSH_AUTH_SOCK", &socket) .output() - .expect("OpenSSH"); + .expect("OpenSSH, which this test needs"); assert!(out.status.success(), "{command:?}: {out:?}"); }; for kind in [["-t", "ecdsa", "-b", "256"].as_slice(), &["-t", "ed25519"]] { |
