forge
Explore
Log in

Don't you dare go Hollow

E2e tests share run_admin, boot_admin, cookie and stream helpers from common instead of per-file copies

Browse files at this commit

128691aa9732cd2b8a89e9d08746b404b9f781b0Ahmet Kaan GümüşParent: 76d78e3
All checks have passed
Show checks
  • refactor
    • e2e tests share run_admin, boot_admin, cookie and stream helpers from common instead of per-file copies
    • docs drop references to removed files
Show full message
♻️ refactor: e2e tests share run_admin, boot_admin, cookie and stream helpers from common instead of per-file copies; docs drop references to removed files
crates/forge-e2e/tests/e2e/account_mail_e2e.rsmodified+2 -21
@@ -2,37 +2,18 @@
2 //! tests, this starts the real `forge` binary. The log transport writes each mail to2 //! tests, this starts the real `forge` binary. The log transport writes each mail to
3 //! `<data_dir>/mail-log/`, which is where the tests read the reset link from.3 //! `<data_dir>/mail-log/`, which is where the tests read the reset link from.
4 4
5-use crate::common::{Http, Resp, launch_with, pick_ports};5+use crate::common::{Http, Resp, cookie_named, input_value, launch_with, pick_ports};
6 use std::fs;6 use std::fs;
7 use std::path::{Path, PathBuf};7 use std::path::{Path, PathBuf};
8 use std::time::Duration;8 use std::time::Duration;
9 9
10 use forge_core::Store;10 use forge_core::Store;
11 use forge_core::password::hash_password;11 use forge_core::password::hash_password;
12-use reqwest::header::SET_COOKIE;
13 12
14 const LOG_TRANSPORT: &str = "\n[mail]\ntransport = \"log\"\n";13 const LOG_TRANSPORT: &str = "\n[mail]\ntransport = \"log\"\n";
15 const OLD_PW: &str = "tahinli-old-password-1";14 const OLD_PW: &str = "tahinli-old-password-1";
16 const NEW_PW: &str = "tahinli-new-password-2";15 const NEW_PW: &str = "tahinli-new-password-2";
17 16
18-/// The `name=value` pair of the Set-Cookie header whose name starts with `prefix`.
19-fn cookie_named(resp: &Resp, prefix: &str) -> Option<String> {
20- resp.headers
21- .get_all(SET_COOKIE)
22- .iter()
23- .filter_map(|v| v.to_str().ok())
24- .find(|raw| raw.starts_with(prefix))
25- .map(|raw| raw.split(';').next().unwrap().to_owned())
26-}
27-
28-/// The value of a hidden `<input name=... value=...>` field.
29-fn input_value(html: &str, name: &str) -> String {
30- let marker = format!("name=\"{name}\" value=\"");
31- let start = html.find(&marker).unwrap_or_else(|| panic!("{name} field")) + marker.len();
32- let end = html[start..].find('"').unwrap() + start;
33- html[start..end].to_owned()
34-}
35-
36 /// Creates tahinli with a verified address. Bob has an address that is not verified. Runs before17 /// Creates tahinli with a verified address. Bob has an address that is not verified. Runs before
37 /// the server starts, like the other e2e tests.18 /// the server starts, like the other e2e tests.
38 async fn seed(dir: &Path) {19 async fn seed(dir: &Path) {
@@ -169,7 +150,7 @@ async fn reset_link_sets_a_new_password_once() {
169 assert!(page.body.contains("Set a new password"));150 assert!(page.body.contains("Set a new password"));
170 151
171 let cookie = cookie_named(&page, "__Host-forge_precsrf").expect("precsrf cookie");152 let cookie = cookie_named(&page, "__Host-forge_precsrf").expect("precsrf cookie");
172- let precsrf = cookie.split_once('=').unwrap().1.to_owned();153+ let precsrf = input_value(&page.body, "precsrf");
173 let form = [154 let form = [
174 ("precsrf", precsrf.as_str()),155 ("precsrf", precsrf.as_str()),
175 ("password", NEW_PW),156 ("password", NEW_PW),
crates/forge-e2e/tests/e2e/advisories_e2e.rsmodified+1 -17
@@ -9,7 +9,7 @@
9 //! - a reader without Write gets a 404 on the page.9 //! - a reader without Write gets a 404 on the page.
10 10
11 use crate::common::{11 use crate::common::{
12- Http, Resp, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path,12+ Http, Resp, Server, input_value, launch_with, login, pick_ports, run_admin, tool_on_path,
13 write_config_with,13 write_config_with,
14 };14 };
15 use std::fs;15 use std::fs;
@@ -121,22 +121,6 @@ async fn boot() -> Booted {
121 }121 }
122 }122 }
123 123
124-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
125- let out = Command::new(bin())
126- .arg("--config")
127- .arg(config)
128- .args(["admin", "create-user", username])
129- .args(extra)
130- .env("FORGE_PASSWORD", password)
131- .output()
132- .expect("run admin create-user");
133- assert!(
134- out.status.success(),
135- "create-user {username} failed:\n{}",
136- String::from_utf8_lossy(&out.stderr)
137- );
138-}
139-
140 async fn create_token(http: &Http, session: &str) -> String {124 async fn create_token(http: &Http, session: &str) -> String {
141 let page = http.get_cookie("/settings/keys", session).await;125 let page = http.get_cookie("/settings/keys", session).await;
142 assert_eq!(page.status, 200, "GET /settings/keys");126 assert_eq!(page.status, 200, "GET /settings/keys");
crates/forge-e2e/tests/e2e/branch_protection_e2e.rsmodified+2 -15
@@ -3,7 +3,7 @@
3 //! while the server runs. Helpers mirror `git_e2e.rs`.3 //! while the server runs. Helpers mirror `git_e2e.rs`.
4 4
5 use crate::common::{5 use crate::common::{
6- Http, Ports, Server, bin, describe, input_value, launch, login, pick_ports, relaunch,6+ Http, Ports, Server, describe, input_value, launch, login, pick_ports, relaunch, run_admin,
7 tool_on_path, write_config,7 tool_on_path, write_config,
8 };8 };
9 use std::fs;9 use std::fs;
@@ -14,18 +14,6 @@ use forge_core::Store;
14 14
15 const TAHINLI_PW: &str = "tahinli-password-123";15 const TAHINLI_PW: &str = "tahinli-password-123";
16 16
17-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
18- let out = Command::new(bin())
19- .arg("--config")
20- .arg(config)
21- .args(["admin", "create-user", username])
22- .args(extra)
23- .env("FORGE_PASSWORD", password)
24- .output()
25- .expect("run admin create-user");
26- ok(&out, &format!("create-user {username}"));
27-}
28-
29 fn ok(out: &Output, what: &str) {17 fn ok(out: &Output, what: &str) {
30 assert!(out.status.success(), "{what} failed:\n{}", describe(out));18 assert!(out.status.success(), "{what} failed:\n{}", describe(out));
31 }19 }
@@ -233,10 +221,9 @@ async fn branch_protection_end_to_end() {
233 };221 };
234 let mut server = start_server(&ctx).await;222 let mut server = start_server(&ctx).await;
235 223
236- // Seed main, feature/x and release/1 with two commits on main.
237 let url = format!(224 let url = format!(
238 "http://tahinli:{token}@127.0.0.1:{}/tahinli/bp.git",225 "http://tahinli:{token}@127.0.0.1:{}/tahinli/bp.git",
239- ctx.http.base.rsplit(':').next().expect("port")226+ ctx.ports.http
240 );227 );
241 let work = ctx.dir.join("work");228 let work = ctx.dir.join("work");
242 ok(&git(&ctx.dir, &["clone", &url, path_str(&work)]), "clone");229 ok(&git(&ctx.dir, &["clone", &url, path_str(&work)]), "clone");
crates/forge-e2e/tests/e2e/browse_e2e.rsmodified+9 -88
@@ -5,7 +5,7 @@
5 //! Cookies are handled by hand, as in `git_e2e.rs`: the session cookie is `__Host-forge_session`5 //! Cookies are handled by hand, as in `git_e2e.rs`: the session cookie is `__Host-forge_session`
6 //! with `Secure`, so a cookie jar would not send it over plain http.6 //! with `Secure`, so a cookie jar would not send it over plain http.
7 7
8-use crate::common::{bin, describe, input_value, launch, pick_ports, tool_on_path, write_config};8+use crate::common::{boot_admin, describe, input_value, tool_on_path};
9 use std::fs;9 use std::fs;
10 use std::path::Path;10 use std::path::Path;
11 use std::process::{Command, Output};11 use std::process::{Command, Output};
@@ -147,18 +147,6 @@ fn assert_latest_bar(body: &str, what: &str, subject: &str, oid: &str, count: &s
147 );147 );
148 }148 }
149 149
150-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
151- let out = Command::new(bin())
152- .arg("--config")
153- .arg(config)
154- .args(["admin", "create-user", username])
155- .args(extra)
156- .env("FORGE_PASSWORD", password)
157- .output()
158- .expect("run admin create-user");
159- ok(&out, &format!("create-user {username}"));
160-}
161-
162 fn ok(out: &Output, what: &str) {150 fn ok(out: &Output, what: &str) {
163 assert!(out.status.success(), "{what} failed:\n{}", describe(out));151 assert!(out.status.success(), "{what} failed:\n{}", describe(out));
164 }152 }
@@ -200,7 +188,6 @@ fn write_fixtures(work: &Path) {
200 fs::write(work.join("src/main.rs"), "fn main() {}\n").expect("write main.rs");188 fs::write(work.join("src/main.rs"), "fn main() {}\n").expect("write main.rs");
201 fs::write(work.join("img.png"), PNG).expect("write img.png");189 fs::write(work.join("img.png"), PNG).expect("write img.png");
202 fs::write(work.join("evil.html"), "<script>alert(1)</script>\n").expect("write evil.html");190 fs::write(work.join("evil.html"), "<script>alert(1)</script>\n").expect("write evil.html");
203- // A Git LFS pointer whose object is not stored, so the blob page says so.
204 fs::write(191 fs::write(
205 work.join("weights.bin"),192 work.join("weights.bin"),
206 "version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n",193 "version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n",
@@ -334,30 +321,17 @@ async fn browse_end_to_end() {
334 return;321 return;
335 }322 }
336 323
337- // Keep the path short, as in git_e2e.rs.324+ let (root, _server, ports) = boot_admin("fbrw", TAHINLI_PW).await;
338- let root = tempfile::Builder::new()
339- .prefix("fbrw")
340- .tempdir_in("/tmp")
341- .expect("temp dir");
342 let dir = root.path().to_path_buf();325 let dir = root.path().to_path_buf();
343-
344- let ports = pick_ports();
345- let config = write_config(&dir, ports);
346-
347- run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
348-
349- let (_server, ports) = launch(&dir, ports).await;
350 let http = Http::new(ports.http);326 let http = Http::new(ports.http);
351 let raw = Http::new(ports.content);327 let raw = Http::new(ports.content);
352 let raw_base = raw.base.clone();328 let raw_base = raw.base.clone();
353 329
354- // Setup: tahinli logs in, makes a token and creates one public and one private repo.
355 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;330 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
356 let token = create_token(&http, &tahinli, "browse-token").await;331 let token = create_token(&http, &tahinli, "browse-token").await;
357 create_repo(&http, &tahinli, "pub", "public").await;332 create_repo(&http, &tahinli, "pub", "public").await;
358 create_repo(&http, &tahinli, "priv", "private").await;333 create_repo(&http, &tahinli, "priv", "private").await;
359 334
360- // Push the same fixtures to both repos over HTTPS with the token.
361 let pub_url = format!(335 let pub_url = format!(
362 "http://tahinli:{token}@127.0.0.1:{}/tahinli/pub.git",336 "http://tahinli:{token}@127.0.0.1:{}/tahinli/pub.git",
363 ports.http337 ports.http
@@ -369,7 +343,6 @@ async fn browse_end_to_end() {
369 let pub_main = push_fixtures(&dir, &pub_url, &dir.join("pub-work"));343 let pub_main = push_fixtures(&dir, &pub_url, &dir.join("pub-work"));
370 push_fixtures(&dir, &priv_url, &dir.join("priv-work"));344 push_fixtures(&dir, &priv_url, &dir.join("priv-work"));
371 345
372- // A branch named `media` in the public repo, with its own README.md.
373 let pub_work = dir.join("pub-work");346 let pub_work = dir.join("pub-work");
374 ok(347 ok(
375 &git(348 &git(
@@ -382,7 +355,6 @@ async fn browse_end_to_end() {
382 commit_all(&pub_work, "media branch");355 commit_all(&pub_work, "media branch");
383 ok(&git(&pub_work, &["push", "origin", "media"]), "push media");356 ok(&git(&pub_work, &["push", "origin", "media"]), "push media");
384 357
385- // App origin, anonymous, public repo.
386 let home = http.get("/tahinli/pub", None).await;358 let home = http.get("/tahinli/pub", None).await;
387 assert_eq!(home.status, 200, "anonymous home of public repo");359 assert_eq!(home.status, 200, "anonymous home of public repo");
388 let csp = home360 let csp = home
@@ -420,7 +392,6 @@ async fn browse_end_to_end() {
420 "README image must point at the raw origin: {image_srcs:?}"392 "README image must point at the raw origin: {image_srcs:?}"
421 );393 );
422 394
423- // Latest commit bar: the root has one commit on main, so its subject, short sha and count.
424 assert_latest_bar(395 assert_latest_bar(
425 &home_body,396 &home_body,
426 "repo home",397 "repo home",
@@ -494,7 +465,6 @@ async fn browse_end_to_end() {
494 feature_tree.body().contains("feature.txt"),465 feature_tree.body().contains("feature.txt"),
495 "feature/x tree must list feature.txt"466 "feature/x tree must list feature.txt"
496 );467 );
497- // The feature commit is the newest on feature/x, on top of the two-commit history.
498 assert_latest_bar(468 assert_latest_bar(
499 &feature_tree.body(),469 &feature_tree.body(),
500 "tree of feature/x",470 "tree of feature/x",
@@ -510,7 +480,6 @@ async fn browse_end_to_end() {
510 "archive must start with gzip magic bytes"480 "archive must start with gzip magic bytes"
511 );481 );
512 482
513- // App origin, private repo: anonymous gets 404 everywhere.
514 for path in [483 for path in [
515 "/tahinli/priv",484 "/tahinli/priv",
516 "/tahinli/priv/tree/main/src",485 "/tahinli/priv/tree/main/src",
@@ -520,7 +489,6 @@ async fn browse_end_to_end() {
520 assert_eq!(res.status, 404, "anonymous {path} on private repo");489 assert_eq!(res.status, 404, "anonymous {path} on private repo");
521 }490 }
522 491
523- // Logged in, the image blob page carries a signed raw URL.
524 let priv_img = http492 let priv_img = http
525 .get("/tahinli/priv/blob/main/img.png", Some(&tahinli))493 .get("/tahinli/priv/blob/main/img.png", Some(&tahinli))
526 .await;494 .await;
@@ -534,11 +502,9 @@ async fn browse_end_to_end() {
534 "signed raw URL shape: {priv_img_src}"502 "signed raw URL shape: {priv_img_src}"
535 );503 );
536 504
537- // Raw origin: the media route 404s when the repo does not link the object.
538 let media = raw.get("/tahinli/pub/-/media/main/weights.bin", None).await;505 let media = raw.get("/tahinli/pub/-/media/main/weights.bin", None).await;
539 assert_eq!(media.status, 404, "media of an unstored LFS object");506 assert_eq!(media.status, 404, "media of an unstored LFS object");
540 507
541- // Raw origin: a branch named `media` is an ordinary raw path, not the media route.
542 let media_branch = raw.get("/tahinli/pub/media/README.md", None).await;508 let media_branch = raw.get("/tahinli/pub/media/README.md", None).await;
543 assert_eq!(509 assert_eq!(
544 media_branch.status, 200,510 media_branch.status, 200,
@@ -546,11 +512,9 @@ async fn browse_end_to_end() {
546 );512 );
547 assert_eq!(media_branch.body(), "# On a media branch\n");513 assert_eq!(media_branch.body(), "# On a media branch\n");
548 514
549- // Raw origin: `-` is never a ref name, so it is a 404 and not resolved.
550 let dash = raw.get("/tahinli/pub/-/README.md", None).await;515 let dash = raw.get("/tahinli/pub/-/README.md", None).await;
551 assert_eq!(dash.status, 404, "raw path with a `-` ref");516 assert_eq!(dash.status, 404, "raw path with a `-` ref");
552 517
553- // Raw origin: public file.
554 let main_rs = raw.get("/tahinli/pub/main/src/main.rs", None).await;518 let main_rs = raw.get("/tahinli/pub/main/src/main.rs", None).await;
555 assert_eq!(main_rs.status, 200, "raw public main.rs");519 assert_eq!(main_rs.status, 200, "raw public main.rs");
556 assert_eq!(520 assert_eq!(
@@ -570,7 +534,6 @@ async fn browse_end_to_end() {
570 );534 );
571 assert_no_cookie(&main_rs, "raw public main.rs");535 assert_no_cookie(&main_rs, "raw public main.rs");
572 536
573- // Raw origin: HTML is served as a download, never inline.
574 let evil = raw.get("/tahinli/pub/main/evil.html", None).await;537 let evil = raw.get("/tahinli/pub/main/evil.html", None).await;
575 assert_eq!(evil.status, 200, "raw evil.html");538 assert_eq!(evil.status, 200, "raw evil.html");
576 assert!(539 assert!(
@@ -580,13 +543,11 @@ async fn browse_end_to_end() {
580 );543 );
581 assert_no_cookie(&evil, "raw evil.html");544 assert_no_cookie(&evil, "raw evil.html");
582 545
583- // Raw origin: images keep their image type.
584 let img = raw.get("/tahinli/pub/main/img.png", None).await;546 let img = raw.get("/tahinli/pub/main/img.png", None).await;
585 assert_eq!(img.status, 200, "raw img.png");547 assert_eq!(img.status, 200, "raw img.png");
586 assert_eq!(img.header(CONTENT_TYPE).as_deref(), Some("image/png"));548 assert_eq!(img.header(CONTENT_TYPE).as_deref(), Some("image/png"));
587 assert_no_cookie(&img, "raw img.png");549 assert_no_cookie(&img, "raw img.png");
588 550
589- // Raw origin: private repo needs a valid token.
590 let priv_no_token = raw.get("/tahinli/priv/main/img.png", None).await;551 let priv_no_token = raw.get("/tahinli/priv/main/img.png", None).await;
591 assert_eq!(priv_no_token.status, 404, "private raw without token");552 assert_eq!(priv_no_token.status, 404, "private raw without token");
592 assert_no_cookie(&priv_no_token, "raw private without token");553 assert_no_cookie(&priv_no_token, "raw private without token");
@@ -598,8 +559,6 @@ async fn browse_end_to_end() {
598 assert_eq!(priv_ok.status, 200, "private raw with the scraped token");559 assert_eq!(priv_ok.status, 200, "private raw with the scraped token");
599 assert_no_cookie(&priv_ok, "raw private with token");560 assert_no_cookie(&priv_ok, "raw private with token");
600 561
601- // Tampering with the signature (its first character) must fail. The first base64 character
602- // carries six significant bits, so flipping it always changes the signature.
603 let (file_part, query) = priv_path.split_once("?token=").expect("token query");562 let (file_part, query) = priv_path.split_once("?token=").expect("token query");
604 let (expires, sig) = query.split_once('.').expect("token shape");563 let (expires, sig) = query.split_once('.').expect("token shape");
605 let flipped = if sig.starts_with('A') { 'B' } else { 'A' };564 let flipped = if sig.starts_with('A') { 'B' } else { 'A' };
@@ -607,10 +566,12 @@ async fn browse_end_to_end() {
607 let tampered = raw566 let tampered = raw
608 .get(&format!("{file_part}?token={expires}.{tampered_sig}"), None)567 .get(&format!("{file_part}?token={expires}.{tampered_sig}"), None)
609 .await;568 .await;
610- assert_eq!(tampered.status, 404, "tampered token must be rejected");569+ assert_eq!(
570+ tampered.status, 404,
571+ "tampered token must be rejected: the first base64 char carries six bits, so the flip always changes the signature"
572+ );
611 assert_no_cookie(&tampered, "raw tampered token");573 assert_no_cookie(&tampered, "raw tampered token");
612 574
613- // Raw origin has no app routes.
614 let login_page = raw.get("/login", None).await;575 let login_page = raw.get("/login", None).await;
615 assert_eq!(576 assert_eq!(
616 login_page.status, 404,577 login_page.status, 404,
@@ -626,7 +587,6 @@ async fn open_stream(http: &Http, path: &str, cookie: Option<&str>) -> reqwest::
626 req = req.header(COOKIE, cookie);587 req = req.header(COOKIE, cookie);
627 }588 }
628 let mut res = req.send().await.expect("stream request");589 let mut res = req.send().await.expect("stream request");
629- // A stream that opens sends its `retry` field first. It is not an event, so it is read here.
630 if res.status().is_success() {590 if res.status().is_success() {
631 let retry = next_chunk(&mut res).await.expect("the retry field");591 let retry = next_chunk(&mut res).await.expect("the retry field");
632 assert!(retry.contains("retry: 1000"), "{retry}");592 assert!(retry.contains("retry: 1000"), "{retry}");
@@ -650,15 +610,8 @@ async fn code_view_stream_follows_pushes() {
650 return;610 return;
651 }611 }
652 612
653- let root = tempfile::Builder::new()613+ let (root, _server, ports) = boot_admin("fliv", TAHINLI_PW).await;
654- .prefix("fliv")
655- .tempdir_in("/tmp")
656- .expect("temp dir");
657 let dir = root.path().to_path_buf();614 let dir = root.path().to_path_buf();
658- let ports = pick_ports();
659- let config = write_config(&dir, ports);
660- run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
661- let (_server, ports) = launch(&dir, ports).await;
662 let http = Http::new(ports.http);615 let http = Http::new(ports.http);
663 616
664 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;617 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
@@ -677,7 +630,6 @@ async fn code_view_stream_follows_pushes() {
677 push_fixtures(&dir, &priv_url, &dir.join("priv-live"));630 push_fixtures(&dir, &priv_url, &dir.join("priv-live"));
678 let work = dir.join("pub-live");631 let work = dir.join("pub-live");
679 632
680- // The branch page follows its branch. A commit page does not, since a commit never moves.
681 let branch_page = http.get("/tahinli/pub/tree/main/", None).await;633 let branch_page = http.get("/tahinli/pub/tree/main/", None).await;
682 assert_eq!(branch_page.status, 200);634 assert_eq!(branch_page.status, 200);
683 assert!(635 assert!(
@@ -701,7 +653,6 @@ async fn code_view_stream_follows_pushes() {
701 "a commit page does not follow a branch"653 "a commit page does not follow a branch"
702 );654 );
703 655
704- // Anyone can follow a public branch.
705 let mut stream = open_stream(&http, "/tahinli/pub/events?ref_name=main", None).await;656 let mut stream = open_stream(&http, "/tahinli/pub/events?ref_name=main", None).await;
706 assert_eq!(stream.status().as_u16(), 200);657 assert_eq!(stream.status().as_u16(), 200);
707 assert_eq!(658 assert_eq!(
@@ -709,7 +660,6 @@ async fn code_view_stream_follows_pushes() {
709 "text/event-stream"660 "text/event-stream"
710 );661 );
711 662
712- // A push to another branch sends nothing: main did not move and no ref was created.
713 ok(663 ok(
714 &git(&work, &["checkout", "-q", "feature/x"]),664 &git(&work, &["checkout", "-q", "feature/x"]),
715 "checkout feature/x",665 "checkout feature/x",
@@ -722,7 +672,6 @@ async fn code_view_stream_follows_pushes() {
722 );672 );
723 assert!(next_chunk(&mut stream).await.is_none(), "other branch sent");673 assert!(next_chunk(&mut stream).await.is_none(), "other branch sent");
724 674
725- // A push to main sends one `changed` event.
726 ok(&git(&work, &["checkout", "-q", "main"]), "checkout main");675 ok(&git(&work, &["checkout", "-q", "main"]), "checkout main");
727 fs::write(work.join("README.md"), "# Live\n\nChanged by a push.\n").expect("write README");676 fs::write(work.join("README.md"), "# Live\n\nChanged by a push.\n").expect("write README");
728 commit_all(&work, "change the README");677 commit_all(&work, "change the README");
@@ -730,7 +679,6 @@ async fn code_view_stream_follows_pushes() {
730 let event = next_chunk(&mut stream).await.expect("event for main");679 let event = next_chunk(&mut stream).await.expect("event for main");
731 assert!(event.contains("event: changed"), "{event}");680 assert!(event.contains("event: changed"), "{event}");
732 681
733- // Creating and deleting a branch changes the branch list, so the page follows it too.
734 ok(682 ok(
735 &git(&work, &["checkout", "-q", "-b", "topic"]),683 &git(&work, &["checkout", "-q", "-b", "topic"]),
736 "create topic",684 "create topic",
@@ -752,7 +700,6 @@ async fn code_view_stream_follows_pushes() {
752 .expect("event for a deleted branch");700 .expect("event for a deleted branch");
753 assert!(deleted.contains("event: changed"), "{deleted}");701 assert!(deleted.contains("event: changed"), "{deleted}");
754 702
755- // A private repo streams only to a viewer who can read it.
756 let private = "/tahinli/priv/events?ref_name=main";703 let private = "/tahinli/priv/events?ref_name=main";
757 let anonymous = open_stream(&http, private, None).await;704 let anonymous = open_stream(&http, private, None).await;
758 assert_eq!(705 assert_eq!(
@@ -789,22 +736,13 @@ async fn issue_streams_follow_writes() {
789 return;736 return;
790 }737 }
791 738
792- let root = tempfile::Builder::new()739+ let (_root, _server, ports) = boot_admin("filive", TAHINLI_PW).await;
793- .prefix("filive")
794- .tempdir_in("/tmp")
795- .expect("temp dir");
796- let dir = root.path().to_path_buf();
797- let ports = pick_ports();
798- let config = write_config(&dir, ports);
799- run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
800- let (_server, ports) = launch(&dir, ports).await;
801 let http = Http::new(ports.http);740 let http = Http::new(ports.http);
802 741
803 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;742 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
804 create_repo(&http, &tahinli, "pub", "public").await;743 create_repo(&http, &tahinli, "pub", "public").await;
805 create_repo(&http, &tahinli, "priv", "private").await;744 create_repo(&http, &tahinli, "priv", "private").await;
806 745
807- // The list follows the repo's issues. Anyone can follow a public repo.
808 let list_page = http.get("/tahinli/pub/issues", None).await;746 let list_page = http.get("/tahinli/pub/issues", None).await;
809 assert!(747 assert!(
810 list_page748 list_page
@@ -815,7 +753,6 @@ async fn issue_streams_follow_writes() {
815 let mut list = open_stream(&http, "/tahinli/pub/issues/live", None).await;753 let mut list = open_stream(&http, "/tahinli/pub/issues/live", None).await;
816 assert_eq!(list.status().as_u16(), 200);754 assert_eq!(list.status().as_u16(), 200);
817 755
818- // Creating an issue wakes the list.
819 let new_page = http.get("/tahinli/pub/issues/new", Some(&tahinli)).await;756 let new_page = http.get("/tahinli/pub/issues/new", Some(&tahinli)).await;
820 let csrf = input_value(&new_page.body(), "csrf");757 let csrf = input_value(&new_page.body(), "csrf");
821 post_redirect(758 post_redirect(
@@ -827,7 +764,6 @@ async fn issue_streams_follow_writes() {
827 .await;764 .await;
828 assert_changed(&mut list, "creating an issue").await;765 assert_changed(&mut list, "creating an issue").await;
829 766
830- // The issue page follows the issue, and the list stays subscribed to the repo's issues.
831 let mut issue = open_stream(&http, "/tahinli/pub/issues/1/live", None).await;767 let mut issue = open_stream(&http, "/tahinli/pub/issues/1/live", None).await;
832 assert_eq!(issue.status().as_u16(), 200);768 assert_eq!(issue.status().as_u16(), 200);
833 let view = http.get("/tahinli/pub/issues/1", Some(&tahinli)).await;769 let view = http.get("/tahinli/pub/issues/1", Some(&tahinli)).await;
@@ -900,7 +836,6 @@ async fn issue_streams_follow_writes() {
900 assert_changed(&mut issue, what).await;836 assert_changed(&mut issue, what).await;
901 }837 }
902 838
903- // A private repo streams only to a viewer who can read it.
904 let anonymous = open_stream(&http, "/tahinli/priv/issues/live", None).await;839 let anonymous = open_stream(&http, "/tahinli/priv/issues/live", None).await;
905 assert_eq!(840 assert_eq!(
906 anonymous.status().as_u16(),841 anonymous.status().as_u16(),
@@ -924,15 +859,8 @@ async fn browsing_pages_stream_their_changes() {
924 return;859 return;
925 }860 }
926 861
927- let root = tempfile::Builder::new()862+ let (root, _server, ports) = boot_admin("flive", TAHINLI_PW).await;
928- .prefix("flive")
929- .tempdir_in("/tmp")
930- .expect("temp dir");
931 let dir = root.path().to_path_buf();863 let dir = root.path().to_path_buf();
932- let ports = pick_ports();
933- let config = write_config(&dir, ports);
934- run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
935- let (_server, ports) = launch(&dir, ports).await;
936 let http = Http::new(ports.http);864 let http = Http::new(ports.http);
937 865
938 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;866 let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
@@ -944,8 +872,6 @@ async fn browsing_pages_stream_their_changes() {
944 );872 );
945 let pushed = push_fixtures(&dir, &pub_url, &dir.join("pub-pages"));873 let pushed = push_fixtures(&dir, &pub_url, &dir.join("pub-pages"));
946 874
947- // The inbox needs a session. Without one it refuses, and no URL names another user's inbox:
948- // the viewer always comes from the session.
949 for path in [875 for path in [
950 "/notifications/events",876 "/notifications/events",
951 "/notifications/events?all=1&user=tahinli",877 "/notifications/events?all=1&user=tahinli",
@@ -956,7 +882,6 @@ async fn browsing_pages_stream_their_changes() {
956 let inbox = open_stream(&http, "/notifications/events", Some(tahinli.as_str())).await;882 let inbox = open_stream(&http, "/notifications/events", Some(tahinli.as_str())).await;
957 assert_eq!(inbox.status().as_u16(), 200, "inbox stream for its owner");883 assert_eq!(inbox.status().as_u16(), 200, "inbox stream for its owner");
958 884
959- // The header of a public repo streams to anyone. A star moves its count for every viewer.
960 let mut header = open_stream(&http, "/tahinli/pub/events", None).await;885 let mut header = open_stream(&http, "/tahinli/pub/events", None).await;
961 assert_eq!(header.status().as_u16(), 200);886 assert_eq!(header.status().as_u16(), 200);
962 let page = http.get("/tahinli/pub", Some(&tahinli)).await;887 let page = http.get("/tahinli/pub", Some(&tahinli)).await;
@@ -973,16 +898,13 @@ async fn browsing_pages_stream_their_changes() {
973 "the header shows the star"898 "the header shows the star"
974 );899 );
975 900
976- // A second push moves main.
977 let work = dir.join("pub-pages");901 let work = dir.join("pub-pages");
978- // push_fixtures leaves the clone on feature/x, so the new commit must go on main.
979 ok(&git(&work, &["checkout", "-q", "main"]), "checkout main");902 ok(&git(&work, &["checkout", "-q", "main"]), "checkout main");
980 fs::write(work.join("PUSH.txt"), "pushed again\n").expect("write PUSH.txt");903 fs::write(work.join("PUSH.txt"), "pushed again\n").expect("write PUSH.txt");
981 commit_all(&work, "a second push");904 commit_all(&work, "a second push");
982 ok(&git(&work, &["push", "-q", "origin", "main"]), "push main");905 ok(&git(&work, &["push", "-q", "origin", "main"]), "push main");
983 assert_ne!(pushed, head_sha(&work), "the second push moved main");906 assert_ne!(pushed, head_sha(&work), "the second push moved main");
984 907
985- // The explore listing streams to anyone, and a new public repo changes it.
986 let mut explore = open_stream(&http, "/explore/events", None).await;908 let mut explore = open_stream(&http, "/explore/events", None).await;
987 assert_eq!(explore.status().as_u16(), 200);909 assert_eq!(explore.status().as_u16(), 200);
988 create_repo(&http, &tahinli, "lib", "public").await;910 create_repo(&http, &tahinli, "lib", "public").await;
@@ -991,7 +913,6 @@ async fn browsing_pages_stream_their_changes() {
991 .expect("event for a new public repo");913 .expect("event for a new public repo");
992 assert!(listed.contains("event: changed"), "{listed}");914 assert!(listed.contains("event: changed"), "{listed}");
993 915
994- // The profile streams to anyone, and an unknown name is not found.
995 let mut profile = open_stream(&http, "/users/tahinli/events", None).await;916 let mut profile = open_stream(&http, "/users/tahinli/events", None).await;
996 assert_eq!(profile.status().as_u16(), 200);917 assert_eq!(profile.status().as_u16(), 200);
997 create_repo(&http, &tahinli, "tools", "public").await;918 create_repo(&http, &tahinli, "tools", "public").await;
crates/forge-e2e/tests/e2e/ci_e2e.rsmodified+2 -22
@@ -11,7 +11,7 @@
11 //! - a live log: `log.txt` streams while a job runs and ends when the job finishes.11 //! - a live log: `log.txt` streams while a job runs and ends when the job finishes.
12 12
13 use crate::common::{13 use crate::common::{
14- FAST_CLAIMS, Http, Server, bin, input_value, launch_with, login, pick_ports, write_config,14+ FAST_CLAIMS, Http, Server, input_value, launch_with, login, pick_ports, run_admin, write_config,
15 };15 };
16 use forge_ci::proto::{JobAssignment, Outcome, RegisterRequest};16 use forge_ci::proto::{JobAssignment, Outcome, RegisterRequest};
17 use forge_runner::client::ForgeClient;17 use forge_runner::client::ForgeClient;
@@ -21,7 +21,7 @@ use forge_runner::runner::{RunOptions, Runner};
21 use std::collections::BTreeMap;21 use std::collections::BTreeMap;
22 use std::fs;22 use std::fs;
23 use std::path::{Path, PathBuf};23 use std::path::{Path, PathBuf};
24-use std::process::{Command, Output};24+use std::process::Command;
25 use std::sync::Arc;25 use std::sync::Arc;
26 use std::time::{Duration, Instant};26 use std::time::{Duration, Instant};
27 use tokio_util::sync::CancellationToken;27 use tokio_util::sync::CancellationToken;
@@ -103,26 +103,6 @@ fn first_text(body: &str, selector: &str) -> String {
103 .to_owned()103 .to_owned()
104 }104 }
105 105
106-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
107- let out = Command::new(bin())
108- .arg("--config")
109- .arg(config)
110- .args(["admin", "create-user", username])
111- .args(extra)
112- .env("FORGE_PASSWORD", password)
113- .output()
114- .expect("run admin create-user");
115- ok(&out, &format!("create-user {username}"));
116-}
117-
118-fn ok(out: &Output, what: &str) {
119- assert!(
120- out.status.success(),
121- "{what} failed:\n{}",
122- String::from_utf8_lossy(&out.stderr)
123- );
124-}
125-
126 /// Runs git in `cwd` with `env` applied on top of the inherited environment. Returns stdout.106 /// Runs git in `cwd` with `env` applied on top of the inherited environment. Returns stdout.
127 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {107 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {
128 let mut cmd = Command::new("git");108 let mut cmd = Command::new("git");
crates/forge-e2e/tests/e2e/common/http.rsmodified+5 -0
@@ -153,6 +153,11 @@ pub fn cookie_named(resp: &Resp, suffix: &str) -> Option<String> {
153 })153 })
154 }154 }
155 155
156+pub fn with_cookie(session: &str, res: &Resp, notice: &str) -> String {
157+ let cookie = cookie_named(res, notice).expect("notice cookie");
158+ format!("{session}; {cookie}")
159+}
160+
156 /// Signs in as `username` through the `/login` form and returns the session cookie.161 /// Signs in as `username` through the `/login` form and returns the session cookie.
157 pub async fn login(http: &Http, username: &str, password: &str) -> String {162 pub async fn login(http: &Http, username: &str, password: &str) -> String {
158 let page = http.get("/login", None).await;163 let page = http.get("/login", None).await;
crates/forge-e2e/tests/e2e/common/mod.rsmodified+144 -5
@@ -1,14 +1,11 @@
1 //! Helpers shared by the forge-web e2e tests. `main.rs` declares this module once, and each test1 //! Helpers shared by the forge-web e2e tests. `main.rs` declares this module once, and each test
2-//! module imports what it needs from `crate::common`. Items a given test does not use are allowed2+//! module imports what it needs from `crate::common`.
3-//! to be dead code.
4 //!3 //!
5 //! The server is started with `launch`, which waits for the three listeners (HTTP, user content4 //! The server is started with `launch`, which waits for the three listeners (HTTP, user content
6 //! and SSH) with backoff. A connection that is refused just means "not yet". If the child exits5 //! and SSH) with backoff. A connection that is refused just means "not yet". If the child exits
7 //! first, the panic carries its captured log. A port picked with `pick_ports` is only free until6 //! first, the panic carries its captured log. A port picked with `pick_ports` is only free until
8 //! the server binds it, so `launch` retries on fresh ports when the server reports a bind conflict.7 //! the server binds it, so `launch` retries on fresh ports when the server reports a bind conflict.
9 8
10-#![allow(dead_code)]
11-
12 use std::fs;9 use std::fs;
13 use std::net::TcpStream;10 use std::net::TcpStream;
14 use std::path::{Path, PathBuf};11 use std::path::{Path, PathBuf};
@@ -16,9 +13,11 @@ use std::process::{Child, Command, ExitStatus, Output, Stdio};
16 use std::sync::OnceLock;13 use std::sync::OnceLock;
17 use std::time::{Duration, Instant};14 use std::time::{Duration, Instant};
18 15
16+use tempfile::TempDir;
17+
19 mod http;18 mod http;
20 19
21-pub use http::{Http, Resp, cookie_named, login};20+pub use http::{Http, Resp, cookie_named, login, with_cookie};
22 21
23 /// The forge binary the tests start. `env!("CARGO_BIN_EXE_forge")` would only work in the package22 /// The forge binary the tests start. `env!("CARGO_BIN_EXE_forge")` would only work in the package
24 /// that owns the binary, and these tests live in `forge-e2e`, which does not depend on forge-web.23 /// that owns the binary, and these tests live in `forge-e2e`, which does not depend on forge-web.
@@ -97,6 +96,13 @@ pub fn input_value(body: &str, name: &str) -> String {
97 .to_owned()96 .to_owned()
98 }97 }
99 98
99+pub fn temp_dir(prefix: &str) -> tempfile::TempDir {
100+ tempfile::Builder::new()
101+ .prefix(prefix)
102+ .tempdir_in("/tmp")
103+ .expect("temp dir")
104+}
105+
100 /// A port the kernel handed out for a moment. It is free only until something binds it.106 /// A port the kernel handed out for a moment. It is free only until something binds it.
101 pub fn free_port() -> u16 {107 pub fn free_port() -> u16 {
102 std::net::TcpListener::bind("127.0.0.1:0")108 std::net::TcpListener::bind("127.0.0.1:0")
@@ -167,6 +173,98 @@ pub fn write_config_with(dir: &Path, ports: Ports, extra: &str) -> PathBuf {
167 /// before it answers 204, and the production default is 25 s, so the test server answers at once.173 /// before it answers 204, and the production default is 25 s, so the test server answers at once.
168 pub const FAST_CLAIMS: &str = "[ci]\nclaim_wait_ms = 50\n";174 pub const FAST_CLAIMS: &str = "[ci]\nclaim_wait_ms = 50\n";
169 175
176+pub fn git(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output {
177+ let mut cmd = Command::new("git");
178+ cmd.current_dir(cwd)
179+ .args(["-c", "credential.helper="])
180+ .args(args)
181+ .env("GIT_TERMINAL_PROMPT", "0");
182+ for (key, value) in env {
183+ cmd.env(key, value);
184+ }
185+ cmd.output().expect("run git")
186+}
187+
188+/// Creates an access token through `/settings/tokens` and returns the token shown once.
189+pub async fn create_token(http: &Http, session: &str, name: &str) -> String {
190+ let page = http.get_cookie("/settings/keys", session).await;
191+ assert_eq!(page.status, 200, "GET /settings/keys");
192+ let csrf = input_value(&page.body, "csrf");
193+ let res = http
194+ .post_form(
195+ "/settings/tokens",
196+ &[("csrf", &csrf), ("name", name), ("expires", "30")],
197+ Some(session),
198+ )
199+ .await;
200+ assert_eq!(res.status, 200, "create token: {}", res.body);
201+ let doc = scraper::Html::parse_document(&res.body);
202+ let selector = scraper::Selector::parse("pre.code code").expect("selector");
203+ let token: String = doc
204+ .select(&selector)
205+ .next()
206+ .expect("token shown after creation")
207+ .text()
208+ .collect();
209+ let token = token.trim().to_owned();
210+ assert!(token.starts_with("forge_"), "unexpected token shape");
211+ token
212+}
213+
214+/// Creates a repo through `/new`.
215+pub async fn create_repo(http: &Http, session: &str, name: &str, visibility: &str) {
216+ let page = http.get_cookie("/new", session).await;
217+ assert_eq!(page.status, 200, "GET /new");
218+ let csrf = input_value(&page.body, "csrf");
219+ let res = http
220+ .post_form(
221+ "/new",
222+ &[
223+ ("csrf", &csrf),
224+ ("name", name),
225+ ("description", ""),
226+ ("visibility", visibility),
227+ ("default_branch", "main"),
228+ ],
229+ Some(session),
230+ )
231+ .await;
232+ assert_eq!(res.status, 303, "create repo {name}: {}", res.body);
233+ assert_eq!(
234+ res.location().as_deref(),
235+ Some(format!("/tahinli/{name}").as_str())
236+ );
237+}
238+
239+pub const PW: &str = "tahinli-password-123";
240+
241+pub fn admin(config: &Path, args: &[&str]) {
242+ let out = Command::new(bin())
243+ .arg("--config")
244+ .arg(config)
245+ .arg("admin")
246+ .args(args)
247+ .env("FORGE_PASSWORD", PW)
248+ .output()
249+ .expect("run admin command");
250+ assert!(
251+ out.status.success(),
252+ "admin {args:?} failed:\n{}",
253+ describe(&out)
254+ );
255+}
256+
257+pub fn init_bare(data_dir: &Path, repo_id: &str) {
258+ let path = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");
259+ fs::create_dir_all(path.parent().expect("parent")).expect("create repo parent");
260+ let out = Command::new("git")
261+ .args(["init", "--bare", "--quiet", "--initial-branch=main"])
262+ .arg(&path)
263+ .output()
264+ .expect("run git init");
265+ assert!(out.status.success(), "git init --bare: {}", describe(&out));
266+}
267+
170 pub fn describe(out: &Output) -> String {268 pub fn describe(out: &Output) -> String {
171 format!(269 format!(
172 "status: {}\nstdout: {}\nstderr: {}",270 "status: {}\nstdout: {}\nstderr: {}",
@@ -176,6 +274,47 @@ pub fn describe(out: &Output) -> String {
176 )274 )
177 }275 }
178 276
277+/// Waits for the next event of a stream, which must be `changed`.
278+pub async fn next_changed(res: &mut reqwest::Response, what: &str) {
279+ let chunk = tokio::time::timeout(Duration::from_secs(5), res.chunk())
280+ .await
281+ .unwrap_or_else(|_| panic!("no event after {what}"))
282+ .expect("stream chunk")
283+ .expect("stream still open");
284+ let text = String::from_utf8_lossy(&chunk);
285+ assert!(text.contains("event: changed"), "{what}: {text}");
286+}
287+
288+pub fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
289+ let out = Command::new(bin())
290+ .arg("--config")
291+ .arg(config)
292+ .args(["admin", "create-user", username])
293+ .args(extra)
294+ .env("FORGE_PASSWORD", password)
295+ .output()
296+ .expect("run admin create-user");
297+ assert!(
298+ out.status.success(),
299+ "create-user {username} failed:\n{}",
300+ describe(&out)
301+ );
302+}
303+
304+/// A fresh server with `tahinli` as its only user, an admin. The temp dir is under `/tmp` so the
305+/// socket paths stay under the 108-byte unix limit. Returns the dir, the server and its ports.
306+pub async fn boot_admin(prefix: &str, password: &str) -> (TempDir, Server, Ports) {
307+ let root = tempfile::Builder::new()
308+ .prefix(prefix)
309+ .tempdir_in("/tmp")
310+ .expect("temp dir");
311+ let ports = pick_ports();
312+ let config = write_config(root.path(), ports);
313+ run_admin(&config, "tahinli", &["--admin"], password);
314+ let (server, ports) = launch(root.path(), ports).await;
315+ (root, server, ports)
316+}
317+
179 /// Starts `forge serve` on `ports` and returns once all three listeners answer. The config is318 /// Starts `forge serve` on `ports` and returns once all three listeners answer. The config is
180 /// written to `dir/forge.toml` and the log to `dir/serve.log`.319 /// written to `dir/forge.toml` and the log to `dir/serve.log`.
181 ///320 ///
crates/forge-e2e/tests/e2e/discussions_e2e.rsmodified+1 -19
@@ -4,30 +4,12 @@
4 //! owner can still write.4 //! owner can still write.
5 5
6 use crate::common::{6 use crate::common::{
7- Http, bin, input_value, launch, login, pick_ports, tool_on_path, write_config,7+ Http, input_value, launch, login, pick_ports, run_admin, tool_on_path, write_config,
8 };8 };
9-use std::path::Path;
10-use std::process::Command;
11 9
12 const TAHINLI_PW: &str = "tahinli-password-123";10 const TAHINLI_PW: &str = "tahinli-password-123";
13 const BOB_PW: &str = "bob-password-4567";11 const BOB_PW: &str = "bob-password-4567";
14 12
15-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
16- let out = Command::new(bin())
17- .arg("--config")
18- .arg(config)
19- .args(["admin", "create-user", username])
20- .args(extra)
21- .env("FORGE_PASSWORD", password)
22- .output()
23- .expect("run admin create-user");
24- assert!(
25- out.status.success(),
26- "create-user {username} failed:\n{}",
27- String::from_utf8_lossy(&out.stderr)
28- );
29-}
30-
31 /// Creates a public repo through `/new`.13 /// Creates a public repo through `/new`.
32 async fn create_repo(http: &Http, session: &str, name: &str) {14 async fn create_repo(http: &Http, session: &str, name: &str) {
33 let page = http.get("/new", Some(session)).await;15 let page = http.get("/new", Some(session)).await;
crates/forge-e2e/tests/e2e/git_e2e.rsmodified+2 -76
@@ -5,7 +5,8 @@
5 //! cookie jar would not send it over plain http. The test parses `Set-Cookie` and sends `Cookie`.5 //! cookie jar would not send it over plain http. The test parses `Set-Cookie` and sends `Cookie`.
6 6
7 use crate::common::{7 use crate::common::{
8- Http, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config,8+ Http, create_repo, create_token, describe, git, input_value, launch, login, pick_ports,
9+ run_admin, tool_on_path, write_config,
9 };10 };
10 use std::fs;11 use std::fs;
11 use std::path::{Path, PathBuf};12 use std::path::{Path, PathBuf};
@@ -16,18 +17,6 @@ use reqwest::header::WWW_AUTHENTICATE;
16 const TAHINLI_PW: &str = "tahinli-password-123";17 const TAHINLI_PW: &str = "tahinli-password-123";
17 const BOB_PW: &str = "bob-password-4567";18 const BOB_PW: &str = "bob-password-4567";
18 19
19-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
20- let out = Command::new(bin())
21- .arg("--config")
22- .arg(config)
23- .args(["admin", "create-user", username])
24- .args(extra)
25- .env("FORGE_PASSWORD", password)
26- .output()
27- .expect("run admin create-user");
28- ok(&out, &format!("create-user {username}"));
29-}
30-
31 fn ok(out: &Output, what: &str) {20 fn ok(out: &Output, what: &str) {
32 assert!(out.status.success(), "{what} failed:\n{}", describe(out));21 assert!(out.status.success(), "{what} failed:\n{}", describe(out));
33 }22 }
@@ -42,18 +31,6 @@ fn rejected(out: &Output, what: &str) -> String {
42 describe(out)31 describe(out)
43 }32 }
44 33
45-fn git(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> Output {
46- let mut cmd = Command::new("git");
47- cmd.current_dir(cwd)
48- .args(["-c", "credential.helper="])
49- .args(args)
50- .env("GIT_TERMINAL_PROMPT", "0");
51- for (key, value) in env {
52- cmd.env(key, value);
53- }
54- cmd.output().expect("run git")
55-}
56-
57 fn path_str(path: &Path) -> &str {34 fn path_str(path: &Path) -> &str {
58 path.to_str().expect("utf-8 path")35 path.to_str().expect("utf-8 path")
59 }36 }
@@ -140,32 +117,6 @@ fn read(path: PathBuf) -> String {
140 fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()))117 fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()))
141 }118 }
142 119
143-/// Creates an access token through `/settings/tokens` and returns the token shown once.
144-async fn create_token(http: &Http, session: &str, name: &str) -> String {
145- let page = http.get_cookie("/settings/keys", session).await;
146- assert_eq!(page.status, 200, "GET /settings/keys");
147- let csrf = input_value(&page.body, "csrf");
148- let res = http
149- .post_form(
150- "/settings/tokens",
151- &[("csrf", &csrf), ("name", name), ("expires", "30")],
152- Some(session),
153- )
154- .await;
155- assert_eq!(res.status, 200, "create token: {}", res.body);
156- let doc = scraper::Html::parse_document(&res.body);
157- let selector = scraper::Selector::parse("pre.code code").expect("selector");
158- let token: String = doc
159- .select(&selector)
160- .next()
161- .expect("token shown after creation")
162- .text()
163- .collect();
164- let token = token.trim().to_owned();
165- assert!(token.starts_with("forge_"), "unexpected token shape");
166- token
167-}
168-
169 /// Adds a public key through `/settings/keys`.120 /// Adds a public key through `/settings/keys`.
170 async fn add_key(http: &Http, session: &str, public_key: &str) {121 async fn add_key(http: &Http, session: &str, public_key: &str) {
171 let page = http.get_cookie("/settings/keys", session).await;122 let page = http.get_cookie("/settings/keys", session).await;
@@ -185,31 +136,6 @@ async fn add_key(http: &Http, session: &str, public_key: &str) {
185 assert_eq!(res.status, 303, "add SSH key: {}", res.body);136 assert_eq!(res.status, 303, "add SSH key: {}", res.body);
186 }137 }
187 138
188-/// Creates a repo through `/new`.
189-async fn create_repo(http: &Http, session: &str, name: &str, visibility: &str) {
190- let page = http.get_cookie("/new", session).await;
191- assert_eq!(page.status, 200, "GET /new");
192- let csrf = input_value(&page.body, "csrf");
193- let res = http
194- .post_form(
195- "/new",
196- &[
197- ("csrf", &csrf),
198- ("name", name),
199- ("description", ""),
200- ("visibility", visibility),
201- ("default_branch", "main"),
202- ],
203- Some(session),
204- )
205- .await;
206- assert_eq!(res.status, 303, "create repo {name}: {}", res.body);
207- assert_eq!(
208- res.location().as_deref(),
209- Some(format!("/tahinli/{name}").as_str())
210- );
211-}
212-
213 #[tokio::test]139 #[tokio::test]
214 async fn git_end_to_end() {140 async fn git_end_to_end() {
215 for tool in ["git", "ssh", "ssh-keygen"] {141 for tool in ["git", "ssh", "ssh-keygen"] {
crates/forge-e2e/tests/e2e/i18n_e2e.rsmodified+6 -6
@@ -1,7 +1,7 @@
1 //! End-to-end checks for the interface language. Anonymous pages follow `Accept-Language`; a1 //! End-to-end checks for the interface language. Anonymous pages follow `Accept-Language`; a
2 //! signed-in user's stored language beats the browser; `<html lang>` matches the language used.2 //! signed-in user's stored language beats the browser; `<html lang>` matches the language used.
3 3
4-use std::path::{Path, PathBuf};4+use std::path::Path;
5 use std::process::Command;5 use std::process::Command;
6 6
7 use crate::common::{7 use crate::common::{
@@ -38,7 +38,7 @@ struct Env {
38 /// Creates tahinli, then runs `seed` against the store before the server starts.38 /// Creates tahinli, then runs `seed` against the store before the server starts.
39 async fn start<F, Fut>(seed: F) -> Env39 async fn start<F, Fut>(seed: F) -> Env
40 where40 where
41- F: FnOnce(PathBuf, Store) -> Fut,41+ F: FnOnce(Store) -> Fut,
42 Fut: std::future::Future<Output = ()>,42 Fut: std::future::Future<Output = ()>,
43 {43 {
44 let root = tempfile::tempdir().expect("temp dir");44 let root = tempfile::tempdir().expect("temp dir");
@@ -49,7 +49,7 @@ where
49 let store = Store::open(&dir.join("forge.db"))49 let store = Store::open(&dir.join("forge.db"))
50 .await50 .await
51 .expect("open store");51 .expect("open store");
52- seed(dir.clone(), store).await;52+ seed(store).await;
53 let (server, ports) = launch(&dir, ports).await;53 let (server, ports) = launch(&dir, ports).await;
54 let http = Http::new(ports.http);54 let http = Http::new(ports.http);
55 Env {55 Env {
@@ -61,7 +61,7 @@ where
61 61
62 #[tokio::test]62 #[tokio::test]
63 async fn anonymous_pages_follow_the_browser_language() {63 async fn anonymous_pages_follow_the_browser_language() {
64- let env = start(|_, _| async {}).await;64+ let env = start(|_| async {}).await;
65 65
66 let turkish = env66 let turkish = env
67 .http67 .http
@@ -101,7 +101,7 @@ async fn anonymous_pages_follow_the_browser_language() {
101 101
102 #[tokio::test]102 #[tokio::test]
103 async fn stored_language_beats_the_browser_for_a_signed_in_user() {103 async fn stored_language_beats_the_browser_for_a_signed_in_user() {
104- let env = start(|_, store| async move {104+ let env = start(|store| async move {
105 let tahinli = store105 let tahinli = store
106 .user_by_username("tahinli")106 .user_by_username("tahinli")
107 .await107 .await
@@ -128,7 +128,7 @@ async fn stored_language_beats_the_browser_for_a_signed_in_user() {
128 128
129 #[tokio::test]129 #[tokio::test]
130 async fn releases_page_follows_the_stored_turkish_language() {130 async fn releases_page_follows_the_stored_turkish_language() {
131- let env = start(|_, store| async move {131+ let env = start(|store| async move {
132 let tahinli = store132 let tahinli = store
133 .user_by_username("tahinli")133 .user_by_username("tahinli")
134 .await134 .await
crates/forge-e2e/tests/e2e/issue_close_e2e.rsmodified+2 -17
@@ -4,7 +4,8 @@
4 //! file, and every push is a real `git push` through the git HTTP endpoints.4 //! file, and every push is a real `git push` through the git HTTP endpoints.
5 5
6 use crate::common::{6 use crate::common::{
7- Http, bin, input_value, launch, login, pick_ports, relaunch, tool_on_path, write_config,7+ Http, input_value, launch, login, pick_ports, relaunch, run_admin, tool_on_path,
8+ write_config,
8 };9 };
9 use std::fs;10 use std::fs;
10 use std::future::Future;11 use std::future::Future;
@@ -17,22 +18,6 @@ use forge_core::Store;
17 const TAHINLI_PW: &str = "tahinli-password-123";18 const TAHINLI_PW: &str = "tahinli-password-123";
18 const BOB_PW: &str = "bob-password-4567";19 const BOB_PW: &str = "bob-password-4567";
19 20
20-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
21- let out = Command::new(bin())
22- .arg("--config")
23- .arg(config)
24- .args(["admin", "create-user", username])
25- .args(extra)
26- .env("FORGE_PASSWORD", password)
27- .output()
28- .expect("run admin create-user");
29- assert!(
30- out.status.success(),
31- "create-user {username} failed:\n{}",
32- String::from_utf8_lossy(&out.stderr)
33- );
34-}
35-
36 /// Runs git with credential helpers disabled and returns stdout, trimmed. Panics on failure.21 /// Runs git with credential helpers disabled and returns stdout, trimmed. Panics on failure.
37 fn git(cwd: &Path, args: &[&str]) -> String {22 fn git(cwd: &Path, args: &[&str]) -> String {
38 let out = git_output(cwd, args, &[]);23 let out = git_output(cwd, args, &[]);
crates/forge-e2e/tests/e2e/lfs_e2e.rsmodified+1 -13
@@ -5,7 +5,7 @@
5 //! Git config is isolated from the developer's machine: `HOME` and `GIT_CONFIG_GLOBAL` point into5 //! Git config is isolated from the developer's machine: `HOME` and `GIT_CONFIG_GLOBAL` point into
6 //! the test's temp dir.6 //! the test's temp dir.
7 7
8-use crate::common::{Http, bin, describe, input_value, launch, login, pick_ports, write_config};8+use crate::common::{Http, describe, input_value, launch, login, pick_ports, run_admin, write_config};
9 use std::fs;9 use std::fs;
10 use std::path::Path;10 use std::path::Path;
11 use std::process::{Command, Output};11 use std::process::{Command, Output};
@@ -13,18 +13,6 @@ use std::process::{Command, Output};
13 const TAHINLI_PW: &str = "tahinli-password-123";13 const TAHINLI_PW: &str = "tahinli-password-123";
14 const FILE_SIZE: usize = 100 * 1024;14 const FILE_SIZE: usize = 100 * 1024;
15 15
16-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
17- let out = Command::new(bin())
18- .arg("--config")
19- .arg(config)
20- .args(["admin", "create-user", username])
21- .args(extra)
22- .env("FORGE_PASSWORD", password)
23- .output()
24- .expect("run admin create-user");
25- ok(&out, &format!("create-user {username}"));
26-}
27-
28 fn ok(out: &Output, what: &str) {16 fn ok(out: &Output, what: &str) {
29 assert!(out.status.success(), "{what} failed:\n{}", describe(out));17 assert!(out.status.success(), "{what} failed:\n{}", describe(out));
30 }18 }
crates/forge-e2e/tests/e2e/merge_queue_e2e.rsmodified+3 -133
@@ -1,17 +1,6 @@
1-//! End-to-end: the merge queue on a protected branch, against the real `forge` binary and the
2-//! real `forge-runner` library (see `ci_e2e.rs` for the harness).
3-//!
4-//! Scenarios:
5-//! - two pull requests queue; the first lands on a tested candidate, the second is removed with
6-//! a comment linking its failing run, and `main` only ever holds the tested commit;
7-//! - a new commit on a queued pull request's head removes it from the queue.
8-
9-// The harness helpers are the same ones `ci_e2e.rs` uses. This file uses a subset of them.
10-#![allow(dead_code)]
11-
12 use crate::common::{1 use crate::common::{
13- FAST_CLAIMS, Http, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path,2+ FAST_CLAIMS, Http, Server, input_value, launch_with, login, pick_ports, run_admin,
14- write_config,3+ tool_on_path, write_config,
15 };4 };
16 use forge_ci::proto::{JobAssignment, RegisterRequest};5 use forge_ci::proto::{JobAssignment, RegisterRequest};
17 use forge_runner::client::ForgeClient;6 use forge_runner::client::ForgeClient;
@@ -21,18 +10,15 @@ use forge_runner::runner::{RunOptions, Runner};
21 use std::collections::BTreeMap;10 use std::collections::BTreeMap;
22 use std::fs;11 use std::fs;
23 use std::path::{Path, PathBuf};12 use std::path::{Path, PathBuf};
24-use std::process::{Command, Output};13+use std::process::Command;
25 use std::sync::Arc;14 use std::sync::Arc;
26-use std::time::{Duration, Instant};
27 use tokio_util::sync::CancellationToken;15 use tokio_util::sync::CancellationToken;
28 16
29 const TAHINLI_PW: &str = "tahinli-password-123";17 const TAHINLI_PW: &str = "tahinli-password-123";
30 const BOB_PW: &str = "bob-password-4567";18 const BOB_PW: &str = "bob-password-4567";
31-const BOB_EMAIL: &str = "bob@users.noreply.127.0.0.1";
32 const REPO_PATH: &str = "/tahinli/r";19 const REPO_PATH: &str = "/tahinli/r";
33 const LABELS: &[&str] = &["linux"];20 const LABELS: &[&str] = &["linux"];
34 21
35-/// The text of the first element matching `selector`.
36 fn first_text(body: &str, selector: &str) -> String {22 fn first_text(body: &str, selector: &str) -> String {
37 let doc = scraper::Html::parse_document(body);23 let doc = scraper::Html::parse_document(body);
38 let selector = scraper::Selector::parse(selector).expect("selector");24 let selector = scraper::Selector::parse(selector).expect("selector");
@@ -45,27 +31,6 @@ fn first_text(body: &str, selector: &str) -> String {
45 .to_owned()31 .to_owned()
46 }32 }
47 33
48-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
49- let out = Command::new(bin())
50- .arg("--config")
51- .arg(config)
52- .args(["admin", "create-user", username])
53- .args(extra)
54- .env("FORGE_PASSWORD", password)
55- .output()
56- .expect("run admin create-user");
57- ok(&out, &format!("create-user {username}"));
58-}
59-
60-fn ok(out: &Output, what: &str) {
61- assert!(
62- out.status.success(),
63- "{what} failed:\n{}",
64- String::from_utf8_lossy(&out.stderr)
65- );
66-}
67-
68-/// Runs git in `cwd` with `env` applied on top of the inherited environment. Returns stdout.
69 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {34 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {
70 let mut cmd = Command::new("git");35 let mut cmd = Command::new("git");
71 cmd.current_dir(cwd)36 cmd.current_dir(cwd)
@@ -88,8 +53,6 @@ fn git(cwd: &Path, args: &[&str]) -> String {
88 git_env(cwd, args, &[])53 git_env(cwd, args, &[])
89 }54 }
90 55
91-/// Writes `file` (creating its directory), commits it with `who` as author and committer, and
92-/// returns the new HEAD.
93 fn commit(56 fn commit(
94 repo: &Path,57 repo: &Path,
95 file: &str,58 file: &str,
@@ -117,7 +80,6 @@ fn commit(
117 git(repo, &["rev-parse", "HEAD"])80 git(repo, &["rev-parse", "HEAD"])
118 }81 }
119 82
120-/// Clones `url` into `into` (a path that does not exist yet) and returns it.
121 fn clone(url: &str, into: &Path) -> PathBuf {83 fn clone(url: &str, into: &Path) -> PathBuf {
122 let parent = into.parent().expect("clone target has a parent");84 let parent = into.parent().expect("clone target has a parent");
123 git(85 git(
@@ -127,19 +89,16 @@ fn clone(url: &str, into: &Path) -> PathBuf {
127 into.to_path_buf()89 into.to_path_buf()
128 }90 }
129 91
130-/// The HTTPS remote for `owner/repo`, authenticated with a token.
131 fn remote(port: u16, user: &str, token: &str, owner: &str, repo: &str) -> String {92 fn remote(port: u16, user: &str, token: &str, owner: &str, repo: &str) -> String {
132 format!("http://{user}:{token}@127.0.0.1:{port}/{owner}/{repo}.git")93 format!("http://{user}:{token}@127.0.0.1:{port}/{owner}/{repo}.git")
133 }94 }
134 95
135-/// The CSRF token shown on any settings page of the signed-in user.
136 async fn csrf_from(http: &Http, path: &str, session: &str) -> String {96 async fn csrf_from(http: &Http, path: &str, session: &str) -> String {
137 let page = http.get(path, Some(session)).await;97 let page = http.get(path, Some(session)).await;
138 assert_eq!(page.status, 200, "GET {path}");98 assert_eq!(page.status, 200, "GET {path}");
139 input_value(&page.body, "csrf")99 input_value(&page.body, "csrf")
140 }100 }
141 101
142-/// Creates an access token through `/settings/tokens` and returns the token shown once.
143 async fn create_token(http: &Http, session: &str, name: &str) -> String {102 async fn create_token(http: &Http, session: &str, name: &str) -> String {
144 let csrf = csrf_from(http, "/settings/keys", session).await;103 let csrf = csrf_from(http, "/settings/keys", session).await;
145 let res = http104 let res = http
@@ -155,7 +114,6 @@ async fn create_token(http: &Http, session: &str, name: &str) -> String {
155 token114 token
156 }115 }
157 116
158-/// Creates a public repo `name` owned by tahinli through `/new`.
159 async fn create_repo(http: &Http, session: &str, name: &str) {117 async fn create_repo(http: &Http, session: &str, name: &str) {
160 let page = http.get("/new", Some(session)).await;118 let page = http.get("/new", Some(session)).await;
161 assert_eq!(page.status, 200, "GET /new");119 assert_eq!(page.status, 200, "GET /new");
@@ -180,21 +138,6 @@ async fn create_repo(http: &Http, session: &str, name: &str) {
180 );138 );
181 }139 }
182 140
183-/// Adds or replaces a repo secret through the settings form.
184-async fn set_secret(http: &Http, session: &str, name: &str, value: &str) {
185- let csrf = csrf_from(http, &format!("{REPO_PATH}/settings/secrets"), session).await;
186- let res = http
187- .post_form(
188- &format!("{REPO_PATH}/settings/secrets"),
189- &[("csrf", &csrf), ("name", name), ("value", value)],
190- Some(session),
191- )
192- .await;
193- assert_eq!(res.status, 303, "set secret {name}: {}", res.body);
194-}
195-
196-/// A running server with its own temp data dir. Field order matters: the server is dropped (and
197-/// killed) before the temp dir is removed.
198 struct Booted {141 struct Booted {
199 _server: Server,142 _server: Server,
200 _root: tempfile::TempDir,143 _root: tempfile::TempDir,
@@ -204,14 +147,11 @@ struct Booted {
204 port: u16,147 port: u16,
205 }148 }
206 149
207-/// The server's log, for assertion messages.
208 fn server_log(b: &Booted) -> String {150 fn server_log(b: &Booted) -> String {
209 fs::read_to_string(b.dir.join("serve.log")).unwrap_or_default()151 fs::read_to_string(b.dir.join("serve.log")).unwrap_or_default()
210 }152 }
211 153
212-/// Creates tahinli (admin) and bob, then boots the server on fresh ports.
213 async fn boot() -> Booted {154 async fn boot() -> Booted {
214- // Keep the path short: the internal unix socket path is limited to 108 bytes.
215 let root = tempfile::Builder::new()155 let root = tempfile::Builder::new()
216 .prefix("ci2e")156 .prefix("ci2e")
217 .tempdir_in("/tmp")157 .tempdir_in("/tmp")
@@ -233,7 +173,6 @@ async fn boot() -> Booted {
233 }173 }
234 }174 }
235 175
236-/// A registered runner and the secret it claims with.
237 struct Worker {176 struct Worker {
238 runner: Runner,177 runner: Runner,
239 secret: String,178 secret: String,
@@ -241,7 +180,6 @@ struct Worker {
241 }180 }
242 181
243 impl Worker {182 impl Worker {
244- /// One claim. `None` means the forge had nothing for this runner (after its long poll).
245 async fn claim(&self) -> Option<JobAssignment> {183 async fn claim(&self) -> Option<JobAssignment> {
246 self.runner184 self.runner
247 .client()185 .client()
@@ -251,7 +189,6 @@ impl Worker {
251 .job189 .job
252 }190 }
253 191
254- /// Claims and runs jobs until the forge has nothing left. Returns how many ran.
255 async fn drain(&self) -> usize {192 async fn drain(&self) -> usize {
256 let mut ran = 0;193 let mut ran = 0;
257 while let Some(job) = self.claim().await {194 while let Some(job) = self.claim().await {
@@ -262,7 +199,6 @@ impl Worker {
262 }199 }
263 }200 }
264 201
265-/// Registers a runner through the admin page and the runner API. The admin is `admin_session`.
266 async fn register_runner(b: &Booted, admin_session: &str, name: &str) -> Worker {202 async fn register_runner(b: &Booted, admin_session: &str, name: &str) -> Worker {
267 let page = b.http.get("/admin/runners", Some(admin_session)).await;203 let page = b.http.get("/admin/runners", Some(admin_session)).await;
268 assert_eq!(page.status, 200, "GET /admin/runners");204 assert_eq!(page.status, 200, "GET /admin/runners");
@@ -300,7 +236,6 @@ async fn register_runner(b: &Booted, admin_session: &str, name: &str) -> Worker
300 images: forge_runner::config::ImagesConfig::default(),236 images: forge_runner::config::ImagesConfig::default(),
301 sandbox: forge_runner::config::SandboxConfig::default(),237 sandbox: forge_runner::config::SandboxConfig::default(),
302 registries: Vec::new(),238 registries: Vec::new(),
303- // The e2e runner must not replace the test binary under itself.
304 auto_update: false,239 auto_update: false,
305 cache_max_gib: 0,240 cache_max_gib: 0,
306 };241 };
@@ -313,15 +248,11 @@ async fn register_runner(b: &Booted, admin_session: &str, name: &str) -> Worker
313 }248 }
314 }249 }
315 250
316-/// One commit status as the status API reports it.
317 #[derive(Debug, Clone)]251 #[derive(Debug, Clone)]
318 struct Status {252 struct Status {
319 state: String,253 state: String,
320- description: String,
321- target_url: String,
322 }254 }
323 255
324-/// The statuses on `sha` of tahinli/r, keyed by context.
325 async fn statuses(http: &Http, token: &str, sha: &str) -> BTreeMap<String, Status> {256 async fn statuses(http: &Http, token: &str, sha: &str) -> BTreeMap<String, Status> {
326 let res = http257 let res = http
327 .get_bearer(258 .get_bearer(
@@ -341,62 +272,12 @@ async fn statuses(http: &Http, token: &str, sha: &str) -> BTreeMap<String, Statu
341 field("context"),272 field("context"),
342 Status {273 Status {
343 state: field("state"),274 state: field("state"),
344- description: field("description"),
345- target_url: field("target_url"),
346 },275 },
347 )276 )
348 })277 })
349 .collect()278 .collect()
350 }279 }
351 280
352-/// Polls the statuses until every context in `contexts` is present, then returns them.
353-async fn wait_statuses(
354- http: &Http,
355- token: &str,
356- sha: &str,
357- contexts: &[&str],
358-) -> BTreeMap<String, Status> {
359- let deadline = Instant::now() + Duration::from_secs(20);
360- loop {
361- let found = statuses(http, token, sha).await;
362- if contexts.iter().all(|c| found.contains_key(*c)) {
363- return found;
364- }
365- assert!(
366- Instant::now() < deadline,
367- "statuses never showed {contexts:?}; got {found:?}"
368- );
369- tokio::time::sleep(Duration::from_millis(100)).await;
370- }
371-}
372-
373-/// The job id at the end of a status `target_url` (`.../ci/jobs/<id>`).
374-fn job_id_of(status: &Status) -> String {
375- status
376- .target_url
377- .rsplit('/')
378- .next()
379- .filter(|id| !id.is_empty())
380- .unwrap_or_else(|| panic!("no job id in {:?}", status.target_url))
381- .to_owned()
382-}
383-
384-/// Pushes `.forge/ci.toml` (with `contents`) to `main` as tahinli. Returns the pushed commit.
385-fn push_ci_config(work: &Path, contents: &str) -> String {
386- let sha = commit(
387- work,
388- ".forge/ci.toml",
389- contents,
390- "add ci",
391- "tahinli",
392- "tahinli@example.test",
393- );
394- git(work, &["push", "-q", "origin", "HEAD:refs/heads/main"]);
395- sha
396-}
397-
398-/// The queue's workflow. Only the queue runs it (`merge_queue = true`), never the push to main.
399-/// The job fails when a candidate holds both files, which is what a semantic conflict looks like.
400 const CI_TOML_QUEUE: &str = r#"[on]281 const CI_TOML_QUEUE: &str = r#"[on]
401 merge_queue = true282 merge_queue = true
402 283
@@ -405,7 +286,6 @@ image = "docker.io/library/alpine:3"
405 run = "if [ -f a.txt ] && [ -f b.txt ]; then echo both files present; exit 1; fi"286 run = "if [ -f a.txt ] && [ -f b.txt ]; then echo both files present; exit 1; fi"
406 "#;287 "#;
407 288
408-/// Turns the merge queue on for `main` through the branch rule form.
409 async fn require_merge_queue(http: &Http, session: &str) {289 async fn require_merge_queue(http: &Http, session: &str) {
410 let csrf = csrf_from(http, &format!("{REPO_PATH}/settings"), session).await;290 let csrf = csrf_from(http, &format!("{REPO_PATH}/settings"), session).await;
411 let res = http291 let res = http
@@ -428,8 +308,6 @@ async fn require_merge_queue(http: &Http, session: &str) {
428 );308 );
429 }309 }
430 310
431-/// Pushes one new file on a branch cut from `origin/main`, opens a pull request for it and
432-/// returns the pull request number.
433 async fn open_pull(http: &Http, session: &str, work: &Path, branch: &str, file: &str) -> i64 {311 async fn open_pull(http: &Http, session: &str, work: &Path, branch: &str, file: &str) -> i64 {
434 git(work, &["fetch", "-q", "origin"]);312 git(work, &["fetch", "-q", "origin"]);
435 let start = "origin/main";313 let start = "origin/main";
@@ -469,7 +347,6 @@ async fn open_pull(http: &Http, session: &str, work: &Path, branch: &str, file:
469 .expect("pull number in location")347 .expect("pull number in location")
470 }348 }
471 349
472-/// Queues a pull request with the merge style `merge`.
473 async fn enqueue(http: &Http, session: &str, number: i64) {350 async fn enqueue(http: &Http, session: &str, number: i64) {
474 let csrf = csrf_from(http, &format!("{REPO_PATH}/pulls/{number}"), session).await;351 let csrf = csrf_from(http, &format!("{REPO_PATH}/pulls/{number}"), session).await;
475 let res = http352 let res = http
@@ -482,7 +359,6 @@ async fn enqueue(http: &Http, session: &str, number: i64) {
482 assert_eq!(res.status, 303, "enqueue #{number}: {}", res.body);359 assert_eq!(res.status, 303, "enqueue #{number}: {}", res.body);
483 }360 }
484 361
485-/// The body of a pull request page, lowercased for loose text checks.
486 async fn pull_page(http: &Http, session: &str, number: i64) -> String {362 async fn pull_page(http: &Http, session: &str, number: i64) -> String {
487 let res = http363 let res = http
488 .get(&format!("{REPO_PATH}/pulls/{number}"), Some(session))364 .get(&format!("{REPO_PATH}/pulls/{number}"), Some(session))
@@ -491,8 +367,6 @@ async fn pull_page(http: &Http, session: &str, number: i64) -> String {
491 res.body367 res.body
492 }368 }
493 369
494-/// Pushes the queue workflow to `main` and runs its push-less base state to completion, so the
495-/// only runs from here on are queue candidates.
496 async fn setup_queue_repo(b: &Booted, tahinli: &str, token: &str) -> (Worker, PathBuf) {370 async fn setup_queue_repo(b: &Booted, tahinli: &str, token: &str) -> (Worker, PathBuf) {
497 create_repo(&b.http, tahinli, "r").await;371 create_repo(&b.http, tahinli, "r").await;
498 require_merge_queue(&b.http, tahinli).await;372 require_merge_queue(&b.http, tahinli).await;
@@ -537,8 +411,6 @@ async fn merge_queue_lands_the_first_pull_and_kicks_out_the_conflicting_second()
537 server_log(&b)411 server_log(&b)
538 );412 );
539 413
540- // The first candidate passes and lands. The second candidate is then built on the new tip,
541- // holds both files, and fails.
542 let ran = worker.drain().await;414 let ran = worker.drain().await;
543 assert_eq!(ran, 2, "one candidate run each: {}", server_log(&b));415 assert_eq!(ran, 2, "one candidate run each: {}", server_log(&b));
544 416
@@ -551,7 +423,6 @@ async fn merge_queue_lands_the_first_pull_and_kicks_out_the_conflicting_second()
551 "second pull did not land: {files}"423 "second pull did not land: {files}"
552 );424 );
553 425
554- // The target only points at a tested commit: the candidate carries its passing run.
555 let found = statuses(&b.http, &token, &main_tip).await;426 let found = statuses(&b.http, &token, &main_tip).await;
556 assert_eq!(427 assert_eq!(
557 found["ci/test"].state, "success",428 found["ci/test"].state, "success",
@@ -602,7 +473,6 @@ async fn pushing_to_a_queued_pull_removes_it_from_the_queue() {
602 let queued = pull_page(&b.http, &tahinli, number).await;473 let queued = pull_page(&b.http, &tahinli, number).await;
603 assert!(queued.contains("Position 1 in the merge queue"), "queued");474 assert!(queued.contains("Position 1 in the merge queue"), "queued");
604 475
605- // A new commit on the pull request head: the entry no longer tests what it was queued for.
606 commit(476 commit(
607 &work,477 &work,
608 "c.txt",478 "c.txt",
crates/forge-e2e/tests/e2e/mirrors_e2e.rsmodified+2 -17
@@ -10,7 +10,8 @@
10 //! - the mirror pages and the server log never contain the access token.10 //! - the mirror pages and the server log never contain the access token.
11 11
12 use crate::common::{12 use crate::common::{
13- Http, Server, bin, input_value, launch_with, login, pick_ports, tool_on_path, write_config_with,13+ Http, Server, input_value, launch_with, login, pick_ports, run_admin, tool_on_path,
14+ write_config_with,
14 };15 };
15 use std::collections::BTreeSet;16 use std::collections::BTreeSet;
16 use std::fs;17 use std::fs;
@@ -36,22 +37,6 @@ fn form_actions(body: &str, suffix: &str) -> Vec<String> {
36 .collect()37 .collect()
37 }38 }
38 39
39-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
40- let out = Command::new(bin())
41- .arg("--config")
42- .arg(config)
43- .args(["admin", "create-user", username])
44- .args(extra)
45- .env("FORGE_PASSWORD", password)
46- .output()
47- .expect("run admin create-user");
48- assert!(
49- out.status.success(),
50- "create-user {username} failed:\n{}",
51- String::from_utf8_lossy(&out.stderr)
52- );
53-}
54-
55 /// Fixed identity and config isolation for every git this file spawns, so the result does not40 /// Fixed identity and config isolation for every git this file spawns, so the result does not
56 /// depend on the machine's global git config (a clean CI container has none).41 /// depend on the machine's global git config (a clean CI container has none).
57 const GIT_HERMETIC_ENV: &[(&str, &str)] = &[42 const GIT_HERMETIC_ENV: &[(&str, &str)] = &[
crates/forge-e2e/tests/e2e/oci_e2e.rsmodified+37 -78
@@ -186,10 +186,25 @@ async fn user(store: &Store, name: &str) -> User {
186 .expect("user exists")186 .expect("user exists")
187 }187 }
188 188
189+async fn start_with_packages_token() -> (Env, String) {
190+ let token = generate_token();
191+ let seeded = token.clone();
192+ let env = start(move |store| async move {
193+ let tahinli = user(&store, "tahinli").await;
194+ grant(&store, &tahinli, &["packages"], &seeded).await;
195+ })
196+ .await;
197+ (env, token)
198+}
199+
189 fn sha256_digest(bytes: &[u8]) -> String {200 fn sha256_digest(bytes: &[u8]) -> String {
190 format!("sha256:{}", hex::encode(Sha256::digest(bytes)))201 format!("sha256:{}", hex::encode(Sha256::digest(bytes)))
191 }202 }
192 203
204+fn blob_path(bytes: &[u8]) -> String {
205+ format!("/v2/tahinli/app/blobs/{}", sha256_digest(bytes))
206+}
207+
193 /// The bearer header a client gets from the token endpoint with Basic `tahinli:<token>`.208 /// The bearer header a client gets from the token endpoint with Basic `tahinli:<token>`.
194 async fn bearer_for(http: &Http, token: &str) -> String {209 async fn bearer_for(http: &Http, token: &str) -> String {
195 let res = http210 let res = http
@@ -298,13 +313,7 @@ async fn put_manifest(http: &Http, repo: &str, reference: &str, auth: &str, body
298 313
299 #[tokio::test]314 #[tokio::test]
300 async fn probe_challenges_and_the_token_endpoint_issues_a_bearer_token() {315 async fn probe_challenges_and_the_token_endpoint_issues_a_bearer_token() {
301- let token = generate_token();316+ let (env, token) = start_with_packages_token().await;
302- let seeded = token.clone();
303- let env = start(move |store| async move {
304- let tahinli = user(&store, "tahinli").await;
305- grant(&store, &tahinli, &["packages"], &seeded).await;
306- })
307- .await;
308 let port = env.port;317 let port = env.port;
309 318
310 let probe = env.http.get("/v2/", None).await;319 let probe = env.http.get("/v2/", None).await;
@@ -334,13 +343,7 @@ async fn probe_challenges_and_the_token_endpoint_issues_a_bearer_token() {
334 343
335 #[tokio::test]344 #[tokio::test]
336 async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {345 async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {
337- let token = generate_token();346+ let (env, token) = start_with_packages_token().await;
338- let seeded = token.clone();
339- let env = start(move |store| async move {
340- let tahinli = user(&store, "tahinli").await;
341- grant(&store, &tahinli, &["packages"], &seeded).await;
342- })
343- .await;
344 let http = &env.http;347 let http = &env.http;
345 let auth = bearer_for(http, &token).await;348 let auth = bearer_for(http, &token).await;
346 349
@@ -364,13 +367,13 @@ async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {
364 assert_eq!(res.status, 201, "{}", res.text());367 assert_eq!(res.status, 201, "{}", res.text());
365 assert_eq!(368 assert_eq!(
366 res.header("location"),369 res.header("location"),
367- Some(format!("/v2/tahinli/app/blobs/{}", sha256_digest(&layer_two)).as_str())370+ Some(blob_path(&layer_two).as_str())
368 );371 );
369 372
370 let head = http373 let head = http
371 .send(374 .send(
372 reqwest::Method::HEAD,375 reqwest::Method::HEAD,
373- &format!("/v2/tahinli/app/blobs/{}", sha256_digest(&layer_two)),376+ &blob_path(&layer_two),
374 Some(&auth),377 Some(&auth),
375 &[],378 &[],
376 None,379 None,
@@ -380,7 +383,7 @@ async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {
380 assert_eq!(head.header("content-length"), Some("3000"));383 assert_eq!(head.header("content-length"), Some("3000"));
381 let blob = http384 let blob = http
382 .get(385 .get(
383- &format!("/v2/tahinli/app/blobs/{}", sha256_digest(&layer_two)),386+ &blob_path(&layer_two),
384 Some(&auth),387 Some(&auth),
385 )388 )
386 .await;389 .await;
@@ -421,13 +424,7 @@ async fn push_by_monolithic_and_chunked_upload_then_pull_by_tag_and_digest() {
421 424
422 #[tokio::test]425 #[tokio::test]
423 async fn the_tag_list_pages_with_n_and_last() {426 async fn the_tag_list_pages_with_n_and_last() {
424- let token = generate_token();427+ let (env, token) = start_with_packages_token().await;
425- let seeded = token.clone();
426- let env = start(move |store| async move {
427- let tahinli = user(&store, "tahinli").await;
428- grant(&store, &tahinli, &["packages"], &seeded).await;
429- })
430- .await;
431 let http = &env.http;428 let http = &env.http;
432 let auth = bearer_for(http, &token).await;429 let auth = bearer_for(http, &token).await;
433 let config = b"{}".to_vec();430 let config = b"{}".to_vec();
@@ -467,13 +464,7 @@ async fn the_tag_list_pages_with_n_and_last() {
467 464
468 #[tokio::test]465 #[tokio::test]
469 async fn bad_digests_and_missing_blobs_are_refused_with_oci_codes() {466 async fn bad_digests_and_missing_blobs_are_refused_with_oci_codes() {
470- let token = generate_token();467+ let (env, token) = start_with_packages_token().await;
471- let seeded = token.clone();
472- let env = start(move |store| async move {
473- let tahinli = user(&store, "tahinli").await;
474- grant(&store, &tahinli, &["packages"], &seeded).await;
475- })
476- .await;
477 let http = &env.http;468 let http = &env.http;
478 let auth = bearer_for(http, &token).await;469 let auth = bearer_for(http, &token).await;
479 let config = b"{}".to_vec();470 let config = b"{}".to_vec();
@@ -516,7 +507,7 @@ async fn bad_digests_and_missing_blobs_are_refused_with_oci_codes() {
516 507
517 let res = http508 let res = http
518 .get(509 .get(
519- &format!("/v2/tahinli/app/blobs/{}", sha256_digest(b"absent")),510+ &blob_path(b"absent"),
520 Some(&auth),511 Some(&auth),
521 )512 )
522 .await;513 .await;
@@ -526,13 +517,7 @@ async fn bad_digests_and_missing_blobs_are_refused_with_oci_codes() {
526 517
527 #[tokio::test]518 #[tokio::test]
528 async fn an_aborted_chunked_upload_is_gone_after_a_bad_digest() {519 async fn an_aborted_chunked_upload_is_gone_after_a_bad_digest() {
529- let token = generate_token();520+ let (env, token) = start_with_packages_token().await;
530- let seeded = token.clone();
531- let env = start(move |store| async move {
532- let tahinli = user(&store, "tahinli").await;
533- grant(&store, &tahinli, &["packages"], &seeded).await;
534- })
535- .await;
536 let http = &env.http;521 let http = &env.http;
537 let auth = bearer_for(http, &token).await;522 let auth = bearer_for(http, &token).await;
538 523
@@ -621,7 +606,7 @@ async fn a_public_image_pulls_anonymously_and_a_private_one_does_not() {
621 assert_eq!(anon.body, image);606 assert_eq!(anon.body, image);
622 let anon_blob = http607 let anon_blob = http
623 .get(608 .get(
624- &format!("/v2/tahinli/app/blobs/{}", sha256_digest(&config)),609+ &blob_path(&config),
625 None,610 None,
626 )611 )
627 .await;612 .await;
@@ -710,13 +695,7 @@ async fn bearer_for_as(http: &Http, who: &str, token: &str) -> String {
710 695
711 #[tokio::test]696 #[tokio::test]
712 async fn mount_copies_a_blob_across_repositories() {697 async fn mount_copies_a_blob_across_repositories() {
713- let token = generate_token();698+ let (env, token) = start_with_packages_token().await;
714- let seeded = token.clone();
715- let env = start(move |store| async move {
716- let tahinli = user(&store, "tahinli").await;
717- grant(&store, &tahinli, &["packages"], &seeded).await;
718- })
719- .await;
720 let http = &env.http;699 let http = &env.http;
721 let auth = bearer_for(http, &token).await;700 let auth = bearer_for(http, &token).await;
722 let layer = b"shared layer bytes".to_vec();701 let layer = b"shared layer bytes".to_vec();
@@ -757,13 +736,7 @@ async fn mount_copies_a_blob_across_repositories() {
757 736
758 #[tokio::test]737 #[tokio::test]
759 async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {738 async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
760- let token = generate_token();739+ let (env, token) = start_with_packages_token().await;
761- let seeded = token.clone();
762- let env = start(move |store| async move {
763- let tahinli = user(&store, "tahinli").await;
764- grant(&store, &tahinli, &["packages"], &seeded).await;
765- })
766- .await;
767 let http = &env.http;740 let http = &env.http;
768 let auth = bearer_for(http, &token).await;741 let auth = bearer_for(http, &token).await;
769 let config = b"{\"shared\":true}".to_vec();742 let config = b"{\"shared\":true}".to_vec();
@@ -790,7 +763,6 @@ async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
790 201763 201
791 );764 );
792 765
793- let blob_url = |bytes: &[u8]| format!("/v2/tahinli/app/blobs/{}", sha256_digest(bytes));
794 let res = http766 let res = http
795 .send(767 .send(
796 reqwest::Method::DELETE,768 reqwest::Method::DELETE,
@@ -809,9 +781,9 @@ async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
809 );781 );
810 // The blobs were pushed just now: the sweep keeps a link newer than the grace period, since a782 // The blobs were pushed just now: the sweep keeps a link newer than the grace period, since a
811 // push can still be on its way to a manifest. The store test covers the sweep after it.783 // push can still be on its way to a manifest. The store test covers the sweep after it.
812- assert_eq!(http.get(&blob_url(&layer_b), Some(&auth)).await.status, 200);784+ assert_eq!(http.get(&blob_path(&layer_b), Some(&auth)).await.status, 200);
813- assert_eq!(http.get(&blob_url(&layer_a), Some(&auth)).await.status, 200);785+ assert_eq!(http.get(&blob_path(&layer_a), Some(&auth)).await.status, 200);
814- assert_eq!(http.get(&blob_url(&config), Some(&auth)).await.status, 200);786+ assert_eq!(http.get(&blob_path(&config), Some(&auth)).await.status, 200);
815 787
816 let v1_digest = sha256_digest(&v1);788 let v1_digest = sha256_digest(&v1);
817 let res = http789 let res = http
@@ -824,21 +796,15 @@ async fn deleting_tags_and_manifests_keeps_fresh_blobs_for_the_grace_period() {
824 )796 )
825 .await;797 .await;
826 assert_eq!(res.status, 202);798 assert_eq!(res.status, 202);
827- assert_eq!(http.get(&blob_url(&layer_a), Some(&auth)).await.status, 200);799+ assert_eq!(http.get(&blob_path(&layer_a), Some(&auth)).await.status, 200);
828- assert_eq!(http.get(&blob_url(&config), Some(&auth)).await.status, 200);800+ assert_eq!(http.get(&blob_path(&config), Some(&auth)).await.status, 200);
829 let tags = http.get("/v2/tahinli/app/tags/list", Some(&auth)).await;801 let tags = http.get("/v2/tahinli/app/tags/list", Some(&auth)).await;
830 assert_eq!(tags.json()["tags"], serde_json::json!([]));802 assert_eq!(tags.json()["tags"], serde_json::json!([]));
831 }803 }
832 804
833 #[tokio::test]805 #[tokio::test]
834 async fn a_blob_a_manifest_uses_cannot_be_deleted_and_an_unused_one_can() {806 async fn a_blob_a_manifest_uses_cannot_be_deleted_and_an_unused_one_can() {
835- let token = generate_token();807+ let (env, token) = start_with_packages_token().await;
836- let seeded = token.clone();
837- let env = start(move |store| async move {
838- let tahinli = user(&store, "tahinli").await;
839- grant(&store, &tahinli, &["packages"], &seeded).await;
840- })
841- .await;
842 let http = &env.http;808 let http = &env.http;
843 let auth = bearer_for(http, &token).await;809 let auth = bearer_for(http, &token).await;
844 let config = b"{}".to_vec();810 let config = b"{}".to_vec();
@@ -869,11 +835,10 @@ async fn a_blob_a_manifest_uses_cannot_be_deleted_and_an_unused_one_can() {
869 201835 201
870 );836 );
871 837
872- let delete = |bytes: &[u8]| format!("/v2/tahinli/app/blobs/{}", sha256_digest(bytes));
873 let refused = http838 let refused = http
874 .send(839 .send(
875 reqwest::Method::DELETE,840 reqwest::Method::DELETE,
876- &delete(&layer),841+ &blob_path(&layer),
877 Some(&auth),842 Some(&auth),
878 &[],843 &[],
879 None,844 None,
@@ -885,14 +850,14 @@ async fn a_blob_a_manifest_uses_cannot_be_deleted_and_an_unused_one_can() {
885 let gone = http850 let gone = http
886 .send(851 .send(
887 reqwest::Method::DELETE,852 reqwest::Method::DELETE,
888- &delete(&spare),853+ &blob_path(&spare),
889 Some(&auth),854 Some(&auth),
890 &[],855 &[],
891 None,856 None,
892 )857 )
893 .await;858 .await;
894 assert_eq!(gone.status, 202);859 assert_eq!(gone.status, 202);
895- assert_eq!(http.get(&delete(&spare), Some(&auth)).await.status, 404);860+ assert_eq!(http.get(&blob_path(&spare), Some(&auth)).await.status, 404);
896 }861 }
897 862
898 #[tokio::test]863 #[tokio::test]
@@ -902,13 +867,7 @@ async fn podman_logs_in_pushes_and_pulls_an_image() {
902 eprintln!("podman is not installed; skipping");867 eprintln!("podman is not installed; skipping");
903 return;868 return;
904 }869 }
905- let token = generate_token();870+ let (env, token) = start_with_packages_token().await;
906- let seeded = token.clone();
907- let env = start(move |store| async move {
908- let tahinli = user(&store, "tahinli").await;
909- grant(&store, &tahinli, &["packages"], &seeded).await;
910- })
911- .await;
912 let host = format!("127.0.0.1:{}", env.port);871 let host = format!("127.0.0.1:{}", env.port);
913 let work = tempfile::tempdir().expect("work dir");872 let work = tempfile::tempdir().expect("work dir");
914 let dir = work.path();873 let dir = work.path();
crates/forge-e2e/tests/e2e/orgs_core_e2e.rsmodified+6 -21
@@ -7,7 +7,7 @@ use crate::common::{
7 Http, Resp, Server, bin, cookie_named, describe, input_value, launch, pick_ports, write_config,7 Http, Resp, Server, bin, cookie_named, describe, input_value, launch, pick_ports, write_config,
8 };8 };
9 use std::future::Future;9 use std::future::Future;
10-use std::path::{Path, PathBuf};10+use std::path::Path;
11 use std::process::Command;11 use std::process::Command;
12 use std::time::Duration;12 use std::time::Duration;
13 13
@@ -69,7 +69,7 @@ struct Env {
69 /// the store before the server starts.69 /// the store before the server starts.
70 async fn start<F, Fut>(seed: F) -> Env70 async fn start<F, Fut>(seed: F) -> Env
71 where71 where
72- F: FnOnce(PathBuf, Store) -> Fut,72+ F: FnOnce(Store) -> Fut,
73 Fut: Future<Output = ()>,73 Fut: Future<Output = ()>,
74 {74 {
75 let root = tempfile::tempdir().expect("temp dir");75 let root = tempfile::tempdir().expect("temp dir");
@@ -82,7 +82,7 @@ where
82 let store = Store::open(&dir.join("forge.db"))82 let store = Store::open(&dir.join("forge.db"))
83 .await83 .await
84 .expect("open store");84 .expect("open store");
85- seed(dir.clone(), store).await;85+ seed(store).await;
86 let (server, ports) = launch(&dir, ports).await;86 let (server, ports) = launch(&dir, ports).await;
87 Env {87 Env {
88 _root: root,88 _root: root,
@@ -93,7 +93,7 @@ where
93 93
94 /// `acme` is an org owned by tahinli, with a public repo, a session row, and an API token. None of94 /// `acme` is an org owned by tahinli, with a public repo, a session row, and an API token. None of
95 /// them may authenticate.95 /// them may authenticate.
96-async fn seed_org(_dir: PathBuf, store: Store) {96+async fn seed_org(store: Store) {
97 let tahinli = store97 let tahinli = store
98 .user_by_username("tahinli")98 .user_by_username("tahinli")
99 .await99 .await
@@ -129,20 +129,15 @@ async fn seed_org(_dir: PathBuf, store: Store) {
129 }129 }
130 130
131 #[tokio::test]131 #[tokio::test]
132-async fn an_org_cannot_sign_in_with_a_password() {132+async fn org_credentials_never_authenticate() {
133 let _guard = SERIAL.lock().await;133 let _guard = SERIAL.lock().await;
134 let env = start(seed_org).await;134 let env = start(seed_org).await;
135+
135 let res = try_login(&env.http, "acme").await;136 let res = try_login(&env.http, "acme").await;
136 assert_ne!(res.status, 303, "org login must not redirect: {}", res.body);137 assert_ne!(res.status, 303, "org login must not redirect: {}", res.body);
137 assert!(cookie_named(&res, "forge_session").is_none());138 assert!(cookie_named(&res, "forge_session").is_none());
138-}
139 139
140-#[tokio::test]
141-async fn an_org_session_signs_nobody_in() {
142- let _guard = SERIAL.lock().await;
143- let env = start(seed_org).await;
144 let cookie = format!("__Host-forge_session={ORG_SESSION}");140 let cookie = format!("__Host-forge_session={ORG_SESSION}");
145- // A page that needs a person answers the same with the org session as with no cookie.
146 let with_org = env.http.get("/new", Some(&cookie)).await;141 let with_org = env.http.get("/new", Some(&cookie)).await;
147 let without = env.http.get("/new", None).await;142 let without = env.http.get("/new", None).await;
148 assert_eq!(with_org.status, without.status);143 assert_eq!(with_org.status, without.status);
@@ -152,12 +147,7 @@ async fn an_org_session_signs_nobody_in() {
152 "a person is required: {}",147 "a person is required: {}",
153 with_org.body148 with_org.body
154 );149 );
155-}
156 150
157-#[tokio::test]
158-async fn an_org_api_token_is_refused() {
159- let _guard = SERIAL.lock().await;
160- let env = start(seed_org).await;
161 let res = env151 let res = env
162 .http152 .http
163 .client153 .client
@@ -171,12 +161,7 @@ async fn an_org_api_token_is_refused() {
171 .await161 .await
172 .expect("api request");162 .expect("api request");
173 assert_eq!(res.status().as_u16(), 401, "org API token must be refused");163 assert_eq!(res.status().as_u16(), 401, "org API token must be refused");
174-}
175 164
176-#[tokio::test]
177-async fn an_org_token_cannot_use_git_over_http_basic() {
178- let _guard = SERIAL.lock().await;
179- let env = start(seed_org).await;
180 let res = env165 let res = env
181 .http166 .http
182 .client167 .client
crates/forge-e2e/tests/e2e/orgs_ui_e2e.rsmodified+6 -14
@@ -4,8 +4,8 @@
4 //! handled by hand, as in `repo_collaborators_e2e.rs`.4 //! handled by hand, as in `repo_collaborators_e2e.rs`.
5 5
6 use crate::common::{6 use crate::common::{
7- Http, Resp, bin, describe, input_value, launch, launch_with, login, pick_ports, tool_on_path,7+ Http, Resp, bin, describe, input_value, launch, launch_with, login, pick_ports, temp_dir,
8- write_config,8+ tool_on_path, write_config,
9 };9 };
10 use std::fs;10 use std::fs;
11 use std::path::Path;11 use std::path::Path;
@@ -84,14 +84,6 @@ fn notice_location(redirect: &Resp) -> String {
84 redirect.header(LOCATION).expect("notice redirect")84 redirect.header(LOCATION).expect("notice redirect")
85 }85 }
86 86
87-/// A temp dir short enough for the unix socket path limit.
88-fn short_temp_dir() -> tempfile::TempDir {
89- tempfile::Builder::new()
90- .prefix("forg")
91- .tempdir_in("/tmp")
92- .expect("temp dir")
93-}
94-
95 #[tokio::test]87 #[tokio::test]
96 async fn org_members_teams_and_access_end_to_end() {88 async fn org_members_teams_and_access_end_to_end() {
97 let _guard = SERIAL.lock().await;89 let _guard = SERIAL.lock().await;
@@ -99,7 +91,7 @@ async fn org_members_teams_and_access_end_to_end() {
99 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");91 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");
100 return;92 return;
101 }93 }
102- let root = short_temp_dir();94+ let root = temp_dir("forg");
103 let dir = root.path().to_path_buf();95 let dir = root.path().to_path_buf();
104 let ports = pick_ports();96 let ports = pick_ports();
105 let config = write_config(&dir, ports);97 let config = write_config(&dir, ports);
@@ -329,7 +321,7 @@ async fn org_settings_delete_and_audit_end_to_end() {
329 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");321 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");
330 return;322 return;
331 }323 }
332- let root = short_temp_dir();324+ let root = temp_dir("forg");
333 let dir = root.path().to_path_buf();325 let dir = root.path().to_path_buf();
334 let ports = pick_ports();326 let ports = pick_ports();
335 let config = write_config(&dir, ports);327 let config = write_config(&dir, ports);
@@ -484,7 +476,7 @@ async fn org_settings_delete_and_audit_end_to_end() {
484 #[tokio::test]476 #[tokio::test]
485 async fn org_creation_can_be_limited_to_admins() {477 async fn org_creation_can_be_limited_to_admins() {
486 let _guard = SERIAL.lock().await;478 let _guard = SERIAL.lock().await;
487- let root = short_temp_dir();479+ let root = temp_dir("forg");
488 let dir = root.path().to_path_buf();480 let dir = root.path().to_path_buf();
489 let ports = pick_ports();481 let ports = pick_ports();
490 let config = write_config(&dir, ports);482 let config = write_config(&dir, ports);
@@ -630,7 +622,7 @@ async fn org_member_pushes_over_https_through_a_write_team() {
630 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");622 eprintln!("SKIP orgs_ui_e2e: `git` was not found on PATH");
631 return;623 return;
632 }624 }
633- let root = short_temp_dir();625+ let root = temp_dir("forg");
634 let dir = root.path().to_path_buf();626 let dir = root.path().to_path_buf();
635 let ports = pick_ports();627 let ports = pick_ports();
636 let config = write_config(&dir, ports);628 let config = write_config(&dir, ports);
crates/forge-e2e/tests/e2e/pulls_e2e.rsmodified+17 -69
@@ -6,7 +6,8 @@
6 //! a fork pull merged by squash, and a conflict that blocks the merge.6 //! a fork pull merged by squash, and a conflict that blocks the merge.
7 7
8 use crate::common::{8 use crate::common::{
9- Http, Resp, Server, bin, input_value, launch, login, pick_ports, tool_on_path, write_config,9+ Http, Resp, Server, create_token, input_value, launch, login, pick_ports, run_admin,
10+ tool_on_path, write_config,
10 };11 };
11 use std::fs;12 use std::fs;
12 use std::path::{Path, PathBuf};13 use std::path::{Path, PathBuf};
@@ -19,6 +20,8 @@ const TAHINLI_PW: &str = "tahinli-password-123";
19 const BOB_PW: &str = "bob-password-4567";20 const BOB_PW: &str = "bob-password-4567";
20 const BOB_EMAIL: &str = "bob@users.noreply.127.0.0.1";21 const BOB_EMAIL: &str = "bob@users.noreply.127.0.0.1";
21 const REPO_PATH: &str = "/tahinli/r";22 const REPO_PATH: &str = "/tahinli/r";
23+const TAHINLI: (&str, &str) = ("tahinli", "tahinli@example.test");
24+const BOB: (&str, &str) = ("bob", BOB_EMAIL);
22 25
23 /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`.26 /// Text of the first state badge on a page, e.g. `Open`, `Closed` or `Merged`.
24 fn state_badge(body: &str) -> String {27 fn state_badge(body: &str) -> String {
@@ -31,22 +34,6 @@ fn state_badge(body: &str) -> String {
31 .unwrap_or_default()34 .unwrap_or_default()
32 }35 }
33 36
34-fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) {
35- let out = Command::new(bin())
36- .arg("--config")
37- .arg(config)
38- .args(["admin", "create-user", username])
39- .args(extra)
40- .env("FORGE_PASSWORD", password)
41- .output()
42- .expect("run admin create-user");
43- assert!(
44- out.status.success(),
45- "create-user {username} failed:\n{}",
46- String::from_utf8_lossy(&out.stderr)
47- );
48-}
49-
50 /// Runs git with credential helpers disabled and extra env, returning stdout trimmed. Panics on37 /// Runs git with credential helpers disabled and extra env, returning stdout trimmed. Panics on
51 /// failure.38 /// failure.
52 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {39 fn git_env(cwd: &Path, args: &[&str], env: &[(&str, &str)]) -> String {
@@ -72,23 +59,17 @@ fn git(cwd: &Path, args: &[&str]) -> String {
72 }59 }
73 60
74 /// Writes `file`, commits it with `who` as author and committer, and returns the new HEAD.61 /// Writes `file`, commits it with `who` as author and committer, and returns the new HEAD.
75-fn commit(62+fn commit(repo: &Path, file: &str, contents: &str, message: &str, who: (&str, &str)) -> String {
76- repo: &Path,63+ let (name, email) = who;
77- file: &str,
78- contents: &str,
79- message: &str,
80- who: &str,
81- email: &str,
82-) -> String {
83 fs::write(repo.join(file), contents).expect("write file");64 fs::write(repo.join(file), contents).expect("write file");
84 git(repo, &["add", file]);65 git(repo, &["add", file]);
85 git_env(66 git_env(
86 repo,67 repo,
87 &["-c", "commit.gpgsign=false", "commit", "-q", "-m", message],68 &["-c", "commit.gpgsign=false", "commit", "-q", "-m", message],
88 &[69 &[
89- ("GIT_AUTHOR_NAME", who),70+ ("GIT_AUTHOR_NAME", name),
90 ("GIT_AUTHOR_EMAIL", email),71 ("GIT_AUTHOR_EMAIL", email),
91- ("GIT_COMMITTER_NAME", who),72+ ("GIT_COMMITTER_NAME", name),
92 ("GIT_COMMITTER_EMAIL", email),73 ("GIT_COMMITTER_EMAIL", email),
93 ],74 ],
94 );75 );
@@ -132,30 +113,6 @@ async fn csrf_token(http: &Http, session: &str) -> String {
132 input_value(&page.body, "csrf")113 input_value(&page.body, "csrf")
133 }114 }
134 115
135-/// Creates an access token through `/settings/tokens` and returns the token shown once.
136-async fn create_token(http: &Http, session: &str, name: &str) -> String {
137- let csrf = csrf_token(http, session).await;
138- let res = http
139- .post_form(
140- "/settings/tokens",
141- &[("csrf", &csrf), ("name", name), ("expires", "30")],
142- Some(session),
143- )
144- .await;
145- assert_eq!(res.status, 200, "create token: {}", res.body);
146- let doc = scraper::Html::parse_document(&res.body);
147- let selector = scraper::Selector::parse("pre.code code").expect("selector");
148- let token: String = doc
149- .select(&selector)
150- .next()
151- .expect("token shown after creation")
152- .text()
153- .collect();
154- let token = token.trim().to_owned();
155- assert!(token.starts_with("forge_"), "unexpected token shape");
156- token
157-}
158-
159 /// Creates a public repo `name` owned by tahinli through `/new`.116 /// Creates a public repo `name` owned by tahinli through `/new`.
160 async fn create_repo(http: &Http, session: &str, name: &str) {117 async fn create_repo(http: &Http, session: &str, name: &str) {
161 let page = http.get_cookie("/new", session).await;118 let page = http.get_cookie("/new", session).await;
@@ -236,8 +193,7 @@ async fn tahinli_repo_with_main(b: &Booted) -> (String, String, PathBuf) {
236 "base.txt",193 "base.txt",
237 "base\n",194 "base\n",
238 "base commit",195 "base commit",
239- "tahinli",196+ TAHINLI,
240- "tahinli@example.test",
241 );197 );
242 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/main"]);198 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/main"]);
243 (tahinli, token, work)199 (tahinli, token, work)
@@ -343,8 +299,7 @@ async fn same_repo_pull_merges_and_closes_issue() {
343 "x.txt",299 "x.txt",
344 "x\n",300 "x\n",
345 "Add x\n\nFixes #1",301 "Add x\n\nFixes #1",
346- "tahinli",302+ TAHINLI,
347- "tahinli@example.test",
348 );303 );
349 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature"]);304 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature"]);
350 305
@@ -410,8 +365,7 @@ async fn push_to_head_branch_updates_open_pull() {
410 "one.txt",365 "one.txt",
411 "1\n",366 "1\n",
412 "first on feature2",367 "first on feature2",
413- "tahinli",368+ TAHINLI,
414- "tahinli@example.test",
415 );369 );
416 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature2"]);370 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature2"]);
417 let number = open_pull(&b.http, &tahinli, "main", "feature2", "Feature two").await;371 let number = open_pull(&b.http, &tahinli, "main", "feature2", "Feature two").await;
@@ -421,8 +375,7 @@ async fn push_to_head_branch_updates_open_pull() {
421 "two.txt",375 "two.txt",
422 "2\n",376 "2\n",
423 "second on feature2",377 "second on feature2",
424- "tahinli",378+ TAHINLI,
425- "tahinli@example.test",
426 );379 );
427 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature2"]);380 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/feature2"]);
428 381
@@ -496,8 +449,7 @@ async fn pull_pages_follow_writes_live() {
496 "live.txt",449 "live.txt",
497 "live\n",450 "live\n",
498 "first on live",451 "first on live",
499- "tahinli",452+ TAHINLI,
500- "tahinli@example.test",
501 );453 );
502 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/live"]);454 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/live"]);
503 let number = open_pull(&b.http, &tahinli, "main", "live", "Live pull").await;455 let number = open_pull(&b.http, &tahinli, "main", "live", "Live pull").await;
@@ -567,8 +519,7 @@ async fn pull_pages_follow_writes_live() {
567 "second.txt",519 "second.txt",
568 "2\n",520 "2\n",
569 "second on live",521 "second on live",
570- "tahinli",522+ TAHINLI,
571- "tahinli@example.test",
572 );523 );
573 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/live"]);524 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/live"]);
574 next_changed(&mut pull_events, "a push to the head").await;525 next_changed(&mut pull_events, "a push to the head").await;
@@ -647,8 +598,7 @@ async fn fork_pull_squash_merge_credits_contributor() {
647 "bob.txt",598 "bob.txt",
648 "bob\n",599 "bob\n",
649 "Bob change",600 "Bob change",
650- "bob",601+ BOB,
651- BOB_EMAIL,
652 );602 );
653 git(603 git(
654 &bob_work,604 &bob_work,
@@ -688,8 +638,7 @@ async fn conflicting_pull_cannot_merge() {
688 "shared.txt",638 "shared.txt",
689 "branch side\n",639 "branch side\n",
690 "branch edit",640 "branch edit",
691- "tahinli",641+ TAHINLI,
692- "tahinli@example.test",
693 );642 );
694 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/conflict"]);643 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/conflict"]);
695 let number = open_pull(&b.http, &tahinli, "main", "conflict", "Conflicting").await;644 let number = open_pull(&b.http, &tahinli, "main", "conflict", "Conflicting").await;
@@ -700,8 +649,7 @@ async fn conflicting_pull_cannot_merge() {
700 "shared.txt",649 "shared.txt",
701 "main side\n",650 "main side\n",
702 "main edit",651 "main edit",
703- "tahinli",652+ TAHINLI,
704- "tahinli@example.test",
705 );653 );
706 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/main"]);654 git(&work, &["push", "-q", "origin", "HEAD:refs/heads/main"]);
707 655
crates/forge-e2e/tests/e2e/repo_collaborators_e2e.rsmodified+7 -9
@@ -3,7 +3,7 @@
3 //! its POST forms over HTTP. Cookies are handled by hand (see `repo_settings_e2e.rs`).3 //! its POST forms over HTTP. Cookies are handled by hand (see `repo_settings_e2e.rs`).
4 4
5 use crate::common::{5 use crate::common::{
6- Http, Resp, bin, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path,6+ Http, bin, describe, input_value, launch, login, pick_ports, tool_on_path, with_cookie,
7 write_config,7 write_config,
8 };8 };
9 use std::fs;9 use std::fs;
@@ -69,12 +69,6 @@ async fn shown_role(http: &Http, session: &str, username: &str) -> Option<String
69 .map(str::to_owned)69 .map(str::to_owned)
70 }70 }
71 71
72-/// The one-shot notice cookie from a redirect, joined with the session cookie for the next GET.
73-fn with_notice(session: &str, redirect: &Resp) -> String {
74- let notice = cookie_named(redirect, "forge_collab_notice").expect("notice cookie");
75- format!("{session}; {notice}")
76-}
77-
78 #[tokio::test]72 #[tokio::test]
79 async fn repo_collaborators_end_to_end() {73 async fn repo_collaborators_end_to_end() {
80 if !tool_on_path("git") {74 if !tool_on_path("git") {
@@ -249,7 +243,9 @@ async fn repo_collaborators_end_to_end() {
249 )243 )
250 .await;244 .await;
251 assert_eq!(res.status, 303, "unknown user redirects with a notice");245 assert_eq!(res.status, 303, "unknown user redirects with a notice");
252- let notice_page = http.get(page, Some(&with_notice(&olivia, &res))).await;246+ let notice_page = http
247+ .get(page, Some(&with_cookie(&olivia, &res, "forge_collab_notice")))
248+ .await;
253 assert!(249 assert!(
254 notice_page.body.contains("No user has that username."),250 notice_page.body.contains("No user has that username."),
255 "unknown user notice missing"251 "unknown user notice missing"
@@ -261,7 +257,9 @@ async fn repo_collaborators_end_to_end() {
261 Some(&olivia),257 Some(&olivia),
262 )258 )
263 .await;259 .await;
264- let notice_page = http.get(page, Some(&with_notice(&olivia, &res))).await;260+ let notice_page = http
261+ .get(page, Some(&with_cookie(&olivia, &res, "forge_collab_notice")))
262+ .await;
265 assert!(263 assert!(
266 notice_page264 notice_page
267 .body265 .body
crates/forge-e2e/tests/e2e/repo_settings_e2e.rsmodified+4 -69
@@ -1,12 +1,6 @@
1-//! Black-box test for repo deletion. It starts the real `forge` binary, seeds repos through the
2-//! store before the server starts, and then drives the settings page and the delete form over HTTP.
3-//!
4-//! Cookies are handled by hand because the session cookie is `__Host-forge_session` with `Secure`,
5-//! which a cookie jar would not send over plain http.
6-
7 use crate::common::{1 use crate::common::{
8- Http, Resp, bin, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path,2+ Http, bin, cookie_named, describe, input_value, launch, login, pick_ports, tool_on_path,
9- write_config,3+ with_cookie, write_config,
10 };4 };
11 use std::fs;5 use std::fs;
12 use std::path::{Path, PathBuf};6 use std::path::{Path, PathBuf};
@@ -17,7 +11,6 @@ use reqwest::header::LOCATION;
17 11
18 const PW: &str = "tahinli-password-123";12 const PW: &str = "tahinli-password-123";
19 13
20-/// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
21 fn admin(config: &Path, args: &[&str]) -> Output {14 fn admin(config: &Path, args: &[&str]) -> Output {
22 let out = Command::new(bin())15 let out = Command::new(bin())
23 .arg("--config")16 .arg("--config")
@@ -35,14 +28,12 @@ fn admin(config: &Path, args: &[&str]) -> Output {
35 out28 out
36 }29 }
37 30
38-/// The session's CSRF token, read from a page every signed-in user can open.
39 async fn csrf_for(http: &Http, session: &str) -> String {31 async fn csrf_for(http: &Http, session: &str) -> String {
40 let page = http.get("/settings/keys", Some(session)).await;32 let page = http.get("/settings/keys", Some(session)).await;
41 assert_eq!(page.status, 200, "GET /settings/keys");33 assert_eq!(page.status, 200, "GET /settings/keys");
42 input_value(&page.body, "csrf")34 input_value(&page.body, "csrf")
43 }35 }
44 36
45-/// Creates a bare git repo for `repo_id` at its data-dir location, as the create-repo page does.
46 fn init_bare(data_dir: &Path, repo_id: &str) {37 fn init_bare(data_dir: &Path, repo_id: &str) {
47 let path = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");38 let path = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");
48 fs::create_dir_all(path.parent().expect("parent")).expect("create repo parent");39 fs::create_dir_all(path.parent().expect("parent")).expect("create repo parent");
@@ -54,7 +45,6 @@ fn init_bare(data_dir: &Path, repo_id: &str) {
54 assert!(out.status.success(), "git init --bare: {}", describe(&out));45 assert!(out.status.success(), "git init --bare: {}", describe(&out));
55 }46 }
56 47
57-/// Directories in `data_dir/trash` for the repo `id` (lowercase, as the trash names them).
58 fn trash_entries(data_dir: &Path, repo_id: &str) -> Vec<PathBuf> {48 fn trash_entries(data_dir: &Path, repo_id: &str) -> Vec<PathBuf> {
59 let prefix = format!("{}-", repo_id.to_ascii_lowercase());49 let prefix = format!("{}-", repo_id.to_ascii_lowercase());
60 let Ok(read) = fs::read_dir(data_dir.join(forge_git::repo::TRASH_DIR)) else {50 let Ok(read) = fs::read_dir(data_dir.join(forge_git::repo::TRASH_DIR)) else {
@@ -77,7 +67,6 @@ async fn repo_settings_end_to_end() {
77 return;67 return;
78 }68 }
79 69
80- // Keep the path short: the data dir holds a unix socket with a length limit.
81 let root = tempfile::Builder::new()70 let root = tempfile::Builder::new()
82 .prefix("frs")71 .prefix("frs")
83 .tempdir_in("/tmp")72 .tempdir_in("/tmp")
@@ -87,8 +76,6 @@ async fn repo_settings_end_to_end() {
87 let ports = pick_ports();76 let ports = pick_ports();
88 let config = write_config(&dir, ports);77 let config = write_config(&dir, ports);
89 78
90- // The first user is an admin. Bob owns the repos, carol is an admin collaborator on the private
91- // one, and tahinli (admin) must still be able to delete bob's repo.
92 admin(&config, &["create-user", "tahinli", "--admin"]);79 admin(&config, &["create-user", "tahinli", "--admin"]);
93 admin(&config, &["create-user", "bob"]);80 admin(&config, &["create-user", "bob"]);
94 admin(&config, &["create-user", "carol"]);81 admin(&config, &["create-user", "carol"]);
@@ -127,12 +114,9 @@ async fn repo_settings_end_to_end() {
127 let carol = login(&http, "carol", PW).await;114 let carol = login(&http, "carol", PW).await;
128 let tahinli = login(&http, "tahinli", PW).await;115 let tahinli = login(&http, "tahinli", PW).await;
129 116
130- // Anonymous on a private repo: 404, the same as a missing repo.
131 let anon = http.get("/bob/priv/settings", None).await;117 let anon = http.get("/bob/priv/settings", None).await;
132 assert_eq!(anon.status, 404, "anonymous settings on private repo");118 assert_eq!(anon.status, 404, "anonymous settings on private repo");
133 119
134- // A collaborator with the Admin role gets the settings page (branch rules) but no danger zone,
135- // and a POST to the delete form is 403. The repo stays.
136 let carol_page = http120 let carol_page = http
137 .get("/bob/priv/settings?section=danger", Some(&carol))121 .get("/bob/priv/settings?section=danger", Some(&carol))
138 .await;122 .await;
@@ -152,7 +136,6 @@ async fn repo_settings_end_to_end() {
152 assert_eq!(carol_delete.status, 403, "collaborator delete");136 assert_eq!(carol_delete.status, 403, "collaborator delete");
153 assert_eq!(http.get("/bob/priv", Some(&carol)).await.status, 200);137 assert_eq!(http.get("/bob/priv", Some(&carol)).await.status, 200);
154 138
155- // The owner sees the danger zone, and the Settings tab appears on the repo header.
156 let owner_page = http139 let owner_page = http
157 .get("/bob/pub/settings?section=danger", Some(&bob))140 .get("/bob/pub/settings?section=danger", Some(&bob))
158 .await;141 .await;
@@ -173,7 +156,6 @@ async fn repo_settings_end_to_end() {
173 "Settings tab shows to an Admin collaborator"156 "Settings tab shows to an Admin collaborator"
174 );157 );
175 158
176- // A wrong confirmation is an error and keeps the repo.
177 let owner_csrf = csrf_for(&http, &bob).await;159 let owner_csrf = csrf_for(&http, &bob).await;
178 let wrong = http160 let wrong = http
179 .post_form(161 .post_form(
@@ -197,7 +179,6 @@ async fn repo_settings_end_to_end() {
197 "nothing trashed on mismatch"179 "nothing trashed on mismatch"
198 );180 );
199 181
200- // No CSRF token is rejected, even with the right confirmation.
201 let no_csrf = http182 let no_csrf = http
202 .post_form(183 .post_form(
203 "/bob/pub/settings/delete",184 "/bob/pub/settings/delete",
@@ -212,7 +193,6 @@ async fn repo_settings_end_to_end() {
212 "repo kept without CSRF"193 "repo kept without CSRF"
213 );194 );
214 195
215- // The owner deletes: redirect home with a notice, the repo is gone, the directory is trashed.
216 let deleted = http196 let deleted = http
217 .post_form(197 .post_form(
218 "/bob/pub/settings/delete",198 "/bob/pub/settings/delete",
@@ -246,7 +226,6 @@ async fn repo_settings_end_to_end() {
246 "trash entry is a bare repo"226 "trash entry is a bare repo"
247 );227 );
248 228
249- // The home page is the signed-in viewer's own page, not a redirect.
250 let home = http.get("/", Some(&bob)).await;229 let home = http.get("/", Some(&bob)).await;
251 assert_eq!(home.status, 200, "home page for a signed-in viewer");230 assert_eq!(home.status, 200, "home page for a signed-in viewer");
252 assert!(231 assert!(
@@ -254,7 +233,6 @@ async fn repo_settings_end_to_end() {
254 "home lists their repositories"233 "home lists their repositories"
255 );234 );
256 235
257- // An admin who does not own the repo can delete it.
258 let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await;236 let admin_page = http.get("/bob/priv/settings", Some(&tahinli)).await;
259 assert_eq!(admin_page.status, 200, "admin settings page");237 assert_eq!(admin_page.status, 200, "admin settings page");
260 let admin_csrf = csrf_for(&http, &tahinli).await;238 let admin_csrf = csrf_for(&http, &tahinli).await;
@@ -277,7 +255,6 @@ async fn repo_settings_end_to_end() {
277 "admin delete is trashed"255 "admin delete is trashed"
278 );256 );
279 257
280- // The admin CLI lists both trash entries, then purges them.
281 let listed = String::from_utf8_lossy(&admin(&config, &["trash-list"]).stdout).into_owned();258 let listed = String::from_utf8_lossy(&admin(&config, &["trash-list"]).stdout).into_owned();
282 assert!(259 assert!(
283 listed.contains(&public_id.to_ascii_lowercase()),260 listed.contains(&public_id.to_ascii_lowercase()),
@@ -298,8 +275,6 @@ async fn repo_settings_end_to_end() {
298 drop(server);275 drop(server);
299 }276 }
300 277
301-/// A repo whose bare directory was removed by hand can still be deleted from the UI: the DB rows
302-/// go, nothing is trashed, and the request succeeds.
303 #[tokio::test]278 #[tokio::test]
304 async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {279 async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {
305 if !tool_on_path("git") {280 if !tool_on_path("git") {
@@ -327,7 +302,6 @@ async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {
327 .expect("repo");302 .expect("repo");
328 init_bare(&dir, &repo.id);303 init_bare(&dir, &repo.id);
329 let bare = forge_git::repo::repo_path(&dir, &repo.id).expect("repo path");304 let bare = forge_git::repo::repo_path(&dir, &repo.id).expect("repo path");
330- // Simulate the broken state: the DB row exists but the bare directory is gone.
331 fs::remove_dir_all(&bare).expect("remove bare dir by hand");305 fs::remove_dir_all(&bare).expect("remove bare dir by hand");
332 (repo.id, bare)306 (repo.id, bare)
333 };307 };
@@ -362,7 +336,6 @@ async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {
362 trash_entries(&dir, &repo_id).is_empty(),336 trash_entries(&dir, &repo_id).is_empty(),
363 "nothing to trash when the dir is missing"337 "nothing to trash when the dir is missing"
364 );338 );
365- // Stop the server first: the database file is locked while it runs.
366 drop(server);339 drop(server);
367 let store = Store::open(&dir.join("forge.db"))340 let store = Store::open(&dir.join("forge.db"))
368 .await341 .await
@@ -378,12 +351,8 @@ async fn repo_settings_deletes_rows_when_repo_dir_is_missing() {
378 );351 );
379 }352 }
380 353
381-/// The rule rows of the branch rules list in page order, each as its pattern followed by the texts
382-/// of its summary pills. The built-in default-branch row has no rule behind it, so it is skipped.
383 fn branch_rows(body: &str) -> Vec<Vec<String>> {354 fn branch_rows(body: &str) -> Vec<Vec<String>> {
384 let doc = scraper::Html::parse_document(body);355 let doc = scraper::Html::parse_document(body);
385- // Every rule row is a `details` with the pattern in its summary's name; the "Add rule" row
386- // has no pattern there, so it drops out.
387 let cards = scraper::Selector::parse("details.row-open").expect("selector");356 let cards = scraper::Selector::parse("details.row-open").expect("selector");
388 let pattern = scraper::Selector::parse("summary .name code").expect("selector");357 let pattern = scraper::Selector::parse("summary .name code").expect("selector");
389 let pills = scraper::Selector::parse("summary .rule-pills span").expect("selector");358 let pills = scraper::Selector::parse("summary .rule-pills span").expect("selector");
@@ -398,15 +367,12 @@ fn branch_rows(body: &str) -> Vec<Vec<String>> {
398 .collect()367 .collect()
399 }368 }
400 369
401-/// The row for `pattern` as its cells (see `branch_rows`), if the list has one.
402 fn rule_row(body: &str, pattern: &str) -> Option<Vec<String>> {370 fn rule_row(body: &str, pattern: &str) -> Option<Vec<String>> {
403 branch_rows(body)371 branch_rows(body)
404 .into_iter()372 .into_iter()
405 .find(|cells| cells.first().is_some_and(|c| c == pattern))373 .find(|cells| cells.first().is_some_and(|c| c == pattern))
406 }374 }
407 375
408-/// Owner adds, updates, invalidates and removes branch rules. A Write collaborator and an Admin
409-/// collaborator get the right access: the Admin can manage rules but sees no danger zone.
410 #[tokio::test]376 #[tokio::test]
411 async fn branch_protection_end_to_end() {377 async fn branch_protection_end_to_end() {
412 if !tool_on_path("git") {378 if !tool_on_path("git") {
@@ -422,7 +388,6 @@ async fn branch_protection_end_to_end() {
422 let ports = pick_ports();388 let ports = pick_ports();
423 let config = write_config(&dir, ports);389 let config = write_config(&dir, ports);
424 390
425- // The first user is an instance admin, so bob (the owner) is an ordinary user.
426 admin(&config, &["create-user", "tahinli", "--admin"]);391 admin(&config, &["create-user", "tahinli", "--admin"]);
427 admin(&config, &["create-user", "bob"]);392 admin(&config, &["create-user", "bob"]);
428 admin(&config, &["create-user", "carol"]);393 admin(&config, &["create-user", "carol"]);
@@ -460,7 +425,6 @@ async fn branch_protection_end_to_end() {
460 let carol = login(&http, "carol", PW).await;425 let carol = login(&http, "carol", PW).await;
461 let dan = login(&http, "dan", PW).await;426 let dan = login(&http, "dan", PW).await;
462 427
463- // Owner: the built-in row is there before any rule, and the danger zone is shown.
464 let page = http428 let page = http
465 .get("/bob/app/settings?section=branches", Some(&bob))429 .get("/bob/app/settings?section=branches", Some(&bob))
466 .await;430 .await;
@@ -484,7 +448,6 @@ async fn branch_protection_end_to_end() {
484 );448 );
485 let owner_csrf = csrf_for(&http, &bob).await;449 let owner_csrf = csrf_for(&http, &bob).await;
486 450
487- // Adding main with force push allowed: it appears, and the built-in row disappears.
488 let added = http451 let added = http
489 .post_form(452 .post_form(
490 "/bob/app/settings/branches",453 "/bob/app/settings/branches",
@@ -522,7 +485,6 @@ async fn branch_protection_end_to_end() {
522 "built-in row must disappear once a rule matches"485 "built-in row must disappear once a rule matches"
523 );486 );
524 487
525- // Updating the same pattern toggles the value and does not add a second row.
526 let updated = http488 let updated = http
527 .post_form(489 .post_form(
528 "/bob/app/settings/branches",490 "/bob/app/settings/branches",
@@ -536,7 +498,6 @@ async fn branch_protection_end_to_end() {
536 .await;498 .await;
537 assert_eq!(updated.status, 303, "update rule: {}", updated.body);499 assert_eq!(updated.status, 303, "update rule: {}", updated.body);
538 500
539- // Adding a new rule for a pattern that has one is refused instead of overwriting it.
540 let duplicate = http501 let duplicate = http
541 .post_form(502 .post_form(
542 "/bob/app/settings/branches",503 "/bob/app/settings/branches",
@@ -563,7 +524,6 @@ async fn branch_protection_end_to_end() {
563 "update must not add a row"524 "update must not add a row"
564 );525 );
565 526
566- // An invalid pattern is refused inline and nothing is saved.
567 let invalid = http527 let invalid = http
568 .post_form(528 .post_form(
569 "/bob/app/settings/branches",529 "/bob/app/settings/branches",
@@ -592,7 +552,6 @@ async fn branch_protection_end_to_end() {
592 "invalid rule must not be saved"552 "invalid rule must not be saved"
593 );553 );
594 554
595- // No CSRF token is rejected.
596 let no_csrf = http555 let no_csrf = http
597 .post_form(556 .post_form(
598 "/bob/app/settings/branches",557 "/bob/app/settings/branches",
@@ -621,7 +580,6 @@ async fn branch_protection_end_to_end() {
621 "main kept without CSRF"580 "main kept without CSRF"
622 );581 );
623 582
624- // Remove works: the row goes and the built-in row comes back.
625 let rule_id = input_value(&page.body, "rule_id");583 let rule_id = input_value(&page.body, "rule_id");
626 let removed = http584 let removed = http
627 .post_form(585 .post_form(
@@ -640,7 +598,6 @@ async fn branch_protection_end_to_end() {
640 "built-in row back after remove"598 "built-in row back after remove"
641 );599 );
642 600
643- // A Write collaborator cannot open the settings or post rules.
644 let dan_page = http601 let dan_page = http
645 .get("/bob/app/settings?section=branches", Some(&dan))602 .get("/bob/app/settings?section=branches", Some(&dan))
646 .await;603 .await;
@@ -662,7 +619,6 @@ async fn branch_protection_end_to_end() {
662 "write collaborator must not change rules"619 "write collaborator must not change rules"
663 );620 );
664 621
665- // An Admin collaborator manages rules, sees no danger zone and cannot delete the repo.
666 let carol_page = http622 let carol_page = http
667 .get("/bob/app/settings?section=branches", Some(&carol))623 .get("/bob/app/settings?section=branches", Some(&carol))
668 .await;624 .await;
@@ -744,7 +700,6 @@ async fn branch_protection_end_to_end() {
744 drop(server);700 drop(server);
745 }701 }
746 702
747-/// Creates commits in a scratch work tree and pushes them as `branches` into the bare repo.
748 fn seed_branches(dir: &Path, repo_id: &str, branches: &[&str]) {703 fn seed_branches(dir: &Path, repo_id: &str, branches: &[&str]) {
749 let bare = forge_git::repo::repo_path(dir, repo_id).expect("repo path");704 let bare = forge_git::repo::repo_path(dir, repo_id).expect("repo path");
750 let work = dir.join(format!("seed-{repo_id}"));705 let work = dir.join(format!("seed-{repo_id}"));
@@ -778,7 +733,6 @@ fn seed_branches(dir: &Path, repo_id: &str, branches: &[&str]) {
778 run(&push);733 run(&push);
779 }734 }
780 735
781-/// The symbolic target of HEAD in the bare repo, e.g. `refs/heads/dev`.
782 fn git_head(data_dir: &Path, repo_id: &str) -> String {736 fn git_head(data_dir: &Path, repo_id: &str) -> String {
783 let bare = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");737 let bare = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");
784 let out = Command::new("git")738 let out = Command::new("git")
@@ -791,7 +745,6 @@ fn git_head(data_dir: &Path, repo_id: &str) -> String {
791 String::from_utf8_lossy(&out.stdout).trim().to_owned()745 String::from_utf8_lossy(&out.stdout).trim().to_owned()
792 }746 }
793 747
794-/// The value of the `selected` option of the default-branch select, if the page has one.
795 fn selected_branch(body: &str) -> Option<String> {748 fn selected_branch(body: &str) -> Option<String> {
796 let doc = scraper::Html::parse_document(body);749 let doc = scraper::Html::parse_document(body);
797 let selector =750 let selector =
@@ -802,14 +755,6 @@ fn selected_branch(body: &str) -> Option<String> {
802 .map(str::to_owned)755 .map(str::to_owned)
803 }756 }
804 757
805-/// Cookie header with the session plus a one-shot settings notice set by the previous response.
806-fn with_notice(session: &str, res: &Resp) -> String {
807- match cookie_named(res, "forge_settings_notice") {
808- Some(notice) => format!("{session}; {notice}"),
809- None => session.to_owned(),
810- }
811-}
812-
813 #[tokio::test]758 #[tokio::test]
814 async fn general_settings_end_to_end() {759 async fn general_settings_end_to_end() {
815 if !tool_on_path("git") {760 if !tool_on_path("git") {
@@ -862,7 +807,6 @@ async fn general_settings_end_to_end() {
862 let bob = login(&http, "bob", PW).await;807 let bob = login(&http, "bob", PW).await;
863 let carol = login(&http, "carol", PW).await;808 let carol = login(&http, "carol", PW).await;
864 809
865- // The General section is the first card on the page, with the sub-navigation above it.
866 let page = http.get("/bob/gen/settings", Some(&bob)).await;810 let page = http.get("/bob/gen/settings", Some(&bob)).await;
867 assert_eq!(page.status, 200, "owner settings page");811 assert_eq!(page.status, 200, "owner settings page");
868 assert!(812 assert!(
@@ -879,7 +823,6 @@ async fn general_settings_end_to_end() {
879 .contains("href=\"/bob/gen/settings?section=danger\"")823 .contains("href=\"/bob/gen/settings?section=danger\"")
880 );824 );
881 825
882- // Description: control characters are stripped and it shows on the repo header.
883 let csrf = csrf_for(&http, &bob).await;826 let csrf = csrf_for(&http, &bob).await;
884 let saved = http827 let saved = http
885 .post_form(828 .post_form(
@@ -899,7 +842,6 @@ async fn general_settings_end_to_end() {
899 "description not on header"842 "description not on header"
900 );843 );
901 844
902- // Default branch: an existing branch updates the DB value and git HEAD.
903 let switched = http845 let switched = http
904 .post_form(846 .post_form(
905 "/bob/gen/settings/general",847 "/bob/gen/settings/general",
@@ -916,7 +858,6 @@ async fn general_settings_end_to_end() {
916 let after = http.get("/bob/gen/settings", Some(&bob)).await;858 let after = http.get("/bob/gen/settings", Some(&bob)).await;
917 assert_eq!(selected_branch(&after.body).as_deref(), Some("dev"));859 assert_eq!(selected_branch(&after.body).as_deref(), Some("dev"));
918 860
919- // A nonexistent branch is rejected: HEAD and the DB keep dev.
920 let missing = http861 let missing = http
921 .post_form(862 .post_form(
922 "/bob/gen/settings/general",863 "/bob/gen/settings/general",
@@ -930,7 +871,7 @@ async fn general_settings_end_to_end() {
930 .await;871 .await;
931 assert_eq!(missing.status, 303);872 assert_eq!(missing.status, 303);
932 let notice_page = http873 let notice_page = http
933- .get("/bob/gen/settings", Some(&with_notice(&bob, &missing)))874+ .get("/bob/gen/settings", Some(&with_cookie(&bob, &missing, "forge_settings_notice")))
934 .await;875 .await;
935 assert!(876 assert!(
936 notice_page.body.contains("That branch does not exist"),877 notice_page.body.contains("That branch does not exist"),
@@ -942,7 +883,6 @@ async fn general_settings_end_to_end() {
942 Some("dev")883 Some("dev")
943 );884 );
944 885
945- // Over-long description is rejected.
946 let long = "x".repeat(351);886 let long = "x".repeat(351);
947 let too_long = http887 let too_long = http
948 .post_form(888 .post_form(
@@ -957,11 +897,10 @@ async fn general_settings_end_to_end() {
957 .await;897 .await;
958 assert_eq!(too_long.status, 303);898 assert_eq!(too_long.status, 303);
959 let long_page = http899 let long_page = http
960- .get("/bob/gen/settings", Some(&with_notice(&bob, &too_long)))900+ .get("/bob/gen/settings", Some(&with_cookie(&bob, &too_long, "forge_settings_notice")))
961 .await;901 .await;
962 assert!(long_page.body.contains("at most 350 characters"));902 assert!(long_page.body.contains("at most 350 characters"));
963 903
964- // Visibility: changing to private needs "I understand"; then anonymous gets 404.
965 let vis_csrf = csrf_for(&http, &bob).await;904 let vis_csrf = csrf_for(&http, &bob).await;
966 let no_ack = http905 let no_ack = http
967 .post_form(906 .post_form(
@@ -1016,7 +955,6 @@ async fn general_settings_end_to_end() {
1016 "anonymous on public"955 "anonymous on public"
1017 );956 );
1018 957
1019- // Archive, then unarchive. The banner shows only while archived.
1020 let arch_csrf = csrf_for(&http, &bob).await;958 let arch_csrf = csrf_for(&http, &bob).await;
1021 let archive = http959 let archive = http
1022 .post_form(960 .post_form(
@@ -1050,7 +988,6 @@ async fn general_settings_end_to_end() {
1050 "banner after unarchive"988 "banner after unarchive"
1051 );989 );
1052 990
1053- // A Write collaborator cannot reach the settings: GET and every POST are 403.
1054 let carol_page = http.get("/bob/gen/settings", Some(&carol)).await;991 let carol_page = http.get("/bob/gen/settings", Some(&carol)).await;
1055 assert_eq!(carol_page.status, 403, "write collaborator settings page");992 assert_eq!(carol_page.status, 403, "write collaborator settings page");
1056 let carol_csrf = csrf_for(&http, &carol).await;993 let carol_csrf = csrf_for(&http, &carol).await;
@@ -1080,7 +1017,6 @@ async fn general_settings_end_to_end() {
1080 "HEAD untouched by carol"1017 "HEAD untouched by carol"
1081 );1018 );
1082 1019
1083- // No CSRF token, or a wrong one, is rejected on every General POST.
1084 let no_csrf = http1020 let no_csrf = http
1085 .post_form(1021 .post_form(
1086 "/bob/gen/settings/general",1022 "/bob/gen/settings/general",
@@ -1107,7 +1043,6 @@ async fn general_settings_end_to_end() {
1107 "visibility unchanged"1043 "visibility unchanged"
1108 );1044 );
1109 1045
1110- // An empty repo says so and keeps the current value.
1111 let empty_page = http.get("/bob/empty/settings", Some(&bob)).await;1046 let empty_page = http.get("/bob/empty/settings", Some(&bob)).await;
1112 assert!(1047 assert!(
1113 empty_page.body.contains("No branches yet"),1048 empty_page.body.contains("No branches yet"),
crates/forge-e2e/tests/e2e/section_nav_e2e.rsmodified+0 -97
@@ -1,97 +1,9 @@
1-//! Black-box tests for the admin and settings section tabs: every page under `/admin` and
2-//! `/settings` shows the section's own tab row above the page, marks the current tab with
3-//! `aria-current="page"`, and has no " · "-joined link row.
4-
5-#![allow(dead_code)]
6-
7 use crate::common::{Http, Server, bin, describe, launch, login, pick_ports, write_config};1 use crate::common::{Http, Server, bin, describe, launch, login, pick_ports, write_config};
8 use std::path::Path;2 use std::path::Path;
9 use std::process::Command;3 use std::process::Command;
10 4
11 const PW: &str = "tahinli-password-123";5 const PW: &str = "tahinli-password-123";
12 6
13-/// The `data-theme` attribute of `<html>`, if the page sets one.
14-fn html_theme(body: &str) -> Option<String> {
15- let doc = scraper::Html::parse_document(body);
16- doc.root_element().attr("data-theme").map(str::to_owned)
17-}
18-
19-/// The value of attribute `name` on `<html>`, if the page sets it.
20-fn html_attr(body: &str, name: &str) -> Option<String> {
21- let doc = scraper::Html::parse_document(body);
22- doc.root_element().attr(name).map(str::to_owned)
23-}
24-
25-/// The four colour attributes of `<html>`, in the order light accent, dark accent, light base,
26-/// dark base.
27-fn html_colours(body: &str) -> [Option<String>; 4] {
28- [
29- html_attr(body, "data-accent-light"),
30- html_attr(body, "data-accent-dark"),
31- html_attr(body, "data-base-light"),
32- html_attr(body, "data-base-dark"),
33- ]
34-}
35-
36-/// The checked radio of each colour group, in the same order as `html_colours`.
37-fn checked_colours(body: &str) -> [Option<String>; 4] {
38- [
39- checked_radio(body, "accent_light"),
40- checked_radio(body, "accent_dark"),
41- checked_radio(body, "base_light"),
42- checked_radio(body, "base_dark"),
43- ]
44-}
45-
46-/// The value of the checked radio button in the group `name` on a page.
47-fn checked_radio(body: &str, name: &str) -> Option<String> {
48- let doc = scraper::Html::parse_document(body);
49- let selector =
50- scraper::Selector::parse(&format!("input[type=\"radio\"][name=\"{name}\"][checked]"))
51- .expect("selector");
52- doc.select(&selector)
53- .next()
54- .and_then(|el| el.value().attr("value"))
55- .map(str::to_owned)
56-}
57-
58-/// The option value that is selected in the `<select name="...">` on a page.
59-fn selected_option(body: &str, select: &str) -> Option<String> {
60- let doc = scraper::Html::parse_document(body);
61- let selector = scraper::Selector::parse(&format!("select[name=\"{select}\"] option[selected]"))
62- .expect("selector");
63- doc.select(&selector)
64- .next()
65- .and_then(|el| el.value().attr("value"))
66- .map(str::to_owned)
67-}
68-
69-/// The top-bar theme button: the value it posts and its accessible label.
70-fn theme_button(body: &str) -> (String, String) {
71- let doc = scraper::Html::parse_document(body);
72- let form = scraper::Selector::parse("form.theme-form").expect("selector");
73- let form = doc
74- .select(&form)
75- .next()
76- .unwrap_or_else(|| panic!("no theme button on page"));
77- let value = scraper::Selector::parse("input[name=\"theme\"]").expect("selector");
78- let value = form
79- .select(&value)
80- .next()
81- .and_then(|el| el.value().attr("value"))
82- .expect("theme value")
83- .to_owned();
84- let button = scraper::Selector::parse("button").expect("selector");
85- let label = form
86- .select(&button)
87- .next()
88- .and_then(|el| el.value().attr("aria-label"))
89- .expect("aria-label")
90- .to_owned();
91- (value, label)
92-}
93-
94-/// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
95 fn admin(config: &Path, args: &[&str]) {7 fn admin(config: &Path, args: &[&str]) {
96 let out = Command::new(bin())8 let out = Command::new(bin())
97 .arg("--config")9 .arg("--config")
@@ -108,7 +20,6 @@ fn admin(config: &Path, args: &[&str]) {
108 );20 );
109 }21 }
110 22
111-/// A running server with user `tahinli`. The temp dir lives as long as the test.
112 struct Env {23 struct Env {
113 _root: tempfile::TempDir,24 _root: tempfile::TempDir,
114 _server: Server,25 _server: Server,
@@ -130,8 +41,6 @@ async fn start() -> Env {
130 }41 }
131 }42 }
132 43
133-/// The section's tab row as (href, aria-current) pairs. The row is the first `nav.tabs` in `main`,
134-/// which the shell puts before the page's own content, so a page's own tabs are not read here.
135 fn tab_links(body: &str) -> Vec<(String, Option<String>)> {44 fn tab_links(body: &str) -> Vec<(String, Option<String>)> {
136 let doc = scraper::Html::parse_document(body);45 let doc = scraper::Html::parse_document(body);
137 let row = scraper::Selector::parse("main nav.tabs").expect("selector");46 let row = scraper::Selector::parse("main nav.tabs").expect("selector");
@@ -147,8 +56,6 @@ fn tab_links(body: &str) -> Vec<(String, Option<String>)> {
147 .collect()56 .collect()
148 }57 }
149 58
150-/// Checks the section's tab row: its first tab is the section's first, every tab in `hrefs` is
151-/// there, and exactly one tab, the one at `current`, is marked.
152 fn assert_tabs(body: &str, current: &str, hrefs: &[&str]) {59 fn assert_tabs(body: &str, current: &str, hrefs: &[&str]) {
153 let links = tab_links(body);60 let links = tab_links(body);
154 assert_eq!(links[0].0, hrefs[0], "first tab is the section's first");61 assert_eq!(links[0].0, hrefs[0], "first tab is the section's first");
@@ -176,7 +83,6 @@ async fn admin_pages_get_the_admin_tabs() {
176 "/admin/backups",83 "/admin/backups",
177 "/admin/audit",84 "/admin/audit",
178 ];85 ];
179- // Invites live under Users and replication under Backups: their own tab is the one marked.
180 for (path, current) in [86 for (path, current) in [
181 ("/admin/users", "/admin/users"),87 ("/admin/users", "/admin/users"),
182 ("/admin/invites", "/admin/users"),88 ("/admin/invites", "/admin/users"),
@@ -209,8 +115,6 @@ async fn settings_pages_get_the_settings_tabs() {
209 "/settings/keys",115 "/settings/keys",
210 "/settings/export",116 "/settings/export",
211 ];117 ];
212- // A page folded into another tab marks that tab: GPG keys and
213- // tokens under keys.
214 let pages = [118 let pages = [
215 ("/settings/profile", "/settings/profile"),119 ("/settings/profile", "/settings/profile"),
216 ("/settings/keys", "/settings/keys"),120 ("/settings/keys", "/settings/keys"),
@@ -223,7 +127,6 @@ async fn settings_pages_get_the_settings_tabs() {
223 assert_eq!(page.status, 200, "GET {path}");127 assert_eq!(page.status, 200, "GET {path}");
224 assert_tabs(&page.body, current, &tabs);128 assert_tabs(&page.body, current, &tabs);
225 }129 }
226- // GPG keys and tokens are kinds of the Keys tab, each at its own address.
227 for path in ["/settings/gpg", "/settings/tokens"] {130 for path in ["/settings/gpg", "/settings/tokens"] {
228 let page = env.http.get(path, Some(&session)).await;131 let page = env.http.get(path, Some(&session)).await;
229 assert_eq!(page.status, 200, "GET {path}");132 assert_eq!(page.status, 200, "GET {path}");
crates/forge-e2e/tests/e2e/snippets_e2e.rsmodified+13 -45
@@ -3,13 +3,12 @@
3 //! `Secure`. Files are fetched from the user-content listener, as a browser would.3 //! `Secure`. Files are fetched from the user-content listener, as a browser would.
4 4
5 use crate::common::{5 use crate::common::{
6- Http, Server, bin, describe, input_value, launch, login, pick_ports, write_config,6+ Http, Server, bin, describe, input_value, launch, login, next_changed, pick_ports, write_config,
7 };7 };
8 use std::path::{Path, PathBuf};8 use std::path::{Path, PathBuf};
9 use std::process::Command;9 use std::process::Command;
10-use std::time::Duration;
11 10
12-use reqwest::header::{CONTENT_TYPE, COOKIE, LOCATION};11+use reqwest::header::{CONTENT_TYPE, LOCATION};
13 12
14 const PW: &str = "tahinli-password-123";13 const PW: &str = "tahinli-password-123";
15 14
@@ -107,36 +106,6 @@ async fn create(
107 .to_owned()106 .to_owned()
108 }107 }
109 108
110-/// Opens a live stream as `cookie` (or anonymously) and reads its `retry` field. Returns the
111-/// status with the response, so a refused stream can be checked too.
112-async fn open_stream(http: &Http, path: &str, cookie: Option<&str>) -> reqwest::Response {
113- let mut req = http.client.get(format!("{}{path}", http.base));
114- if let Some(cookie) = cookie {
115- req = req.header(COOKIE, cookie);
116- }
117- let mut res = req.send().await.expect("stream request");
118- if res.status().is_success() {
119- let retry = tokio::time::timeout(Duration::from_secs(5), res.chunk())
120- .await
121- .expect("the retry field")
122- .expect("stream chunk")
123- .expect("stream still open");
124- assert!(String::from_utf8_lossy(&retry).contains("retry: 1000"));
125- }
126- res
127-}
128-
129-/// Waits for the next event of a stream, which must be `changed`.
130-async fn next_change(res: &mut reqwest::Response, what: &str) {
131- let chunk = tokio::time::timeout(Duration::from_secs(5), res.chunk())
132- .await
133- .unwrap_or_else(|_| panic!("no event after {what}"))
134- .expect("stream chunk")
135- .expect("stream still open");
136- let text = String::from_utf8_lossy(&chunk);
137- assert!(text.contains("event: changed"), "{what}: {text}");
138-}
139-
140 /// The list and the snippet page follow their streams. A create, an edit and a delete each wake109 /// The list and the snippet page follow their streams. A create, an edit and a delete each wake
141 /// them, and a private snippet's stream answers 404 to everyone but its owner.110 /// them, and a private snippet's stream answers 404 to everyone but its owner.
142 #[tokio::test]111 #[tokio::test]
@@ -170,9 +139,9 @@ async fn snippet_streams_follow_writes() {
170 "snippet page follows its stream"139 "snippet page follows its stream"
171 );140 );
172 141
173- let mut list_events = open_stream(&env.app, "/snippets/events", Some(&tahinli)).await;142+ let mut list_events = env.app.stream("/snippets/events", Some(&tahinli)).await;
174 assert_eq!(list_events.status().as_u16(), 200, "list stream");143 assert_eq!(list_events.status().as_u16(), 200, "list stream");
175- let mut item_events = open_stream(&env.app, &item, Some(&tahinli)).await;144+ let mut item_events = env.app.stream(&item, Some(&tahinli)).await;
176 assert_eq!(item_events.status().as_u16(), 200, "snippet stream");145 assert_eq!(item_events.status().as_u16(), 200, "snippet stream");
177 146
178 // An edit wakes both.147 // An edit wakes both.
@@ -194,8 +163,8 @@ async fn snippet_streams_follow_writes() {
194 )163 )
195 .await;164 .await;
196 assert_eq!(saved.status, 303, "edit: {}", saved.body);165 assert_eq!(saved.status, 303, "edit: {}", saved.body);
197- next_change(&mut list_events, "an edit").await;166+ next_changed(&mut list_events, "an edit").await;
198- next_change(&mut item_events, "an edit").await;167+ next_changed(&mut item_events, "an edit").await;
199 168
200 // A create wakes the list only.169 // A create wakes the list only.
201 let other = create(170 let other = create(
@@ -206,7 +175,7 @@ async fn snippet_streams_follow_writes() {
206 &[("two.txt", "2\n")],175 &[("two.txt", "2\n")],
207 )176 )
208 .await;177 .await;
209- next_change(&mut list_events, "a create").await;178+ next_changed(&mut list_events, "a create").await;
210 179
211 // A delete wakes the list, and the snippet's stream sends `changed` too: its page now 404s.180 // A delete wakes the list, and the snippet's stream sends `changed` too: its page now 404s.
212 let csrf = input_value(181 let csrf = input_value(
@@ -225,7 +194,7 @@ async fn snippet_streams_follow_writes() {
225 )194 )
226 .await;195 .await;
227 assert_eq!(deleted.status, 303, "delete: {}", deleted.body);196 assert_eq!(deleted.status, 303, "delete: {}", deleted.body);
228- next_change(&mut list_events, "a delete").await;197+ next_changed(&mut list_events, "a delete").await;
229 198
230 // A private snippet: the owner's stream opens, everyone else gets 404 (anonymous too).199 // A private snippet: the owner's stream opens, everyone else gets 404 (anonymous too).
231 let secret = create(200 let secret = create(
@@ -238,7 +207,8 @@ async fn snippet_streams_follow_writes() {
238 .await;207 .await;
239 let secret_item = format!("/snippets/{secret}/events");208 let secret_item = format!("/snippets/{secret}/events");
240 assert_eq!(209 assert_eq!(
241- open_stream(&env.app, &secret_item, Some(&tahinli))210+ env.app
211+ .stream(&secret_item, Some(&tahinli))
242 .await212 .await
243 .status()213 .status()
244 .as_u16(),214 .as_u16(),
@@ -246,7 +216,8 @@ async fn snippet_streams_follow_writes() {
246 "owner opens the private stream"216 "owner opens the private stream"
247 );217 );
248 assert_eq!(218 assert_eq!(
249- open_stream(&env.app, &secret_item, Some(&bob))219+ env.app
220+ .stream(&secret_item, Some(&bob))
250 .await221 .await
251 .status()222 .status()
252 .as_u16(),223 .as_u16(),
@@ -254,10 +225,7 @@ async fn snippet_streams_follow_writes() {
254 "others get 404"225 "others get 404"
255 );226 );
256 assert_eq!(227 assert_eq!(
257- open_stream(&env.app, &secret_item, None)228+ env.app.stream(&secret_item, None).await.status().as_u16(),
258- .await
259- .status()
260- .as_u16(),
261 404,229 404,
262 "anonymous gets 404"230 "anonymous gets 404"
263 );231 );
crates/forge-e2e/tests/e2e/stars_e2e.rsmodified+2 -34
@@ -3,47 +3,15 @@
3 //! HTTP. Cookies are set by hand because the session cookie is `__Host-` and `Secure`.3 //! HTTP. Cookies are set by hand because the session cookie is `__Host-` and `Secure`.
4 4
5 use crate::common::{5 use crate::common::{
6- Http, Resp, Server, bin, describe, input_value, launch, login, pick_ports, tool_on_path,6+ Http, PW, Resp, Server, admin, describe, init_bare, input_value, launch, login, pick_ports,
7- write_config,7+ tool_on_path, write_config,
8 };8 };
9-use std::fs;
10 use std::path::{Path, PathBuf};9 use std::path::{Path, PathBuf};
11 use std::process::{Command, Stdio};10 use std::process::{Command, Stdio};
12 11
13 use forge_core::{Store, Visibility};12 use forge_core::{Store, Visibility};
14 use reqwest::header::LOCATION;13 use reqwest::header::LOCATION;
15 14
16-const PW: &str = "tahinli-password-123";
17-
18-/// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
19-fn admin(config: &Path, args: &[&str]) {
20- let out = Command::new(bin())
21- .arg("--config")
22- .arg(config)
23- .arg("admin")
24- .args(args)
25- .env("FORGE_PASSWORD", PW)
26- .output()
27- .expect("run admin command");
28- assert!(
29- out.status.success(),
30- "admin {args:?} failed:\n{}",
31- describe(&out)
32- );
33-}
34-
35-/// Creates a bare git repo for `repo_id` at its data-dir location, as the create-repo page does.
36-fn init_bare(data_dir: &Path, repo_id: &str) {
37- let path = forge_git::repo::repo_path(data_dir, repo_id).expect("repo path");
38- fs::create_dir_all(path.parent().expect("parent")).expect("create repo parent");
39- let out = Command::new("git")
40- .args(["init", "--bare", "--quiet", "--initial-branch=main"])
41- .arg(&path)
42- .output()
43- .expect("run git init");
44- assert!(out.status.success(), "git init --bare: {}", describe(&out));
45-}
46-
47 /// A running server plus the data it was seeded with. The temp dir lives as long as the test.15 /// A running server plus the data it was seeded with. The temp dir lives as long as the test.
48 struct Env {16 struct Env {
49 _root: tempfile::TempDir,17 _root: tempfile::TempDir,
crates/forge-e2e/tests/e2e/user_delete_e2e.rsmodified+0 -7
@@ -15,10 +15,6 @@ use std::process::Command;
15 use forge_core::{Store, Visibility};15 use forge_core::{Store, Visibility};
16 use reqwest::header::LOCATION;16 use reqwest::header::LOCATION;
17 17
18-/// Each test starts a server on ports picked just before, so the tests run one at a time.
19-static SERIAL: std::sync::LazyLock<tokio::sync::Mutex<()>> =
20- std::sync::LazyLock::new(|| tokio::sync::Mutex::new(()));
21-
22 const PW: &str = "tahinli-password-123";18 const PW: &str = "tahinli-password-123";
23 19
24 /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.20 /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
@@ -122,7 +118,6 @@ async fn seed_issue_by_tahinli(dir: PathBuf, store: Store) {
122 118
123 #[tokio::test]119 #[tokio::test]
124 async fn admin_delete_moves_content_to_ghost_and_pages_still_render() {120 async fn admin_delete_moves_content_to_ghost_and_pages_still_render() {
125- let _serial = SERIAL.lock().await;
126 let env = start(seed_issue_by_tahinli).await;121 let env = start(seed_issue_by_tahinli).await;
127 let http = &env.http;122 let http = &env.http;
128 let dana = login(http, "dana", PW).await;123 let dana = login(http, "dana", PW).await;
@@ -173,7 +168,6 @@ async fn admin_delete_moves_content_to_ghost_and_pages_still_render() {
173 168
174 #[tokio::test]169 #[tokio::test]
175 async fn self_delete_refuses_wrong_password_and_owned_repos() {170 async fn self_delete_refuses_wrong_password_and_owned_repos() {
176- let _serial = SERIAL.lock().await;
177 let env = start(seed_issue_by_tahinli).await;171 let env = start(seed_issue_by_tahinli).await;
178 let http = &env.http;172 let http = &env.http;
179 173
@@ -236,7 +230,6 @@ async fn self_delete_refuses_wrong_password_and_owned_repos() {
236 230
237 #[tokio::test]231 #[tokio::test]
238 async fn self_delete_with_correct_password_signs_out_and_removes_login() {232 async fn self_delete_with_correct_password_signs_out_and_removes_login() {
239- let _serial = SERIAL.lock().await;
240 let env = start(seed_issue_by_tahinli).await;233 let env = start(seed_issue_by_tahinli).await;
241 let http = &env.http;234 let http = &env.http;
242 let tahinli = login(http, "tahinli", PW).await;235 let tahinli = login(http, "tahinli", PW).await;
crates/forge-e2e/tests/e2e/wiki_e2e.rsmodified+11 -22
@@ -6,7 +6,7 @@
6 //! which a cookie jar would not send over plain http.6 //! which a cookie jar would not send over plain http.
7 7
8 use crate::common::{8 use crate::common::{
9- Http, Resp, bin, describe, input_value, launch, login, pick_ports, tool_on_path, write_config,9+ Http, Resp, bin, describe, input_value, launch, login, pick_ports, write_config,
10 };10 };
11 use std::fs;11 use std::fs;
12 use std::path::Path;12 use std::path::Path;
@@ -116,8 +116,7 @@ fn commit_file(repo: &Path, name: &str, content: &str, message: &str) {
116 );116 );
117 }117 }
118 118
119-/// Reads the wiki page `name` as the viewer, returns its body.119+async fn get_ok(http: &Http, path: &str, session: Option<&str>) -> Resp {
120-async fn page_body(http: &Http, path: &str, session: Option<&str>) -> Resp {
121 let res = http.get(path, session).await;120 let res = http.get(path, session).await;
122 assert_eq!(res.status, 200, "GET {path}: {}", res.body);121 assert_eq!(res.status, 200, "GET {path}: {}", res.body);
123 res122 res
@@ -125,11 +124,6 @@ async fn page_body(http: &Http, path: &str, session: Option<&str>) -> Resp {
125 124
126 #[tokio::test]125 #[tokio::test]
127 async fn wiki_end_to_end() {126 async fn wiki_end_to_end() {
128- if !tool_on_path("git") {
129- eprintln!("SKIP wiki_e2e: `git` was not found on PATH");
130- return;
131- }
132-
133 // Keep the path short: the data dir holds a unix socket with a length limit.127 // Keep the path short: the data dir holds a unix socket with a length limit.
134 let root = tempfile::Builder::new()128 let root = tempfile::Builder::new()
135 .prefix("fwk")129 .prefix("fwk")
@@ -172,7 +166,7 @@ async fn wiki_end_to_end() {
172 let dave = login(&http, "dave", PW).await;166 let dave = login(&http, "dave", PW).await;
173 167
174 // The wiki starts empty, and the tab is there.168 // The wiki starts empty, and the tab is there.
175- let empty = page_body(&http, "/bob/proj/wiki", Some(&bob)).await;169+ let empty = get_ok(&http, "/bob/proj/wiki", Some(&bob)).await;
176 assert!(empty.body.contains("no pages yet"), "{}", empty.body);170 assert!(empty.body.contains("no pages yet"), "{}", empty.body);
177 171
178 // Bob creates Home on the web. The save redirects to the page.172 // Bob creates Home on the web. The save redirects to the page.
@@ -198,7 +192,7 @@ async fn wiki_end_to_end() {
198 saved.header(LOCATION).as_deref(),192 saved.header(LOCATION).as_deref(),
199 Some("/bob/proj/wiki/Home")193 Some("/bob/proj/wiki/Home")
200 );194 );
201- let home = page_body(&http, "/bob/proj/wiki/Home", Some(&bob)).await;195+ let home = get_ok(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
202 assert!(home.body.contains("Welcome"), "{}", home.body);196 assert!(home.body.contains("Welcome"), "{}", home.body);
203 assert!(197 assert!(
204 home.body.contains("/bob/proj/wiki/Getting-Started"),198 home.body.contains("/bob/proj/wiki/Getting-Started"),
@@ -207,7 +201,7 @@ async fn wiki_end_to_end() {
207 );201 );
208 202
209 // Dave can read the page but not edit it.203 // Dave can read the page but not edit it.
210- page_body(&http, "/bob/proj/wiki/Home", Some(&dave)).await;204+ get_ok(&http, "/bob/proj/wiki/Home", Some(&dave)).await;
211 let refused = http.get("/bob/proj/wiki/Home/edit", Some(&dave)).await;205 let refused = http.get("/bob/proj/wiki/Home/edit", Some(&dave)).await;
212 assert_eq!(refused.status, 403, "read-only user must not edit");206 assert_eq!(refused.status, 403, "read-only user must not edit");
213 207
@@ -229,7 +223,7 @@ async fn wiki_end_to_end() {
229 &git(&work, &["push", "-q", "origin", "HEAD:main"]),223 &git(&work, &["push", "-q", "origin", "HEAD:main"]),
230 "push wiki change over HTTPS",224 "push wiki change over HTTPS",
231 );225 );
232- let after_push = page_body(&http, "/bob/proj/wiki/Home", Some(&carol)).await;226+ let after_push = get_ok(&http, "/bob/proj/wiki/Home", Some(&carol)).await;
233 assert!(227 assert!(
234 after_push.body.contains("Welcome again"),228 after_push.body.contains("Welcome again"),
235 "{}",229 "{}",
@@ -275,11 +269,11 @@ async fn wiki_end_to_end() {
275 "{}",269 "{}",
276 stale.body270 stale.body
277 );271 );
278- let still = page_body(&http, "/bob/proj/wiki/Home", Some(&bob)).await;272+ let still = get_ok(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
279 assert!(still.body.contains("Welcome again"), "{}", still.body);273 assert!(still.body.contains("Welcome again"), "{}", still.body);
280 274
281 // The history lists both edits.275 // The history lists both edits.
282- let history = page_body(&http, "/bob/proj/wiki/Home/history", Some(&bob)).await;276+ let history = get_ok(&http, "/bob/proj/wiki/Home/history", Some(&bob)).await;
283 assert!(history.body.contains("first page"), "{}", history.body);277 assert!(history.body.contains("first page"), "{}", history.body);
284 assert!(history.body.contains("edit from git"), "{}", history.body);278 assert!(history.body.contains("edit from git"), "{}", history.body);
285 279
@@ -299,7 +293,7 @@ async fn wiki_end_to_end() {
299 assert!(!denied.status.success(), "read-only push must fail");293 assert!(!denied.status.success(), "read-only push must fail");
300 294
301 // Bob turns the wiki off on the settings page. Carol, who is not an admin, cannot.295 // Bob turns the wiki off on the settings page. Carol, who is not an admin, cannot.
302- let settings = page_body(&http, "/bob/proj/settings", Some(&bob)).await;296+ let settings = get_ok(&http, "/bob/proj/settings", Some(&bob)).await;
303 assert!(297 assert!(
304 settings.body.contains("action=\"/bob/proj/settings/wiki\""),298 settings.body.contains("action=\"/bob/proj/settings/wiki\""),
305 "{}",299 "{}",
@@ -362,11 +356,6 @@ async fn next_wiki_change(res: &mut reqwest::Response, what: &str) {
362 /// wake the wiki streams, and a viewer who cannot read the repo gets 404 from them.356 /// wake the wiki streams, and a viewer who cannot read the repo gets 404 from them.
363 #[tokio::test]357 #[tokio::test]
364 async fn wiki_streams_follow_saves_and_pushes() {358 async fn wiki_streams_follow_saves_and_pushes() {
365- if !tool_on_path("git") {
366- eprintln!("SKIP wiki live: `git` was not found on PATH");
367- return;
368- }
369-
370 let root = tempfile::Builder::new()359 let root = tempfile::Builder::new()
371 .prefix("fwl")360 .prefix("fwl")
372 .tempdir_in("/tmp")361 .tempdir_in("/tmp")
@@ -402,7 +391,7 @@ async fn wiki_streams_follow_saves_and_pushes() {
402 let dave = login(&http, "dave", PW).await;391 let dave = login(&http, "dave", PW).await;
403 392
404 // The page list follows the wiki stream.393 // The page list follows the wiki stream.
405- let listing = page_body(&http, "/bob/proj/wiki/-/pages", Some(&bob)).await;394+ let listing = get_ok(&http, "/bob/proj/wiki/-/pages", Some(&bob)).await;
406 assert!(395 assert!(
407 listing396 listing
408 .body397 .body
@@ -433,7 +422,7 @@ async fn wiki_streams_follow_saves_and_pushes() {
433 next_wiki_change(&mut wiki_events, "a web save").await;422 next_wiki_change(&mut wiki_events, "a web save").await;
434 423
435 // The page's own stream follows Home, and a push from git wakes it.424 // The page's own stream follows Home, and a push from git wakes it.
436- let home = page_body(&http, "/bob/proj/wiki/Home", Some(&bob)).await;425+ let home = get_ok(&http, "/bob/proj/wiki/Home", Some(&bob)).await;
437 assert!(426 assert!(
438 home.body427 home.body
439 .contains(r#"data-live="/bob/proj/wiki/Home/events""#),428 .contains(r#"data-live="/bob/proj/wiki/Home/events""#),
docs/architecture.mdmodified+1 -1
@@ -61,7 +61,7 @@ Module ownership (from the contract):
61 - `error.rs`, `time.rs` (`now_stamp()`, `stamp_after()`), `model.rs` (domain types)61 - `error.rs`, `time.rs` (`now_stamp()`, `stamp_after()`), `model.rs` (domain types)
62 - `config.rs` (`Config::load`), `secret.rs` (`load_or_create_key`, `seal`, `open`)62 - `config.rs` (`Config::load`), `secret.rs` (`load_or_create_key`, `seal`, `open`)
63 - `names.rs` (`normalize_name`, `validate_name`, `RESERVED`), `password.rs` (argon2id)63 - `names.rs` (`normalize_name`, `validate_name`, `RESERVED`), `password.rs` (argon2id)
64- - `token.rs` (`generate_token`, `hash_token`, `constant_time_eq`), `session.rs`64+ - `token.rs` (`generate_token`, `hash_token`, `constant_time_eq`)
65 - `authz.rs` (`Action`, `Denied`, `authorize`)65 - `authz.rs` (`Action`, `Denied`, `authorize`)
66 - `store/mod.rs` (`Store`), `store/migrate.rs` (migration runner)66 - `store/mod.rs` (`Store`), `store/migrate.rs` (migration runner)
67 - `migrations/0001_init.sql`67 - `migrations/0001_init.sql`
docs/backlog.mdmodified+1 -1
@@ -51,7 +51,7 @@ Status: `[ ]` todo, `[~]` in progress, `[x]` done.
51 51
52 ## Tech debt52 ## Tech debt
53 - [x] A shared test fixture `test_support::app(dir) -> (AppState, Router)`: Config and AppState literals are copied into about 8 test modules, and every new field breaks them all53 - [x] A shared test fixture `test_support::app(dir) -> (AppState, Router)`: Config and AppState literals are copied into about 8 test modules, and every new field breaks them all
54-- [x] Store read pool: one writer connection plus 4 `query_only` readers (`Store::read_conn`); pure-SELECT functions use the readers (rules in the `Store` doc comment, proof in `crates/forge-core/tests/integration/read_pool.rs`)54+- [x] Store read pool: one writer connection plus 4 `query_only` readers (`Store::read_conn`); pure-SELECT functions use the readers
55 - [x] Login and git auth throttling (`throttle.rs`, `client_ip.rs`, `trusted_proxies`)55 - [x] Login and git auth throttling (`throttle.rs`, `client_ip.rs`, `trusted_proxies`)
56 56
57 ## Later57 ## Later