diff options
| author | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
| commit | 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch) | |
| tree | 7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /tests/http.rs | |
| parent | 9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff) | |
| download | aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.tar.gz aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.zip | |
rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off
rustfmt.toml fixes the shape the tree is written in (120 columns, small
items kept on one line) and one canonical pass makes it the truth.
[lints.clippy] names the idiom lints worth enforcing and leaves out the
two that would add doc-comment boilerplate rather than remove it. The
tree pays them off here: write!/writeln! instead of push_str(&format!()),
let-else instead of match-on-Option, borrows where a thread entry point
only reads what it owns, no `&self` on a Copy state and no `self` nobody
reads.
ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and
value are now emitted by the same call instead of three.
Diffstat (limited to 'tests/http.rs')
| -rw-r--r-- | tests/http.rs | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/tests/http.rs b/tests/http.rs index 23c8ba5..209096f 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -77,16 +77,12 @@ fn risk_signals_are_shown_inline() { fn every_post_requires_a_csrf_token() { let web = Web::new("plain-make"); let c = web.open_review("plain-make"); - let page = web.post_bare( + let page = web.post_bare(&format!("/reviews/{}/approve", c.id), &[("identity_hash", "x"), ("diff_digest", "y")]); + assert_eq!(page.status, 403, "a POST without CSRF must be refused"); + let page = web.post( &format!("/reviews/{}/approve", c.id), - &[("identity_hash", "x"), ("diff_digest", "y")], + &[("csrf", "not-the-token"), ("identity_hash", &c.identity_hash), ("diff_digest", &c.diff_digest)], ); - assert_eq!(page.status, 403, "a POST without CSRF must be refused"); - let page = web.post(&format!("/reviews/{}/approve", c.id), &[ - ("csrf", "not-the-token"), - ("identity_hash", &c.identity_hash), - ("diff_digest", &c.diff_digest), - ]); assert_eq!(page.status, 403, "a forged CSRF token must be refused"); assert_eq!( web.env.query_i64("SELECT count(*) FROM approval", &[]), @@ -147,16 +143,11 @@ fn a_stale_approval_is_a_409_that_renders_the_current_diff() { fn reject_requires_a_note() { let web = Web::new("plain-make"); let c = web.open_review("plain-make"); - let res = web.post( - &format!("/reviews/{}/reject", c.id), - &[("csrf", &web.csrf), ("note", "")], - ); + let res = web.post(&format!("/reviews/{}/reject", c.id), &[("csrf", &web.csrf), ("note", "")]); assert_eq!(res.status, 400, "an empty note must be refused"); assert_eq!(web.env.query_i64("SELECT count(*) FROM approval", &[]), Some(0)); - let res = web.post( - &format!("/reviews/{}/reject", c.id), - &[("csrf", &web.csrf), ("note", "upstream dropped our license")], - ); + let res = web + .post(&format!("/reviews/{}/reject", c.id), &[("csrf", &web.csrf), ("note", "upstream dropped our license")]); assert_eq!(res.status, 200); assert_eq!(web.env.query_i64("SELECT count(*) FROM approval WHERE decision='rejected'", &[]), Some(1)); } @@ -168,14 +159,20 @@ fn bulk_approve_refuses_high_risk_without_individual_confirmation() { assert_eq!(c.risk_level, aur_build::review::risk::level::HIGH, "fixture should be high risk"); let id = c.id.to_string(); let res = web.post("/reviews/bulk", &[("csrf", &web.csrf), ("decision", "approve"), ("ids", &id)]); - assert!(res.body.contains("refused"), "bulk approve accepted a high-risk item: {}", &res.body[..300.min(res.body.len())]); + assert!( + res.body.contains("refused"), + "bulk approve accepted a high-risk item: {}", + &res.body[..300.min(res.body.len())] + ); assert_eq!(web.env.query_i64("SELECT count(*) FROM approval", &[]), Some(0)); - let res = web.post( - "/reviews/bulk", - &[("csrf", &web.csrf), ("decision", "approve"), ("ids", &id), ("confirm", &id)], + let res = + web.post("/reviews/bulk", &[("csrf", &web.csrf), ("decision", "approve"), ("ids", &id), ("confirm", &id)]); + assert!( + !res.body.contains("refused"), + "confirmed item was still refused: {}", + &res.body[..300.min(res.body.len())] ); - assert!(!res.body.contains("refused"), "confirmed item was still refused: {}", &res.body[..300.min(res.body.len())]); assert_eq!(web.env.query_i64("SELECT count(*) FROM approval", &[]), Some(1)); } @@ -200,7 +197,13 @@ fn a_forged_auth_cookie_is_not_a_session() { let web = Web::with_password("plain-make", "s3cret"); for path in ["/", "/reviews", "/audit", "/settings", "/builds", "/packages"] { let res = web.raw_request("GET", path, &[("Cookie", "auth=1".into())], None); - assert_eq!(res.status, 303, "{path} let a forged cookie through ({}): {}", res.status, &res.body[..120.min(res.body.len())]); + assert_eq!( + res.status, + 303, + "{path} let a forged cookie through ({}): {}", + res.status, + &res.body[..120.min(res.body.len())] + ); assert_eq!(res.header("location"), Some("/login"), "{path} did not redirect to the login page"); } let res = web.raw_request("POST", "/logout", &[("Cookie", "auth=1".into())], Some("")); @@ -221,11 +224,24 @@ fn login_rotates_the_session_and_logout_ends_it() { assert_ne!(session, anon, "login promoted the anonymous session instead of rotating it"); assert_eq!(web.raw_request("GET", "/reviews", &[("Cookie", session.clone())], None).status, 200); if !anon.is_empty() { - assert_eq!(web.raw_request("GET", "/reviews", &[("Cookie", anon)], None).status, 303, "the pre-login sid still worked"); + assert_eq!( + web.raw_request("GET", "/reviews", &[("Cookie", anon)], None).status, + 303, + "the pre-login sid still worked" + ); } - let out = web.raw_request("POST", "/logout", &[("Cookie", session.clone()), ("Content-Type", "application/x-www-form-urlencoded".into())], Some(&format!("csrf={}", web.csrf))); + let out = web.raw_request( + "POST", + "/logout", + &[("Cookie", session.clone()), ("Content-Type", "application/x-www-form-urlencoded".into())], + Some(&format!("csrf={}", web.csrf)), + ); assert_eq!(out.status, 303, "logout did not redirect: {}", out.status); - assert_eq!(web.raw_request("GET", "/reviews", &[("Cookie", session)], None).status, 303, "the logged-out sid still worked"); + assert_eq!( + web.raw_request("GET", "/reviews", &[("Cookie", session)], None).status, + 303, + "the logged-out sid still worked" + ); } #[test] |
