[control] Root-key refusal test: a control that does not refuse is killed after 20 s instead of hanging the suite

This commit is contained in:
2026-11-08 00:10:26 +01:00
parent b85c38f615
commit e2a777882c
+23 -4
View File
@@ -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}");