Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,10 @@ mod tests {
let r = db.rotate_key_sealed("g1", b"spki-2", |_id| Err("seal boom".to_string()));
assert!(r.is_err());

let after = db.active_key("g1").unwrap().expect("original key still active");
let after = db
.active_key("g1")
.unwrap()
.expect("original key still active");
assert_eq!(after.key_id, before.key_id, "the original key stays active");
let opened = kek.open("g1", after.key_id, &after.sealed_pkcs8).unwrap();
assert_eq!(opened, b"secret-1");
Expand Down
6 changes: 4 additions & 2 deletions tests/at_rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ async fn private_key_is_ciphertext_at_rest() {
res.status() == 202 || res.status() == 200,
"POST /key should enqueue (202) or be already-ready (200)"
);
// Poll until ready (generous ceiling for slow release keygen).
// Poll until ready. Ceiling 3600 x 100ms ~ 360s: 2048-bit safe-prime
// keygen is high-variance and a single key has taken ~50s on a slow
// shared CI runner; the poll exits as soon as the key is ready.
let mut ready = false;
for _ in 0..1200 {
for _ in 0..3600 {
let res = client
.get(format!("{base}/key?group_id={g}"))
.send()
Expand Down
8 changes: 7 additions & 1 deletion tests/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ fn info(version: &str) -> Vec<u8> {

/// Fetch the active public key, polling `GET /key` until the async keygen
/// reports the key ready. The first call typically returns 202 pending.
///
/// Ceiling 3600 x 100ms ~ 360s: all five tests here run in parallel, each with
/// its own 2048-bit safe-prime keygen (the scheme rejects smaller moduli), so
/// on a slow shared CI runner a single key can take minutes to come ready. The
/// poll exits as soon as the key is ready; the ceiling only spends wall clock
/// on degraded runners instead of failing.
async fn fetch_pubkey(client: &reqwest::Client, base: &str, group: &str) -> PubKey {
for _ in 0..1200 {
for _ in 0..3600 {
let res = client
.get(format!("{base}/key?group_id={group}"))
.send()
Expand Down
12 changes: 10 additions & 2 deletions tests/keygen_dos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ use std::time::Duration;
const FAST_BITS: usize = 1024;

/// Poll `GET /key` until ready (200) or timeout. Returns the final status code.
///
/// The ceiling (3600 x 100ms ~ 360s) matches the other integration suites
/// (at_rest, issuance): safe-prime keygen is high-variance, the binary runs its
/// tests in parallel, and shared CI runners are slow, so many concurrent
/// keygens contending for a few vCPUs can legitimately take minutes. The poll
/// exits as soon as the key is ready, so the ceiling costs nothing on a healthy
/// run. The DoS bound is asserted by the immediate 200/202 responses, not by
/// this eventual-readiness poll, so a generous ceiling weakens nothing.
async fn poll_until_ready(client: &reqwest::Client, base: &str, group: &str) -> bool {
for _ in 0..600 {
for _ in 0..3600 {
let res = client
.get(format!("{base}/key?group_id={group}"))
.send()
Expand All @@ -37,7 +45,7 @@ async fn poll_until_ready(client: &reqwest::Client, base: &str, group: &str) ->
assert_eq!(body["status"], "ready");
return true;
}
tokio::time::sleep(Duration::from_millis(25)).await;
tokio::time::sleep(Duration::from_millis(100)).await;
}
false
}
Expand Down
Loading