mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-27 22:13:12 -08:00
fix(API): Be polite and kill child processes in api integration tests
This commit is contained in:
@@ -19,7 +19,7 @@ use rosenpass_util::{
|
|||||||
file::LoadValueB64,
|
file::LoadValueB64,
|
||||||
io::IoErrorKind,
|
io::IoErrorKind,
|
||||||
length_prefix_encoding::{decoder::LengthPrefixDecoder, encoder::LengthPrefixEncoder},
|
length_prefix_encoding::{decoder::LengthPrefixDecoder, encoder::LengthPrefixEncoder},
|
||||||
mem::MoveExt,
|
mem::{DiscardResultExt, MoveExt},
|
||||||
mio::WriteWithFileDescriptors,
|
mio::WriteWithFileDescriptors,
|
||||||
zerocopy::ZerocopySliceExt,
|
zerocopy::ZerocopySliceExt,
|
||||||
};
|
};
|
||||||
@@ -29,6 +29,15 @@ use zerocopy::AsBytes;
|
|||||||
|
|
||||||
use rosenpass::protocol::SymKey;
|
use rosenpass::protocol::SymKey;
|
||||||
|
|
||||||
|
struct KillChild(std::process::Child);
|
||||||
|
|
||||||
|
impl Drop for KillChild {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.kill().discard_result();
|
||||||
|
self.0.wait().discard_result()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn api_integration_api_setup() -> anyhow::Result<()> {
|
fn api_integration_api_setup() -> anyhow::Result<()> {
|
||||||
rosenpass_secret_memory::policy::secret_policy_use_only_malloc_secrets();
|
rosenpass_secret_memory::policy::secret_policy_use_only_malloc_secrets();
|
||||||
@@ -120,33 +129,37 @@ fn api_integration_api_setup() -> anyhow::Result<()> {
|
|||||||
let deliberate_fail_child_fd = 3;
|
let deliberate_fail_child_fd = 3;
|
||||||
|
|
||||||
// Start peer a
|
// Start peer a
|
||||||
let _proc_a = std::process::Command::new(env!("CARGO_BIN_EXE_rosenpass"))
|
let _proc_a = KillChild(
|
||||||
.args(["--api-stream-fd", &deliberate_fail_child_fd.to_string()])
|
std::process::Command::new(env!("CARGO_BIN_EXE_rosenpass"))
|
||||||
.fd_mappings(vec![FdMapping {
|
.args(["--api-stream-fd", &deliberate_fail_child_fd.to_string()])
|
||||||
parent_fd: deliberate_fail_api_server.move_here().as_raw_fd(),
|
.fd_mappings(vec![FdMapping {
|
||||||
child_fd: 3,
|
parent_fd: deliberate_fail_api_server.move_here().as_raw_fd(),
|
||||||
}])?
|
child_fd: 3,
|
||||||
.args([
|
}])?
|
||||||
"exchange-config",
|
.args([
|
||||||
peer_a.config_file_path.to_str().context("")?,
|
"exchange-config",
|
||||||
])
|
peer_a.config_file_path.to_str().context("")?,
|
||||||
.stdin(Stdio::null())
|
])
|
||||||
.stdout(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.spawn()?;
|
.stdout(Stdio::null())
|
||||||
|
.spawn()?,
|
||||||
|
);
|
||||||
|
|
||||||
// Start peer b
|
// Start peer b
|
||||||
let proc_b = std::process::Command::new(env!("CARGO_BIN_EXE_rosenpass"))
|
let mut proc_b = KillChild(
|
||||||
.args([
|
std::process::Command::new(env!("CARGO_BIN_EXE_rosenpass"))
|
||||||
"exchange-config",
|
.args([
|
||||||
peer_b.config_file_path.to_str().context("")?,
|
"exchange-config",
|
||||||
])
|
peer_b.config_file_path.to_str().context("")?,
|
||||||
.stdin(Stdio::null())
|
])
|
||||||
.stderr(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
.stdout(Stdio::piped())
|
.stderr(Stdio::null())
|
||||||
.spawn()?;
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()?,
|
||||||
|
);
|
||||||
|
|
||||||
// Acquire stdout
|
// Acquire stdout
|
||||||
let mut out_b = BufReader::new(proc_b.stdout.context("")?).lines();
|
let mut out_b = BufReader::new(proc_b.0.stdout.take().context("")?).lines();
|
||||||
|
|
||||||
// Now connect to the peers
|
// Now connect to the peers
|
||||||
let api_path = peer_a.api.listen_path[0].as_path();
|
let api_path = peer_a.api.listen_path[0].as_path();
|
||||||
|
|||||||
@@ -8,16 +8,25 @@ use std::{
|
|||||||
use anyhow::{bail, Context};
|
use anyhow::{bail, Context};
|
||||||
use rosenpass::api;
|
use rosenpass::api;
|
||||||
use rosenpass_to::{ops::copy_slice_least_src, To};
|
use rosenpass_to::{ops::copy_slice_least_src, To};
|
||||||
use rosenpass_util::zerocopy::ZerocopySliceExt;
|
|
||||||
use rosenpass_util::{
|
use rosenpass_util::{
|
||||||
file::LoadValueB64,
|
file::LoadValueB64,
|
||||||
length_prefix_encoding::{decoder::LengthPrefixDecoder, encoder::LengthPrefixEncoder},
|
length_prefix_encoding::{decoder::LengthPrefixDecoder, encoder::LengthPrefixEncoder},
|
||||||
};
|
};
|
||||||
|
use rosenpass_util::{mem::DiscardResultExt, zerocopy::ZerocopySliceExt};
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
use zerocopy::AsBytes;
|
use zerocopy::AsBytes;
|
||||||
|
|
||||||
use rosenpass::protocol::SymKey;
|
use rosenpass::protocol::SymKey;
|
||||||
|
|
||||||
|
struct KillChild(std::process::Child);
|
||||||
|
|
||||||
|
impl Drop for KillChild {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.kill().discard_result();
|
||||||
|
self.0.wait().discard_result()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn api_integration_test() -> anyhow::Result<()> {
|
fn api_integration_test() -> anyhow::Result<()> {
|
||||||
rosenpass_secret_memory::policy::secret_policy_use_only_malloc_secrets();
|
rosenpass_secret_memory::policy::secret_policy_use_only_malloc_secrets();
|
||||||
@@ -93,28 +102,32 @@ fn api_integration_test() -> anyhow::Result<()> {
|
|||||||
peer_b.commit()?;
|
peer_b.commit()?;
|
||||||
|
|
||||||
// Start peer a
|
// Start peer a
|
||||||
let proc_a = std::process::Command::new(env!("CARGO_BIN_EXE_rosenpass"))
|
let mut proc_a = KillChild(
|
||||||
.args([
|
std::process::Command::new(env!("CARGO_BIN_EXE_rosenpass"))
|
||||||
"exchange-config",
|
.args([
|
||||||
peer_a.config_file_path.to_str().context("")?,
|
"exchange-config",
|
||||||
])
|
peer_a.config_file_path.to_str().context("")?,
|
||||||
.stdin(Stdio::null())
|
])
|
||||||
.stdout(Stdio::piped())
|
.stdin(Stdio::null())
|
||||||
.spawn()?;
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()?,
|
||||||
|
);
|
||||||
|
|
||||||
// Start peer b
|
// Start peer b
|
||||||
let proc_b = std::process::Command::new(env!("CARGO_BIN_EXE_rosenpass"))
|
let mut proc_b = KillChild(
|
||||||
.args([
|
std::process::Command::new(env!("CARGO_BIN_EXE_rosenpass"))
|
||||||
"exchange-config",
|
.args([
|
||||||
peer_b.config_file_path.to_str().context("")?,
|
"exchange-config",
|
||||||
])
|
peer_b.config_file_path.to_str().context("")?,
|
||||||
.stdin(Stdio::null())
|
])
|
||||||
.stdout(Stdio::piped())
|
.stdin(Stdio::null())
|
||||||
.spawn()?;
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()?,
|
||||||
|
);
|
||||||
|
|
||||||
// Acquire stdout
|
// Acquire stdout
|
||||||
let mut out_a = BufReader::new(proc_a.stdout.context("")?).lines();
|
let mut out_a = BufReader::new(proc_a.0.stdout.take().context("")?).lines();
|
||||||
let mut out_b = BufReader::new(proc_b.stdout.context("")?).lines();
|
let mut out_b = BufReader::new(proc_b.0.stdout.take().context("")?).lines();
|
||||||
|
|
||||||
// Wait for the keys to successfully exchange a key
|
// Wait for the keys to successfully exchange a key
|
||||||
let mut attempt = 0;
|
let mut attempt = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user