[edge] Reload and share links: in-process config swap with self-reverting trials, admin socket with health and certificate status, share-link cookies, visitor pages and throttle
This commit is contained in:
@@ -107,11 +107,7 @@ mod unix {
|
||||
}
|
||||
|
||||
async fn post_password(&self, token: &str, password: &str) -> Resp {
|
||||
let body = format!(
|
||||
"t={}&password={}",
|
||||
urlencode(token),
|
||||
urlencode(password)
|
||||
);
|
||||
let body = format!("t={}&password={}", urlencode(token), urlencode(password));
|
||||
let req = Req::new("POST", HOST, "/.well-known/ianitor/share")
|
||||
.header("content-type", "application/x-www-form-urlencoded")
|
||||
.body(body.as_bytes());
|
||||
@@ -159,7 +155,10 @@ mod unix {
|
||||
);
|
||||
assert!(r.header("content-type").unwrap().starts_with("text/html"));
|
||||
assert!(!r.text().contains("<script"), "no JavaScript");
|
||||
assert!(!r.text().contains("http://") && !r.text().contains("https://"), "no external requests");
|
||||
assert!(
|
||||
!r.text().contains("http://") && !r.text().contains("https://"),
|
||||
"no external requests"
|
||||
);
|
||||
assert!(r.body.len() < 8 * 1024);
|
||||
}
|
||||
|
||||
@@ -180,19 +179,36 @@ mod unix {
|
||||
.find(|c| c.starts_with("__Secure-ianitor-share="))
|
||||
.unwrap()
|
||||
.to_owned();
|
||||
for attr in ["Path=/albums", "HttpOnly", "Secure", "SameSite=Lax", "Max-Age="] {
|
||||
for attr in [
|
||||
"Path=/albums",
|
||||
"HttpOnly",
|
||||
"Secure",
|
||||
"SameSite=Lax",
|
||||
"Max-Age=",
|
||||
] {
|
||||
assert!(set.contains(attr), "{attr} missing in {set}");
|
||||
}
|
||||
assert!(!set.contains(&t), "the cookie is not the link token");
|
||||
assert!(e.upstream_paths().is_empty(), "the token request never reached the upstream");
|
||||
assert!(
|
||||
e.upstream_paths().is_empty(),
|
||||
"the token request never reached the upstream"
|
||||
);
|
||||
let auth_calls = e.auth.requests().len();
|
||||
|
||||
let cookie = share_cookie(&r);
|
||||
let r = e
|
||||
.get(HOST, "/albums/summer?x=1&y=2", Some(&format!("{cookie}; other=1")))
|
||||
.get(
|
||||
HOST,
|
||||
"/albums/summer?x=1&y=2",
|
||||
Some(&format!("{cookie}; other=1")),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, 200, "{}", r.text());
|
||||
assert_eq!(e.auth.requests().len(), auth_calls, "no forward-auth for a share visitor");
|
||||
assert_eq!(
|
||||
e.auth.requests().len(),
|
||||
auth_calls,
|
||||
"no forward-auth for a share visitor"
|
||||
);
|
||||
let seen = e.echo.proxied();
|
||||
let last = seen.last().unwrap();
|
||||
assert_eq!(last.path, "/albums/summer");
|
||||
@@ -200,20 +216,32 @@ mod unix {
|
||||
.header("cookie")
|
||||
.map(|c| String::from_utf8_lossy(c).into_owned())
|
||||
.unwrap_or_default();
|
||||
assert!(!cookie_sent.contains("ianitor-share"), "share cookie stripped: {cookie_sent}");
|
||||
assert!(cookie_sent.contains("other=1"), "other cookies kept: {cookie_sent}");
|
||||
assert!(
|
||||
!cookie_sent.contains("ianitor-share"),
|
||||
"share cookie stripped: {cookie_sent}"
|
||||
);
|
||||
assert!(
|
||||
cookie_sent.contains("other=1"),
|
||||
"other cookies kept: {cookie_sent}"
|
||||
);
|
||||
assert!(last.header("referer").is_none());
|
||||
|
||||
// The prefix itself and deeper paths are covered.
|
||||
assert_eq!(e.get(HOST, "/albums", Some(&cookie)).await.status, 200);
|
||||
assert_eq!(e.get(HOST, "/albums/a/b/c.jpg", Some(&cookie)).await.status, 200);
|
||||
assert_eq!(
|
||||
e.get(HOST, "/albums/a/b/c.jpg", Some(&cookie)).await.status,
|
||||
200
|
||||
);
|
||||
|
||||
// Neither the token nor the cookie appears in any log.
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
let logs = e.edge.all_output();
|
||||
assert!(!logs.contains(&t[5..40]), "token in logs");
|
||||
assert!(!logs.contains(&cookie[30..60]), "cookie in logs");
|
||||
assert!(!e.edge.access_log().contains("share="), "query in access log");
|
||||
assert!(
|
||||
!e.edge.access_log().contains("share="),
|
||||
"query in access log"
|
||||
);
|
||||
for r in e.echo.requests() {
|
||||
for (_, v) in &r.headers {
|
||||
assert!(!String::from_utf8_lossy(v).contains(&t[5..40]));
|
||||
@@ -309,7 +337,11 @@ mod unix {
|
||||
// The cookie of a password link cannot be turned into a link that skips the password.
|
||||
let v = cookie.split_once('=').unwrap().1.to_owned();
|
||||
let r = e
|
||||
.get(HOST, &format!("/docs?share={}", v.replacen("iss1.", "ish1.", 1)), None)
|
||||
.get(
|
||||
HOST,
|
||||
&format!("/docs?share={}", v.replacen("iss1.", "ish1.", 1)),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_ne!(r.status, 303);
|
||||
|
||||
@@ -384,16 +416,25 @@ mod unix {
|
||||
assert_eq!(e.get(HOST, "/", Some(&cookie)).await.status, 200);
|
||||
|
||||
e.edge.write_revocations(0, &[ShareId([12; 16]).to_hex()]);
|
||||
let r = e.edge.admin("POST", "/v1/share-revocations/reload", None).await;
|
||||
let r = e
|
||||
.edge
|
||||
.admin("POST", "/v1/share-revocations/reload", None)
|
||||
.await;
|
||||
assert_eq!(r.status, 200, "{}", r.text);
|
||||
assert_eq!(e.get(HOST, "/", Some(&cookie)).await.status, 302, "back to sign-in");
|
||||
assert_eq!(
|
||||
e.get(HOST, "/", Some(&cookie)).await.status,
|
||||
302,
|
||||
"back to sign-in"
|
||||
);
|
||||
let r = e.get(HOST, &format!("/?share={t}"), None).await;
|
||||
assert_visitor_page(&r, 403, "This link no longer works");
|
||||
assert_eq!(e.get(HOST, "/", Some(&keep_cookie)).await.status, 200);
|
||||
|
||||
// Stop all: a new epoch ends every older link.
|
||||
e.edge.write_revocations(1, &[]);
|
||||
e.edge.admin("POST", "/v1/share-revocations/reload", None).await;
|
||||
e.edge
|
||||
.admin("POST", "/v1/share-revocations/reload", None)
|
||||
.await;
|
||||
assert_eq!(e.get(HOST, "/", Some(&keep_cookie)).await.status, 302);
|
||||
|
||||
// Without the admin call, edge notices a changed file within 5 s.
|
||||
@@ -403,11 +444,16 @@ mod unix {
|
||||
|
||||
// A broken file keeps the last good state; a missing one stops all share access.
|
||||
std::fs::write(e.edge.revocations_path(), "{ broken").unwrap();
|
||||
let r = e.edge.admin("POST", "/v1/share-revocations/reload", None).await;
|
||||
let r = e
|
||||
.edge
|
||||
.admin("POST", "/v1/share-revocations/reload", None)
|
||||
.await;
|
||||
assert_eq!(r.status, 422);
|
||||
assert_eq!(e.get(HOST, "/", Some(&keep_cookie)).await.status, 200);
|
||||
std::fs::remove_file(e.edge.revocations_path()).unwrap();
|
||||
e.edge.admin("POST", "/v1/share-revocations/reload", None).await;
|
||||
e.edge
|
||||
.admin("POST", "/v1/share-revocations/reload", None)
|
||||
.await;
|
||||
assert_eq!(e.get(HOST, "/", Some(&keep_cookie)).await.status, 302);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user