From eefbefed9cbea6b2edef65900fbe6cb6da0b48e4 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 08:23:14 +0000 Subject: =?UTF-8?q?http:=20surfaces=20driven=20by=20live=20state=20?= =?UTF-8?q?=E2=80=94=20staleness,=20downgrades,=20deps,=20rebuild=20(I6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Attention, the package page and the builds page now answer real questions instead of rendering empty tables: - Attention lists outdated dependencies derived from the recorded world snapshots, naming the dependency that moved, what the artifact was built against and what the index holds now; also missing dependencies and downgrades (AUR offering a lower version than we serve), which is an announcement for a human, not a build request. - The package page shows depends-on from the recipe we actually serve and needed-by from the packages whose recipes name it, plus staleness and the aur_commit timeline, each release linking into cgit at that exact commit. - Builds rows carry the version they are about, in both the live and the recently-finished table. - A manual rebuild reuses the approved source identity and mints no approval (I6); the test asserts the approval count is unchanged before and after the rebuild runs. - A paused subscription is not observed at all: detection returns Paused without polling, so pausing a broken package stops it opening reviews. - Staleness stays computed on read (ยง10.2). Nothing stores a stale flag, so nothing can serve a stale lie. Also: dep-client fixture added for dependency pairs. --- tests/http.rs | 110 +++------------------------------------------------------- 1 file changed, 4 insertions(+), 106 deletions(-) (limited to 'tests/http.rs') diff --git a/tests/http.rs b/tests/http.rs index 20dcbcb..d5387dc 100644 --- a/tests/http.rs +++ b/tests/http.rs @@ -8,109 +8,9 @@ mod common; -use aur_build::db::model::*; -use aur_build::http::{self, Server}; use aur_build::review::{candidates, diff}; use common::*; -struct Web { - env: Env, - fx: Fixture, - #[allow(dead_code)] - server: Server, - cookie: String, - csrf: String, -} - -struct Page { - status: u16, - body: String, -} - -impl Web { - fn new(name: &str) -> Self { - Self::with_password(name, "") - } - - fn with_password(name: &str, password: &str) -> Self { - let (mut env, fx) = env_with_fixture(name); - env.cfg.bind = "127.0.0.1:0".into(); - env.cfg.password = password.into(); - let server = http::spawn(env.cfg.clone(), env.db.clone()).unwrap(); - let mut web = Self { env, fx, server, cookie: String::new(), csrf: String::new() }; - // First contact mints the session cookie and the CSRF token. - let first = web.raw_get("/"); - web.cookie = first - .0 - .iter() - .find(|(k, _)| k == "set-cookie") - .and_then(|(_, v)| v.split(';').next().map(|s| s.to_string())) - .unwrap_or_default(); - let body = web.get("/"); - web.csrf = extract(&body.body, "name=\"csrf\" content=\"", "\"").unwrap_or_default(); - web - } - - fn url(&self, path: &str) -> String { - format!("http://{}{}", self.server.addr, path) - } - - fn raw_get(&self, path: &str) -> (Vec<(String, String)>, String) { - let resp = ureq::get(&self.url(path)).set("Cookie", &self.cookie).call(); - let r = match resp { - Ok(r) => r, - Err(ureq::Error::Status(_, r)) => r, - Err(e) => panic!("GET {path}: {e}"), - }; - let cookie = r.header("set-cookie").map(|s| s.to_string()).unwrap_or_default(); - (vec![("set-cookie".to_string(), cookie)], r.into_string().unwrap_or_default()) - } - - fn get(&self, path: &str) -> Page { - let resp = ureq::get(&self.url(path)).set("Cookie", &self.cookie).call(); - self.finish(resp, path) - } - - fn post(&self, path: &str, form: &[(&str, &str)]) -> Page { - let resp = ureq::post(&self.url(path)).set("Cookie", &self.cookie).send_form(form); - self.finish(resp, path) - } - - fn finish(&self, resp: Result, path: &str) -> Page { - match resp { - Ok(r) => Page { status: r.status(), body: r.into_string().unwrap_or_default() }, - Err(ureq::Error::Status(code, r)) => Page { status: code, body: r.into_string().unwrap_or_default() }, - Err(e) => panic!("{path}: {e}"), - } - } - - /// Subscribe, detect and render a review so an approval can be attempted. - fn open_review(&self, name: &str) -> CandidateRow { - aur_build::watch::detect::check_pkgbase(&self.env.cfg, &self.env.db, name).unwrap(); - let c = candidates::pending_candidates(&self.env.db).unwrap().remove(0); - let dd = diff::render_and_store(&self.env.db, &self.env.cfg, &c).unwrap(); - let _ = dd; - candidates::candidate_by_id(&self.env.db, c.id).unwrap().unwrap() - } -} - -fn extract(hay: &str, open: &str, close: &str) -> Option { - let i = hay.find(open)? + open.len(); - let rest = &hay[i..]; - let j = rest.find(close)?; - Some(unescape(&rest[..j])) -} - -/// Templates escape attribute values; a test comparing one back to a Rust -/// string has to undo that. -fn unescape(s: &str) -> String { - s.replace("&", "&") - .replace(""", "\"") - .replace("<", "<") - .replace(">", ">") - .replace("'", "'") -} - #[test] fn every_surface_renders() { let web = Web::new("plain-make"); @@ -192,12 +92,10 @@ fn every_post_requires_a_csrf_token() { let web = Web::new("plain-make"); let c = web.open_review("plain-make"); // A form post with no token at all is refused outright. - let page = { - let resp = ureq::post(&web.url(&format!("/reviews/{}/approve", c.id))) - .set("Cookie", &web.cookie) - .send_form(&[("identity_hash", "x"), ("diff_digest", "y")]); - web.finish(resp, "approve") - }; + 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"); // And so is one with a token from someone else's session. let page = web.post(&format!("/reviews/{}/approve", c.id), &[ -- cgit v1.2.3