Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Sep 4, 2024
1 parent d09ea8a commit abaac1f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/rust-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ jobs:
env:
RUST_BACKTRACE: full
RUST_LOG: trace
USE_SUDO_IPTABLES: true
USE_SUDO_DOCKER: true
# NETHSM_DOCKER_HOSTNAME: nethsm
# services:
# docker:
Expand All @@ -112,7 +114,7 @@ jobs:
- uses: actions/checkout@v2

- name: install opensc and dependencies
run: apt-get update && apt-get install -y curl opensc openssl gcc xxd jq gnutls-bin make docker.io
run: sudo apt-get update && sudo apt-get install -y curl opensc openssl gcc xxd jq gnutls-bin make

- name: Install Rust
uses: actions-rs/toolchain@v1
Expand All @@ -126,4 +128,4 @@ jobs:
- name: build release
run: cargo build --release
- name: run network tests
run: cargo t --features pkcs11-full-tests -p nethsm_pkcs11 --test basic
run: cargo t --features pkcs11-full-tests -p nethsm_pkcs11 --test basic -- --nocapture
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkcs11/config_file/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum ConfigError {
}

const CONFIG_FILE_NAME: &str = "p11nethsm.conf";
const ENV_VAR_CONFIG_FILE: &str = "P11NETHSM_CONFIG_FILE";
pub const ENV_VAR_CONFIG_FILE: &str = "P11NETHSM_CONFIG_FILE";

pub fn config_files() -> Result<Vec<(Vec<u8>, PathBuf)>, ConfigError> {
if let Ok(file_path) = std::env::var(ENV_VAR_CONFIG_FILE) {
Expand Down
14 changes: 12 additions & 2 deletions pkcs11/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ fn basic() {
max_idle_connections: None,
}],
retries: None,
timeout_seconds: None,
timeout_seconds: Some(10),
connections_max_idle_duration: None,
tcp_keepalive: None,
}],
..Default::default()
},
Expand Down Expand Up @@ -135,7 +137,9 @@ fn multiple_instances() {
},
],
retries: None,
timeout_seconds: None,
timeout_seconds: Some(10),
connections_max_idle_duration: None,
tcp_keepalive: None,
}],
..Default::default()
},
Expand Down Expand Up @@ -185,6 +189,8 @@ fn timeout() {
}],
retries: None,
timeout_seconds: Some(10),
connections_max_idle_duration: None,
tcp_keepalive: None,
}],
..Default::default()
},
Expand Down Expand Up @@ -245,6 +251,8 @@ fn retries() {
delay_seconds: 2,
}),
timeout_seconds: Some(10),
connections_max_idle_duration: None,
tcp_keepalive: None,
}],
..Default::default()
},
Expand Down Expand Up @@ -320,6 +328,8 @@ fn multi_instance_retries() {
delay_seconds: 1,
}),
timeout_seconds: Some(1),
connections_max_idle_duration: None,
tcp_keepalive: None,
}],
..Default::default()
},
Expand Down
58 changes: 35 additions & 23 deletions pkcs11/tests/tools/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::io::{BufWriter, Read};
use std::io::BufWriter;
use std::net::Ipv4Addr;
use std::process::{Child, Stdio};
use std::sync::{Arc, LazyLock, Mutex, MutexGuard};
Expand Down Expand Up @@ -111,7 +111,7 @@ pub struct TestDropper {
}

fn iptables() -> Command {
if option_env!("USE_SUDO").is_some() {
if option_env!("USE_SUDO_IPTABLES").is_some() {
let mut command = Command::new("sudo");
command.arg("iptables");
command
Expand All @@ -120,6 +120,25 @@ fn iptables() -> Command {
}
}

fn docker() -> Command {
if option_env!("USE_SUDO_DOCKER").is_some() {
let mut command = Command::new("sudo");
command.arg("docker");
command
} else {
Command::new("docker")
}
}

fn kill() -> Command {
if option_env!("USE_SUDO_DOCKER").is_some() {
let mut command = Command::new("sudo");
command.arg("kill");
command
} else {
Command::new("kill")
}
}
impl TestContext {
fn unblock(port: u16) {
let out_in = iptables()
Expand Down Expand Up @@ -194,32 +213,18 @@ impl TestContext {

impl Drop for TestDropper {
fn drop(&mut self) {
Command::new("kill")
kill()
.args([self.command_to_kill.id().to_string()])
.spawn()
.unwrap()
.wait()
.unwrap();
self.command_to_kill.wait().unwrap();
let mut buf = String::new();
self.command_to_kill
.stdout
.take()
.unwrap()
.read_to_string(&mut buf)
.unwrap();
buf.push('\n');
self.command_to_kill
.stderr
.take()
.unwrap()
.read_to_string(&mut buf)
.unwrap();

for p in self.context.blocked_ports.iter().cloned() {
TestContext::unblock(p);
}
println!("{buf}");
println!("Finished killing nethsm");
}
}

Expand Down Expand Up @@ -307,25 +312,31 @@ pub fn run_tests(
};
let mut test_dropper = TestDropper {
serialize_test,
command_to_kill: Command::new("docker")
command_to_kill: docker()
.args([
"run",
"--init",
"--rm",
"-ti",
"-i",
"-p8443:8443",
"docker.io/nitrokey/nethsm:testing",
])
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.unwrap(),
context: TestContext {
blocked_ports: HashSet::new(),
},
};

let client = AgentBuilder::new().tls_config(Arc::new(tls_conf())).build();
let client = AgentBuilder::new()
.tls_config(Arc::new(tls_conf()))
.timeout_connect(Duration::from_secs(1))
.timeout_read(Duration::from_secs(10))
.timeout_write(Duration::from_secs(10))
.build();

let sdk_config = Configuration {
client,
Expand Down Expand Up @@ -378,4 +389,5 @@ pub fn run_tests(
let mut ctx = Ctx::new_and_initialize("../target/release/libnethsm_pkcs11.so").unwrap();
f(&mut test_dropper.context, &mut ctx);
ctx.close_all_sessions(0).unwrap();
println!("Ending test");
}

0 comments on commit abaac1f

Please sign in to comment.