[edge] Tests first: QC repros for 1xx, auth timeout, name resolution, Upgrade tokens, Remote-* stripping (red)

This commit is contained in:
2026-11-07 15:36:00 +01:00
parent fd4b4a7775
commit d42c178a13
6 changed files with 414 additions and 134 deletions
+93
View File
@@ -255,3 +255,96 @@ async fn unreachable_auth_server_fails_closed() {
assert_eq!(r.status, 502);
assert!(echo.proxied().is_empty());
}
/// QC B2a, B2b, m3: misbehaving auth servers. Edge fails closed and never crashes or hangs.
#[tokio::test(flavor = "multi_thread")]
async fn misbehaving_auth_answers_fail_closed() {
let authelia = MockAuthelia::start().await;
let echo = Echo::start("app").await;
let site = site(&authelia.url());
let edge = start(EdgeSpec {
site: &site,
hosts: vec![host_file(
"auth.test",
&format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", echo.url()),
)],
..Default::default()
});
let go = |session: &'static str| {
let roots = edge.roots();
let addr = edge.https;
async move {
let cookie = format!("authelia_session={session}");
client::https(addr, "auth.test", roots, &Req::get("auth.test", "/").header("cookie", &cookie)).await
}
};
// 100 Continue before the real answer is skipped, like any HTTP client does.
let r = go("continue-ok").await.expect("edge answers after a 1xx from the auth server");
assert_eq!(r.status, 200);
assert_eq!(echo.proxied().len(), 1);
assert_eq!(echo.proxied()[0].header("remote-user"), Some(b"alice".as_slice()));
echo.clear();
// 101 is a final answer but not an allow: denied with 502.
assert_eq!(go("switch").await.unwrap().status, 502);
// Oversized or truncated auth answers: 502, never forwarded.
assert_eq!(go("big-ok").await.unwrap().status, 502);
assert_eq!(go("big-deny").await.unwrap().status, 502);
assert_eq!(go("truncated-ok").await.unwrap().status, 502);
assert!(echo.proxied().is_empty(), "{:?}", echo.proxied());
// An auth server that never answers: 502 once the 10 s auth timeout passes.
let t = std::time::Instant::now();
let r = go("hang").await.expect("edge answers a hanging auth server");
assert_eq!(r.status, 502);
assert!(t.elapsed() < std::time::Duration::from_secs(14), "took {:?}", t.elapsed());
assert!(echo.proxied().is_empty());
// Still serving afterwards.
assert_eq!(go("good").await.unwrap().status, 200);
}
/// QC m5: client-sent Remote-* headers never reach a forward-auth upstream, whatever
/// copy_headers says.
#[tokio::test(flavor = "multi_thread")]
async fn remote_headers_are_stripped_even_with_a_custom_copy_list() {
let authelia = MockAuthelia::start().await;
let echo = Echo::start("app").await;
for copy in ["[]", "[\"Remote-User\"]"] {
echo.clear();
let site = format!("[forward_auth]\nurl = \"{}\"\ncopy_headers = {copy}\n", authelia.url());
let edge = start(EdgeSpec {
site: &site,
hosts: vec![host_file(
"auth.test",
&format!("upstreams = [\"{}\"]\nauth = \"forward-auth\"\n", echo.url()),
)],
..Default::default()
});
let r = client::https(
edge.https,
"auth.test",
edge.roots(),
&Req::get("auth.test", "/")
.header("cookie", "authelia_session=good")
.header("remote-user", "mallory")
.header("remote-groups", "root")
.header("remote-email", "m@evil.test")
.header("remote-name", "Mallory"),
)
.await
.unwrap();
assert_eq!(r.status, 200);
let up = &echo.proxied()[0];
let user = up.header("remote-user");
if copy == "[]" {
assert_eq!(user, None, "copy_headers = []");
} else {
assert_eq!(user, Some(b"alice".as_slice()));
}
for h in ["remote-groups", "remote-email", "remote-name"] {
assert_eq!(up.header(h), None, "{h} with copy_headers = {copy}");
}
}
}