summaryrefslogtreecommitdiffstats
path: root/tests/http.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 08:23:14 +0000
committeraur-build <aur-build@localhost>2026-11-18 08:23:14 +0000
commiteefbefed9cbea6b2edef65900fbe6cb6da0b48e4 (patch)
tree1249788a49812fc15b644687af7c1384f94ba236 /tests/http.rs
parenta6b652985f40cf022d6c522415c36fad13bc663d (diff)
downloadaur-build-eefbefed9cbea6b2edef65900fbe6cb6da0b48e4.tar.gz
aur-build-eefbefed9cbea6b2edef65900fbe6cb6da0b48e4.zip
http: surfaces driven by live state — staleness, downgrades, deps, rebuild (I6)
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.
Diffstat (limited to 'tests/http.rs')
-rw-r--r--tests/http.rs110
1 files changed, 4 insertions, 106 deletions
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<ureq::Response, ureq::Error>, 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<String> {
- 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("&amp;", "&")
- .replace("&quot;", "\"")
- .replace("&lt;", "<")
- .replace("&gt;", ">")
- .replace("&#39;", "'")
-}
-
#[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), &[