90 lines
3.4 KiB
Rust
90 lines
3.4 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`.
|
|
|
|
#![cfg(unix)]
|
|
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
|
|
use ianitor_diff::{
|
|
Env, break_caddy, break_edge, compile_pair, corpus, 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:?}"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[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:?}"
|
|
);
|
|
}
|