[edge] Tests first: junk ids cannot flush the password throttle, a lower revocation epoch is refused (red)
This commit is contained in:
@@ -437,23 +437,59 @@ mod unix {
|
||||
.await;
|
||||
assert_eq!(e.get(HOST, "/", Some(&keep_cookie)).await.status, 302);
|
||||
|
||||
// The epoch never goes back: a lower one is refused and the old state kept, so a
|
||||
// control that lost its records cannot revive stopped links.
|
||||
let fresh = mint(
|
||||
&key(),
|
||||
HOST,
|
||||
&LinkSpec {
|
||||
id: ShareId([14; 16]),
|
||||
epoch: 1,
|
||||
expires_at: now() + 3600,
|
||||
prefix: "/",
|
||||
password: None,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let fresh_cookie = share_cookie(&e.get(HOST, &format!("/?share={fresh}"), None).await);
|
||||
assert_eq!(e.get(HOST, "/", Some(&fresh_cookie)).await.status, 200);
|
||||
e.edge.write_revocations(0, &[]);
|
||||
let r = e
|
||||
.edge
|
||||
.admin("POST", "/v1/share-revocations/reload", None)
|
||||
.await;
|
||||
assert_eq!(r.status, 422, "{}", r.text);
|
||||
assert!(r.text.contains("epoch"), "{}", r.text);
|
||||
assert_eq!(e.get(HOST, "/", Some(&keep_cookie)).await.status, 302, "still stopped");
|
||||
assert_eq!(e.get(HOST, "/", Some(&fresh_cookie)).await.status, 200);
|
||||
|
||||
// Without the admin call, edge notices a changed file within 5 s.
|
||||
e.edge.write_revocations(1, &[ShareId([14; 16]).to_hex()]);
|
||||
tokio::time::sleep(Duration::from_secs(6)).await;
|
||||
assert_eq!(e.get(HOST, "/", Some(&fresh_cookie)).await.status, 302);
|
||||
// ...and a lower epoch written behind its back is refused there too.
|
||||
e.edge.write_revocations(0, &[]);
|
||||
tokio::time::sleep(Duration::from_secs(6)).await;
|
||||
assert_eq!(e.get(HOST, "/", Some(&keep_cookie)).await.status, 200);
|
||||
assert_eq!(e.get(HOST, "/", Some(&fresh_cookie)).await.status, 302);
|
||||
assert!(e.edge.stderr().contains("epoch"), "the refusal is logged");
|
||||
|
||||
// A broken file keeps the last good state; a missing one stops all share access.
|
||||
e.edge.write_revocations(1, &[]);
|
||||
e.edge
|
||||
.admin("POST", "/v1/share-revocations/reload", None)
|
||||
.await;
|
||||
assert_eq!(e.get(HOST, "/", Some(&fresh_cookie)).await.status, 200);
|
||||
std::fs::write(e.edge.revocations_path(), "{ broken").unwrap();
|
||||
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);
|
||||
assert_eq!(e.get(HOST, "/", Some(&fresh_cookie)).await.status, 200);
|
||||
std::fs::remove_file(e.edge.revocations_path()).unwrap();
|
||||
e.edge
|
||||
.admin("POST", "/v1/share-revocations/reload", None)
|
||||
.await;
|
||||
assert_eq!(e.get(HOST, "/", Some(&keep_cookie)).await.status, 302);
|
||||
assert_eq!(e.get(HOST, "/", Some(&fresh_cookie)).await.status, 302);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user