[edge] Fixes: skip 1xx, enforce auth timeout, resolve upstreams per connect, all Upgrade tokens, strip Remote-*
This commit is contained in:
@@ -40,14 +40,18 @@ pub struct MockAuthelia {
|
||||
}
|
||||
|
||||
fn h(req: &Recorded, name: &str) -> Option<String> {
|
||||
req.header(name).map(|v| String::from_utf8_lossy(v).into_owned())
|
||||
req.header(name)
|
||||
.map(|v| String::from_utf8_lossy(v).into_owned())
|
||||
}
|
||||
|
||||
fn text(status: u16, reason: &str, body: &str) -> Vec<u8> {
|
||||
response(
|
||||
status,
|
||||
reason,
|
||||
&[("Content-Type", "text/plain; charset=utf-8"), ("X-Sent-Content-Type", "text/plain; charset=utf-8")],
|
||||
&[
|
||||
("Content-Type", "text/plain; charset=utf-8"),
|
||||
("X-Sent-Content-Type", "text/plain; charset=utf-8"),
|
||||
],
|
||||
body.as_bytes(),
|
||||
)
|
||||
}
|
||||
@@ -64,9 +68,12 @@ fn decide(req: &Recorded) -> Reply {
|
||||
if req.method != "GET" || req.path != PATH {
|
||||
return Reply::Bytes(text(404, "Not Found", "404 page not found"));
|
||||
}
|
||||
let (Some(method), Some(proto), Some(host), Some(uri)) =
|
||||
(h(req, "x-forwarded-method"), h(req, "x-forwarded-proto"), h(req, "x-forwarded-host"), h(req, "x-forwarded-uri"))
|
||||
else {
|
||||
let (Some(method), Some(proto), Some(host), Some(uri)) = (
|
||||
h(req, "x-forwarded-method"),
|
||||
h(req, "x-forwarded-proto"),
|
||||
h(req, "x-forwarded-host"),
|
||||
h(req, "x-forwarded-uri"),
|
||||
) else {
|
||||
return Reply::Bytes(text(400, "Bad Request", "missing X-Forwarded headers"));
|
||||
};
|
||||
if let Some(auth) = h(req, "authorization") {
|
||||
@@ -76,13 +83,20 @@ fn decide(req: &Recorded) -> Reply {
|
||||
response(
|
||||
401,
|
||||
"Unauthorized",
|
||||
&[("WWW-Authenticate", "Basic realm=\"Authorization Required\""), ("X-Sent-Content-Type", "none")],
|
||||
&[
|
||||
("WWW-Authenticate", "Basic realm=\"Authorization Required\""),
|
||||
("X-Sent-Content-Type", "none"),
|
||||
],
|
||||
b"401 Unauthorized",
|
||||
)
|
||||
});
|
||||
}
|
||||
let cookie = h(req, "cookie").unwrap_or_default();
|
||||
let session = cookie.split(';').filter_map(|c| c.trim().strip_prefix("authelia_session=")).next().unwrap_or("");
|
||||
let session = cookie
|
||||
.split(';')
|
||||
.filter_map(|c| c.trim().strip_prefix("authelia_session="))
|
||||
.next()
|
||||
.unwrap_or("");
|
||||
Reply::Bytes(match session {
|
||||
"good" => allowed(true),
|
||||
"nameless" => allowed(false),
|
||||
@@ -126,7 +140,10 @@ fn decide(req: &Recorded) -> Reply {
|
||||
impl MockAuthelia {
|
||||
pub async fn start() -> MockAuthelia {
|
||||
let server = RawServer::start(decide).await;
|
||||
MockAuthelia { addr: server.addr, server }
|
||||
MockAuthelia {
|
||||
addr: server.addr,
|
||||
server,
|
||||
}
|
||||
}
|
||||
|
||||
/// The `[forward_auth] url` for the site file.
|
||||
|
||||
Reference in New Issue
Block a user