[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:
@@ -398,14 +398,33 @@ mod unix {
|
|||||||
let (mut env, off) = env_with_pki().await;
|
let (mut env, off) = env_with_pki().await;
|
||||||
env.kill_control();
|
env.kill_control();
|
||||||
std::fs::write(env.dir.join("state/root.key"), off.root_key.serialize_pem()).unwrap();
|
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()
|
.command()
|
||||||
.arg("--config")
|
.arg("--config")
|
||||||
.arg(env.config_path())
|
.arg(env.config_path())
|
||||||
.output()
|
.stdout(std::process::Stdio::null())
|
||||||
|
.stderr(std::process::Stdio::piped())
|
||||||
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!out.status.success());
|
let deadline = Instant::now() + Duration::from_secs(20);
|
||||||
let err = String::from_utf8_lossy(&out.stderr);
|
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}");
|
assert!(err.contains("root"), "{err}");
|
||||||
// And the message never prints the key.
|
// And the message never prints the key.
|
||||||
assert!(!err.contains("PRIVATE KEY"), "{err}");
|
assert!(!err.contains("PRIVATE KEY"), "{err}");
|
||||||
|
|||||||
Reference in New Issue
Block a user