[tests] Diff: the differential suite runs on Windows too (Windows Caddy, drive paths), with two branch previews in the fixtures; edge leaves a websocket 101 as the upstream sent it, as Caddy does

This commit is contained in:
2026-11-17 13:59:18 +01:00
parent acf69a8ed2
commit 5e273241e4
6 changed files with 114 additions and 25 deletions
+1
View File
@@ -15,6 +15,7 @@ tokio.workspace = true
serde_json.workspace = true
rustls.workspace = true
rcgen.workspace = true
toml.workspace = true
[dev-dependencies]
ianitor-control = { path = "../../crates/control" }
+83 -5
View File
@@ -7,9 +7,12 @@
//! to Caddy (the `caddy` binary running the generated JSON); status, selected headers and
//! body are compared. Everything listens on 127.0.0.1.
//!
//! It runs on Linux and on Windows. On Windows the paths in both configs are Windows paths
//! (`F:/…/certs/x.crt`, Caddy's `{file.F:/…/creds/api_key}`), which is what Windows Server's
//! Caddy mode serves from (T4); Pingora runs in-process there only as the reference.
//!
//! Test code: panics are failures.
#![cfg(unix)]
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use std::collections::BTreeMap;
@@ -50,6 +53,46 @@ fn host(name: &str, body: &str) -> (String, String) {
)
}
/// The preview domain of the fixtures, and two branch previews in it (T4): one with a plain
/// branch name, one with a hostile one (mapped to a hashed label).
pub const PREVIEW_DOMAIN: &str = "pv.test";
pub const PREVIEW_PLAIN: &str = "fix-42--shop.pv.test";
/// The host name of the hostile-branch preview.
pub fn preview_hostile() -> &'static str {
static H: std::sync::OnceLock<String> = std::sync::OnceLock::new();
H.get_or_init(|| {
ianitor_core::preview::hostname("github:acme/Web.App", "feature/Ünï ../x", PREVIEW_DOMAIN)
.expect("a preview host name")
})
}
/// A preview host file exactly as control writes it (`ianitor_control::previews::spec`).
fn preview_host(project: &str, branch: &str, upstream: &str) -> (String, String) {
let name = ianitor_core::preview::hostname(project, branch, PREVIEW_DOMAIN).unwrap();
let mut t = toml::Table::new();
t.insert("hostname".into(), name.clone().into());
t.insert(
"upstreams".into(),
toml::Value::Array(vec![upstream.into()]),
);
t.insert("tls".into(), "domi".into());
let mut rule = toml::Table::new();
rule.insert("action".into(), "set".into());
rule.insert("name".into(), "X-Robots-Tag".into());
rule.insert("value".into(), "noindex, nofollow".into());
t.insert(
"response_headers".into(),
toml::Value::Array(vec![toml::Value::Table(rule)]),
);
let mut p = toml::Table::new();
p.insert("project".into(), project.into());
p.insert("branch".into(), branch.into());
p.insert("expires_at".into(), toml::Value::Integer(4_000_000_000));
t.insert("preview".into(), toml::Value::Table(p));
(format!("hosts/{name}.toml"), toml::to_string(&t).unwrap())
}
impl Env {
pub async fn start() -> Env {
let app = Echo::start("app").await;
@@ -117,7 +160,15 @@ impl Env {
"device.test",
&format!("upstreams = [\"{}\"]\ndevice_certs = true\n", app.url()),
),
preview_host("shop", "fix-42", &app.url()),
preview_host("github:acme/Web.App", "feature/Ünï ../x", &ws.url()),
];
assert!(
hosts
.iter()
.any(|(f, _)| f == &format!("hosts/{PREVIEW_PLAIN}.toml")),
"the plain preview fixture is {PREVIEW_PLAIN}"
);
let sources: Vec<SourceFile> = hosts
.iter()
.map(|(n, c)| SourceFile {
@@ -171,13 +222,16 @@ impl Env {
}
pub fn options(&self, engine: &str) -> CompileOptions {
// On Windows these are drive paths (F:\\…), written with forward slashes as control
// writes them (`ianitor_core::compile::windows_path`).
let w = |p: String| compile::windows_path(&p);
CompileOptions {
http_listen: local(free_port()),
https_listen: local(free_port()),
cert_dir: self.dir.str("certs"),
state_dir: self.dir.str(&format!("state-{engine}")),
access_log: self.dir.str(&format!("logs/{engine}-access.log")),
caddy_credentials_dir: self.dir.str("creds"),
cert_dir: w(self.dir.str("certs")),
state_dir: w(self.dir.str(&format!("state-{engine}"))),
access_log: w(self.dir.str(&format!("logs/{engine}-access.log"))),
caddy_credentials_dir: w(self.dir.str("creds")),
caddy_admin: None,
caddy_admin_socket: None,
trusted_proxies: Vec::new(),
@@ -445,6 +499,30 @@ pub fn corpus() -> Vec<Case> {
Req::get(p, "https://evil.test/x"),
),
http("HTTP redirects to HTTPS", Req::get(p, "/a/b?c=d")),
https(
"preview: plain branch",
PREVIEW_PLAIN,
Req::get(PREVIEW_PLAIN, "/a?b=c"),
),
http(
"preview: HTTP redirects to HTTPS",
Req::get(PREVIEW_PLAIN, "/x"),
),
https(
"preview: unknown branch of the preview domain",
PREVIEW_PLAIN,
Req::get("main--shop.pv.test", "/"),
),
https(
"preview: hostile branch",
preview_hostile(),
Req::get(preview_hostile(), "/"),
),
ws(
"preview: websocket on a hostile branch",
preview_hostile(),
vec![],
),
http("HTTP unknown host", Req::get("unknown.test", "/")),
http(
"HTTP unknown ACME token",
+2 -11
View File
@@ -7,17 +7,8 @@
#![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 {
// Runs on Linux and on Windows (with Windows paths; see the crate's docs).
mod both {
use ianitor_diff::{
Action, Env, break_caddy, break_edge, compile_pair, corpus, run_cases, run_corpus, settle,
start_caddy, start_edge,