154 lines
5.9 KiB
Rust
154 lines
5.9 KiB
Rust
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
//! The differential suite (ROADMAP §5 layer 1). Needs the `caddy` binary on PATH (or
|
|
//! `$IANITOR_CADDY_BIN`); without it the tests fail unless `IANITOR_ALLOW_SKIP=1`.
|
|
|
|
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
|
|
#[cfg(not(unix))]
|
|
#[test]
|
|
fn skipped_on_windows() {
|
|
eprintln!(
|
|
"SKIPPED on Windows: {} needs Linux (Pingora runner, Caddy, Pebble); run it in WSL2, see CLAUDE.md",
|
|
file!()
|
|
);
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
mod unix {
|
|
use ianitor_diff::{
|
|
Action, Env, break_caddy, break_edge, compile_pair, corpus, run_cases, run_corpus, settle,
|
|
start_caddy, start_edge,
|
|
};
|
|
use ianitor_testkit::proc::require_binary;
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
|
async fn ianitor_and_caddy_answer_the_corpus_identically() {
|
|
let Some(caddy_bin) = require_binary("caddy") else {
|
|
return;
|
|
};
|
|
assert!(
|
|
corpus().len() >= 20,
|
|
"the seed corpus has at least 20 requests"
|
|
);
|
|
let env = Env::start().await;
|
|
let (edge_cfg, caddy_cfg) = compile_pair(&env);
|
|
let ianitor = start_edge(&env, "ianitor", &edge_cfg);
|
|
let caddy = start_caddy(&env, "caddy", &caddy_bin, &caddy_cfg);
|
|
settle().await;
|
|
|
|
let report = run_corpus(&ianitor, &caddy, env.roots()).await;
|
|
println!("{}", report.render("Ianitor vs Caddy"));
|
|
let statuses: Vec<u16> = report.outcomes.iter().map(|o| o.ianitor.status).collect();
|
|
assert!(
|
|
!statuses.contains(&0),
|
|
"every case got an answer: {statuses:?}"
|
|
);
|
|
assert!(
|
|
report.mismatches().is_empty(),
|
|
"{}",
|
|
report.render("Ianitor vs Caddy")
|
|
);
|
|
|
|
// The corpus really exercises the interesting paths (and not, say, 404 everywhere).
|
|
for wanted in [101, 200, 204, 302, 308, 401, 403, 404, 500, 502, 503] {
|
|
assert!(
|
|
statuses.contains(&wanted),
|
|
"corpus covers status {wanted}: {statuses:?}"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// No device enrolled yet (or every one revoked). Caddy refuses a leaf list with no
|
|
/// certificate in it (QC, fix round 1: the whole config fails to load), so control writes
|
|
/// a placeholder no one holds the key to. Both engines start, serve the other hosts, and
|
|
/// let no device in.
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
|
async fn with_no_device_enrolled_both_engines_start_and_let_no_device_in() {
|
|
let Some(caddy_bin) = require_binary("caddy") else {
|
|
return;
|
|
};
|
|
let env = Env::start().await;
|
|
std::fs::write(
|
|
env.dir.join(&format!(
|
|
"certs/{}",
|
|
ianitor_core::compile::DEVICE_ALLOW_FILE
|
|
)),
|
|
ianitor_core::pki::no_device_placeholder(0).unwrap(),
|
|
)
|
|
.unwrap();
|
|
let (edge_cfg, caddy_cfg) = compile_pair(&env);
|
|
let ianitor = start_edge(&env, "ianitor", &edge_cfg);
|
|
let caddy = start_caddy(&env, "caddy", &caddy_bin, &caddy_cfg);
|
|
settle().await;
|
|
let report = run_cases(&ianitor, &caddy, env.roots(), |c| {
|
|
matches!(c.action, Action::HttpsDevice { .. }) || c.name == "plain GET"
|
|
})
|
|
.await;
|
|
println!("{}", report.render("Ianitor vs Caddy, empty allow list"));
|
|
assert!(
|
|
report.mismatches().is_empty(),
|
|
"{}",
|
|
report.render("Ianitor vs Caddy, empty allow list")
|
|
);
|
|
let get = |name: &str| {
|
|
report
|
|
.outcomes
|
|
.iter()
|
|
.find(|o| o.name == name)
|
|
.unwrap_or_else(|| panic!("no case {name}"))
|
|
};
|
|
assert_eq!(
|
|
get("plain GET").caddy.status,
|
|
200,
|
|
"Caddy serves the others"
|
|
);
|
|
let listed = get("Domi device certificate on the allow list");
|
|
assert!(
|
|
!(200..300).contains(&listed.ianitor.status),
|
|
"a device got in with an empty allow list: {}",
|
|
listed.ianitor.status
|
|
);
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
|
async fn a_deliberately_broken_compiler_is_caught() {
|
|
let Some(caddy_bin) = require_binary("caddy") else {
|
|
return;
|
|
};
|
|
let env = Env::start().await;
|
|
let (edge_cfg, caddy_cfg) = compile_pair(&env);
|
|
let (edge_cfg2, caddy_cfg2) = compile_pair(&env);
|
|
|
|
let ianitor = start_edge(&env, "ianitor", &edge_cfg);
|
|
let broken_caddy = start_caddy(&env, "caddy-broken", &caddy_bin, &break_caddy(&caddy_cfg));
|
|
let caddy = start_caddy(&env, "caddy", &caddy_bin, &caddy_cfg2);
|
|
let broken_ianitor = start_edge(&env, "ianitor-broken", &break_edge(&edge_cfg2));
|
|
settle().await;
|
|
|
|
let r1 = run_corpus(&ianitor, &broken_caddy, env.roots()).await;
|
|
println!(
|
|
"{}",
|
|
r1.render("Ianitor vs Caddy with response header rules dropped")
|
|
);
|
|
let diff1: Vec<&str> = r1.mismatches().iter().map(|o| o.name).collect();
|
|
assert!(!diff1.is_empty(), "broken Caddy compiler was not detected");
|
|
assert!(diff1.contains(&"plain GET"), "{diff1:?}");
|
|
|
|
let r2 = run_corpus(&broken_ianitor, &caddy, env.roots()).await;
|
|
println!(
|
|
"{}",
|
|
r2.render("Ianitor with request header rules dropped vs Caddy")
|
|
);
|
|
let diff2: Vec<&str> = r2.mismatches().iter().map(|o| o.name).collect();
|
|
assert!(!diff2.is_empty(), "broken edge compiler was not detected");
|
|
assert!(diff2.contains(&"request header overwritten"), "{diff2:?}");
|
|
assert!(
|
|
diff2.contains(&"secret header cannot be preset"),
|
|
"{diff2:?}"
|
|
);
|
|
}
|
|
}
|