diff --git a/crates/control/tests/pki.rs b/crates/control/tests/pki.rs index d1eee6b..e7858f9 100644 --- a/crates/control/tests/pki.rs +++ b/crates/control/tests/pki.rs @@ -398,14 +398,33 @@ mod unix { let (mut env, off) = env_with_pki().await; env.kill_control(); std::fs::write(env.dir.join("state/root.key"), off.root_key.serialize_pem()).unwrap(); - let out = env + // A control that does not refuse would serve forever: give it 20 s, then kill it. + let mut child = env .command() .arg("--config") .arg(env.config_path()) - .output() + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::piped()) + .spawn() .unwrap(); - assert!(!out.status.success()); - let err = String::from_utf8_lossy(&out.stderr); + let deadline = Instant::now() + Duration::from_secs(20); + let status = loop { + if let Some(s) = child.try_wait().unwrap() { + break Some(s); + } + if Instant::now() > deadline { + let _ = child.kill(); + let _ = child.wait(); + break None; + } + std::thread::sleep(Duration::from_millis(50)); + }; + assert!( + status.is_some_and(|s| !s.success()), + "control started with a root key in its state dir" + ); + let mut err = String::new(); + std::io::Read::read_to_string(&mut child.stderr.take().unwrap(), &mut err).unwrap(); assert!(err.contains("root"), "{err}"); // And the message never prints the key. assert!(!err.contains("PRIVATE KEY"), "{err}");