forge
Explore
Log in

Don't you dare go Hollow

Page tests share their fixtures and merge into tables

Browse files at this commit

40e7f7d662cc068f31421a72388e0a76f3493705Ahmet Kaan GümüşParent: de06f74
  • test
    • page tests share their fixtures and merge into tables
Show full message
✅ test: page tests share their fixtures and merge into tables

Per-file test counts (#[test]/#[tokio::test]), main -> now:
- pages/authoring_tests.rs: 7 -> 3
- pages/blame.rs: 3 -> 2
- pages/browse_tests.rs: 9 -> 4
- pages/commit.rs: 6 -> 3
- pages/commits.rs: 7 -> 3
- pages/forgot.rs: 3 -> 1
- pages/fork.rs: 9 -> 1
- pages/import_tests.rs: 5 -> 2

Total: 44 -> 19. Scoped run: 19 passed, 0 failed.
crates/forge-web/src/pages/authoring_tests.rsmodified+28 -22
@@ -6,7 +6,7 @@ use topcoat::router::{Body, to_bytes};
6 6
7 use crate::auth::SESSION_COOKIE;7 use crate::auth::SESSION_COOKIE;
8 use crate::pages::authoring::clean_name;8 use crate::pages::authoring::clean_name;
9-use crate::pages::issues_list::test_util::{CSRF, OWNER, REPO, TOKEN, fixture, send};9+use crate::pages::issues_list::test_util::{CSRF, Fixture, OWNER, REPO, TOKEN, fixture, send};
10 10
11 const OID_A: &str = "1111111111111111111111111111111111111111";11 const OID_A: &str = "1111111111111111111111111111111111111111";
12 const OID_B: &str = "2222222222222222222222222222222222222222";12 const OID_B: &str = "2222222222222222222222222222222222222222";
@@ -107,9 +107,8 @@ async fn attachment_round_trip_and_visibility() {
107 );107 );
108 }108 }
109 109
110-#[tokio::test]110+/// Uploads with a bad token or a bad type are refused, and a text file downloads.
111-async fn attachment_rejects_bad_csrf_and_types() {111+async fn scenario_upload_refusals(fx: &Fixture) {
112- let fx = fixture(Visibility::Public).await;
113 let path = format!("{}/attachments", base());112 let path = format!("{}/attachments", base());
114 assert_eq!(113 assert_eq!(
115 upload(&fx.router, &path, "wrong", "a.png", b"x").await.0,114 upload(&fx.router, &path, "wrong", "a.png", b"x").await.0,
@@ -137,9 +136,9 @@ async fn attachment_rejects_bad_csrf_and_types() {
137 assert_eq!(got.body, "hello");136 assert_eq!(got.body, "hello");
138 }137 }
139 138
140-#[tokio::test]139+/// Mention suggestions list users and issues, and anonymous viewers get nothing. This creates
141-async fn suggest_lists_users_and_issues() {140+/// issue 1 and the user tanya, which the later scenarios rely on.
142- let fx = fixture(Visibility::Public).await;141+async fn scenario_suggestions(fx: &Fixture) {
143 fx.store142 fx.store
144 .create_issue(&fx.repo.id, &fx.owner.id, "Parser crash", "")143 .create_issue(&fx.repo.id, &fx.owner.id, "Parser crash", "")
145 .await144 .await
@@ -184,9 +183,8 @@ async fn suggest_lists_users_and_issues() {
184 assert_eq!(anon.status, 403);183 assert_eq!(anon.status, 403);
185 }184 }
186 185
187-#[tokio::test]186+/// Ticking a task saves it with history, and bad, missing or anonymous requests change nothing.
188-async fn ticking_a_task_saves_it_with_history() {187+async fn scenario_task_toggles(fx: &Fixture) {
189- let fx = fixture(Visibility::Public).await;
190 let issue = fx188 let issue = fx
191 .store189 .store
192 .create_issue(&fx.repo.id, &fx.owner.id, "Plan", "- [ ] one\n- [ ] two\n")190 .create_issue(&fx.repo.id, &fx.owner.id, "Plan", "- [ ] one\n- [ ] two\n")
@@ -257,9 +255,9 @@ async fn ticking_a_task_saves_it_with_history() {
257 assert_eq!(c.body, "- [ ] done\n- [ ] todo");255 assert_eq!(c.body, "- [ ] done\n- [ ] todo");
258 }256 }
259 257
260-#[tokio::test]258+/// A review request notifies the reviewer, and a review or a withdrawal clears it. This creates
261-async fn requesting_a_review_notifies_and_a_review_clears_it() {259+/// bob, whom the global review-requests scenario reuses.
262- let fx = fixture(Visibility::Public).await;260+async fn scenario_review_requests(fx: &Fixture) {
263 let bob = fx261 let bob = fx
264 .store262 .store
265 .create_user("bob", None, "hash", false)263 .create_user("bob", None, "hash", false)
@@ -439,14 +437,10 @@ async fn requesting_a_review_notifies_and_a_review_clears_it() {
439 );437 );
440 }438 }
441 439
442-#[tokio::test]440+/// The global review-requests page lists the pulls waiting on a reviewer. Runs after the review
443-async fn global_review_requests_page_lists_waiting_pulls() {441+/// scenario, which counts bob's notifications.
444- let fx = fixture(Visibility::Public).await;442+async fn scenario_review_page(fx: &Fixture) {
445- let bob = fx443+ let bob = fx.store.user_by_username("bob").await.unwrap().unwrap();
446- .store
447- .create_user("bob", None, "hash", false)
448- .await
449- .unwrap();
450 let pr = fx444 let pr = fx
451 .store445 .store
452 .create_pull(446 .create_pull(
@@ -456,7 +450,7 @@ async fn global_review_requests_page_lists_waiting_pulls() {
456 "",450 "",
457 "main",451 "main",
458 &fx.repo.id,452 &fx.repo.id,
459- "feature",453+ "bobs-change",
460 OID_A,454 OID_A,
461 OID_B,455 OID_B,
462 )456 )
@@ -475,3 +469,15 @@ async fn global_review_requests_page_lists_waiting_pulls() {
475 );469 );
476 assert!(page.body.contains("requested by bob"));470 assert!(page.body.contains("requested by bob"));
477 }471 }
472+
473+/// The public-repo flows on one fixture. Each scenario builds on the ones before it (issue
474+/// numbers, the notifications bob gets), so keep this order.
475+#[tokio::test]
476+async fn public_repo_authoring_flows() {
477+ let fx = fixture(Visibility::Public).await;
478+ scenario_upload_refusals(&fx).await;
479+ scenario_suggestions(&fx).await;
480+ scenario_task_toggles(&fx).await;
481+ scenario_review_requests(&fx).await;
482+ scenario_review_page(&fx).await;
483+}
crates/forge-web/src/pages/blame.rsmodified+12 -6
@@ -252,9 +252,8 @@ mod tests {
252 252
253 use crate::pages::commits::test_support::{Fixture, OWNER, REPO, get};253 use crate::pages::commits::test_support::{Fixture, OWNER, REPO, get};
254 254
255- #[tokio::test]255+ /// Blame groups each line under the commit that wrote it.
256- async fn blame_groups_lines_by_commit() {256+ async fn scenario_blame_lines(fx: &Fixture) {
257- let fx = Fixture::new(Visibility::Public).await;
258 let (status, _, body) = get(&fx.router, &format!("/{OWNER}/{REPO}/blame/main/a.txt")).await;257 let (status, _, body) = get(&fx.router, &format!("/{OWNER}/{REPO}/blame/main/a.txt")).await;
259 assert_eq!(status, 200);258 assert_eq!(status, 200);
260 let html = String::from_utf8(body).unwrap();259 let html = String::from_utf8(body).unwrap();
@@ -268,13 +267,20 @@ mod tests {
268 assert!(html.contains("id=\"L4\""));267 assert!(html.contains("id=\"L4\""));
269 }268 }
270 269
271- #[tokio::test]270+ /// A file that is not in the tree is 404.
272- async fn blame_of_a_missing_file_is_404() {271+ async fn scenario_missing_file(fx: &Fixture) {
273- let fx = Fixture::new(Visibility::Public).await;
274 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/blame/main/nope.txt")).await;272 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/blame/main/nope.txt")).await;
275 assert_eq!(status, 404);273 assert_eq!(status, 404);
276 }274 }
277 275
276+ /// Both public blame scenarios on one fixture.
277+ #[tokio::test]
278+ async fn public_repo_blame() {
279+ let fx = Fixture::new(Visibility::Public).await;
280+ scenario_blame_lines(&fx).await;
281+ scenario_missing_file(&fx).await;
282+ }
283+
278 #[tokio::test]284 #[tokio::test]
279 async fn private_repo_blame_is_404_for_anonymous() {285 async fn private_repo_blame_is_404_for_anonymous() {
280 let fx = Fixture::new(Visibility::Private).await;286 let fx = Fixture::new(Visibility::Private).await;
crates/forge-web/src/pages/browse_tests.rsmodified+64 -41
@@ -71,9 +71,8 @@ fn whitespace_commit(fx: &Fixture) -> String {
71 oid71 oid
72 }72 }
73 73
74-#[tokio::test]74+/// The commit toolbar, and the whitespace toggle that hides whitespace-only files.
75-async fn commit_page_has_toolbar_and_ignores_whitespace() {75+async fn scenario_whitespace_toolbar(fx: &Fixture) {
76- let fx = Fixture::new(Visibility::Public).await;
77 let oid = whitespace_commit(&fx);76 let oid = whitespace_commit(&fx);
78 let base = format!("/{OWNER}/{REPO}/commit/{oid}");77 let base = format!("/{OWNER}/{REPO}/commit/{oid}");
79 78
@@ -99,9 +98,8 @@ async fn commit_page_has_toolbar_and_ignores_whitespace() {
99 assert!(main.contains("aria-pressed=\"true\""));98 assert!(main.contains("aria-pressed=\"true\""));
100 }99 }
101 100
102-#[tokio::test]101+/// The split view renders two sides and is remembered in a cookie.
103-async fn split_view_renders_two_sides_and_is_remembered() {102+async fn scenario_split_view(fx: &Fixture) {
104- let fx = Fixture::new(Visibility::Public).await;
105 let uri = format!("/{OWNER}/{REPO}/commit/{}?view=split", fx.modified);103 let uri = format!("/{OWNER}/{REPO}/commit/{}?view=split", fx.modified);
106 104
107 let (status, headers, body) = get(&fx.router, &uri).await;105 let (status, headers, body) = get(&fx.router, &uri).await;
@@ -138,9 +136,8 @@ async fn split_view_renders_two_sides_and_is_remembered() {
138 assert!(!String::from_utf8(body).unwrap().contains("diff-split-row"));136 assert!(!String::from_utf8(body).unwrap().contains("diff-split-row"));
139 }137 }
140 138
141-#[tokio::test]139+/// Patch and diff downloads for a commit and a root commit, and 404s for bad or private ones.
142-async fn patch_and_diff_downloads() {140+async fn scenario_patch_and_diff(fx: &Fixture) {
143- let fx = Fixture::new(Visibility::Public).await;
144 let base = format!("/{OWNER}/{REPO}/commit/{}", fx.modified);141 let base = format!("/{OWNER}/{REPO}/commit/{}", fx.modified);
145 142
146 let (status, headers, body) = get(&fx.router, &format!("{base}.patch")).await;143 let (status, headers, body) = get(&fx.router, &format!("{base}.patch")).await;
@@ -162,7 +159,7 @@ async fn patch_and_diff_downloads() {
162 assert!(text.starts_with("diff --git a/a.txt b/a.txt"));159 assert!(text.starts_with("diff --git a/a.txt b/a.txt"));
163 assert!(!text.contains("Subject:"));160 assert!(!text.contains("Subject:"));
164 161
165- // Root commits work, and a private repo hides both downloads.162+ // Root commits work.
166 let (status, _, _) = get(163 let (status, _, _) = get(
167 &fx.router,164 &fx.router,
168 &format!("/{OWNER}/{REPO}/commit/{}.patch", fx.root),165 &format!("/{OWNER}/{REPO}/commit/{}.patch", fx.root),
@@ -171,18 +168,10 @@ async fn patch_and_diff_downloads() {
171 assert_eq!(status, 200);168 assert_eq!(status, 200);
172 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/commit/zzzz.patch")).await;169 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/commit/zzzz.patch")).await;
173 assert_eq!(status, 404);170 assert_eq!(status, 404);
174- let private = Fixture::new(Visibility::Private).await;
175- let (status, _, _) = get(
176- &private.router,
177- &format!("/{OWNER}/{REPO}/commit/{}.patch", private.root),
178- )
179- .await;
180- assert_eq!(status, 404);
181 }171 }
182 172
183-#[tokio::test]173+/// Compare lists the commits on the head side, as a patch and as a diff.
184-async fn compare_patch_lists_commits_of_the_head_side() {174+async fn scenario_compare(fx: &Fixture) {
185- let fx = Fixture::new(Visibility::Public).await;
186 git(&fx.work, &["checkout", "-q", "-b", "topic", &fx.root]);175 git(&fx.work, &["checkout", "-q", "-b", "topic", &fx.root]);
187 std::fs::write(fx.work.join("topic.txt"), "topic\n").unwrap();176 std::fs::write(fx.work.join("topic.txt"), "topic\n").unwrap();
188 git(&fx.work, &["add", "-A"]);177 git(&fx.work, &["add", "-A"]);
@@ -215,9 +204,8 @@ async fn compare_patch_lists_commits_of_the_head_side() {
215 assert!(text.contains("+++ b/topic.txt"));204 assert!(text.contains("+++ b/topic.txt"));
216 }205 }
217 206
218-#[tokio::test]207+/// The blob page offers blame, a commit-pinned permalink and the finder.
219-async fn blob_page_offers_blame_permalink_and_finder() {208+async fn scenario_blob_page(fx: &Fixture) {
220- let fx = Fixture::new(Visibility::Public).await;
221 let (status, _, body) = get(&fx.router, &format!("/{OWNER}/{REPO}/blob/main/a.txt")).await;209 let (status, _, body) = get(&fx.router, &format!("/{OWNER}/{REPO}/blob/main/a.txt")).await;
222 assert_eq!(status, 200);210 assert_eq!(status, 200);
223 let html = String::from_utf8(body).unwrap();211 let html = String::from_utf8(body).unwrap();
@@ -243,9 +231,8 @@ async fn blob_page_offers_blame_permalink_and_finder() {
243 assert!(String::from_utf8(body).unwrap().contains("data-finder"));231 assert!(String::from_utf8(body).unwrap().contains("data-finder"));
244 }232 }
245 233
246-#[tokio::test]234+/// The paths endpoint lists every file on the ref, and refuses unknown refs and subpaths.
247-async fn paths_endpoint_lists_every_file() {235+async fn scenario_paths(fx: &Fixture) {
248- let fx = Fixture::new(Visibility::Public).await;
249 let (status, headers, body) = get(&fx.router, &format!("/{OWNER}/{REPO}/paths/main")).await;236 let (status, headers, body) = get(&fx.router, &format!("/{OWNER}/{REPO}/paths/main")).await;
250 assert_eq!(status, 200);237 assert_eq!(status, 200);
251 assert!(238 assert!(
@@ -269,14 +256,10 @@ async fn paths_endpoint_lists_every_file() {
269 assert_eq!(status, 404);256 assert_eq!(status, 404);
270 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/paths/main/dir")).await;257 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/paths/main/dir")).await;
271 assert_eq!(status, 404);258 assert_eq!(status, 404);
272- let private = Fixture::new(Visibility::Private).await;
273- let (status, _, _) = get(&private.router, &format!("/{OWNER}/{REPO}/paths/main")).await;
274- assert_eq!(status, 404);
275 }259 }
276 260
277-#[tokio::test]261+/// The branches page shows counts, creates and deletes branches, and refuses bad input.
278-async fn branches_page_shows_counts_and_creates_and_deletes() {262+async fn scenario_branches(fx: &Fixture, cookie: &str) {
279- let fx = Fixture::new(Visibility::Public).await;
280 git(&fx.work, &["checkout", "-q", "-b", "feature", &fx.root]);263 git(&fx.work, &["checkout", "-q", "-b", "feature", &fx.root]);
281 std::fs::write(fx.work.join("f.txt"), "f\n").unwrap();264 std::fs::write(fx.work.join("f.txt"), "f\n").unwrap();
282 git(&fx.work, &["add", "-A"]);265 git(&fx.work, &["add", "-A"]);
@@ -290,7 +273,6 @@ async fn branches_page_shows_counts_and_creates_and_deletes() {
290 "HEAD:refs/heads/feature",273 "HEAD:refs/heads/feature",
291 ],274 ],
292 );275 );
293- let cookie = sign_in_owner(&fx).await;
294 let page = format!("/{OWNER}/{REPO}/branches");276 let page = format!("/{OWNER}/{REPO}/branches");
295 277
296 let (status, _, html) = send(&fx.router, "GET", &page, Some(&cookie), &[]).await;278 let (status, _, html) = send(&fx.router, "GET", &page, Some(&cookie), &[]).await;
@@ -399,9 +381,8 @@ async fn branches_page_shows_counts_and_creates_and_deletes() {
399 git(&fx.bare, &["rev-parse", "--verify", "refs/heads/main"]);381 git(&fx.bare, &["rev-parse", "--verify", "refs/heads/main"]);
400 }382 }
401 383
402-#[tokio::test]384+/// A branch rule blocks deleting the branches it matches.
403-async fn protection_rules_block_branch_deletion() {385+async fn scenario_protection(fx: &Fixture, cookie: &str) {
404- let fx = Fixture::new(Visibility::Public).await;
405 git(&fx.bare, &["branch", "release/1", "main"]);386 git(&fx.bare, &["branch", "release/1", "main"]);
406 git(&fx.bare, &["branch", "scratch", "main"]);387 git(&fx.bare, &["branch", "scratch", "main"]);
407 let repo = fx388 let repo = fx
@@ -414,7 +395,6 @@ async fn protection_rules_block_branch_deletion() {
414 .upsert_branch_rule(&repo.id, "release/*", RuleFlags::basic(false, false))395 .upsert_branch_rule(&repo.id, "release/*", RuleFlags::basic(false, false))
415 .await396 .await
416 .unwrap();397 .unwrap();
417- let cookie = sign_in_owner(&fx).await;
418 let delete = format!("/{OWNER}/{REPO}/branches/delete");398 let delete = format!("/{OWNER}/{REPO}/branches/delete");
419 let tip = git(&fx.bare, &["rev-parse", "refs/heads/main"]);399 let tip = git(&fx.bare, &["rev-parse", "refs/heads/main"]);
420 400
@@ -439,11 +419,9 @@ async fn protection_rules_block_branch_deletion() {
439 assert!(git(&fx.bare, &["branch", "--list", "scratch"]).is_empty());419 assert!(git(&fx.bare, &["branch", "--list", "scratch"]).is_empty());
440 }420 }
441 421
442-#[tokio::test]422+/// Changing the default branch moves HEAD and the record; a missing branch changes nothing.
443-async fn default_branch_setting_updates_head_and_the_record() {423+async fn scenario_default_branch(fx: &Fixture, cookie: &str) {
444- let fx = Fixture::new(Visibility::Public).await;
445 git(&fx.bare, &["branch", "trunk", "main"]);424 git(&fx.bare, &["branch", "trunk", "main"]);
446- let cookie = sign_in_owner(&fx).await;
447 let settings = format!("/{OWNER}/{REPO}/settings/general");425 let settings = format!("/{OWNER}/{REPO}/settings/general");
448 426
449 let (status, _, _) = send(427 let (status, _, _) = send(
@@ -502,3 +480,48 @@ async fn default_branch_setting_updates_head_and_the_record() {
502 .await;480 .await;
503 assert!(html.contains("name=\"default_branch\""));481 assert!(html.contains("name=\"default_branch\""));
504 }482 }
483+
484+/// Paths, patch and diff, split view and blob page, on one public repo. These pin the file set
485+/// and the commit count, so they run before any commit is added.
486+#[tokio::test]
487+async fn public_repo_pages_and_downloads() {
488+ let fx = Fixture::new(Visibility::Public).await;
489+ scenario_paths(&fx).await;
490+ scenario_patch_and_diff(&fx).await;
491+ scenario_split_view(&fx).await;
492+ scenario_blob_page(&fx).await;
493+}
494+
495+/// The commit toolbar, then compare. The whitespace scenario adds commits to main, and compare
496+/// moves the working checkout to a topic branch, so compare runs last.
497+#[tokio::test]
498+async fn public_repo_commit_views_and_compare() {
499+ let fx = Fixture::new(Visibility::Public).await;
500+ scenario_whitespace_toolbar(&fx).await;
501+ scenario_compare(&fx).await;
502+}
503+
504+/// Branches, branch rules and the default branch on one fixture. The branch counts assume main
505+/// has not moved, and the default-branch change runs last.
506+#[tokio::test]
507+async fn public_repo_branches_rules_and_default_branch() {
508+ let fx = Fixture::new(Visibility::Public).await;
509+ let cookie = sign_in_owner(&fx).await;
510+ scenario_branches(&fx, &cookie).await;
511+ scenario_protection(&fx, &cookie).await;
512+ scenario_default_branch(&fx, &cookie).await;
513+}
514+
515+/// A private repo hides its patch download and its file list from anonymous viewers.
516+#[tokio::test]
517+async fn private_repo_hides_downloads_and_paths() {
518+ let private = Fixture::new(Visibility::Private).await;
519+ let (status, _, _) = get(
520+ &private.router,
521+ &format!("/{OWNER}/{REPO}/commit/{}.patch", private.root),
522+ )
523+ .await;
524+ assert_eq!(status, 404);
525+ let (status, _, _) = get(&private.router, &format!("/{OWNER}/{REPO}/paths/main")).await;
526+ assert_eq!(status, 404);
527+}
crates/forge-web/src/pages/commit.rsmodified+21 -17
@@ -228,7 +228,10 @@ mod tests {
228 use scraper::{Html, Selector};228 use scraper::{Html, Selector};
229 229
230 use super::is_hex_prefix;230 use super::is_hex_prefix;
231+ use crate::auth::SESSION_COOKIE;
231 use crate::pages::commits::test_support::{Fixture, OWNER, REPO, get};232 use crate::pages::commits::test_support::{Fixture, OWNER, REPO, get};
233+ use topcoat::router::request::Request;
234+ use topcoat::router::{Body, to_bytes};
232 235
233 fn doc(body: &[u8]) -> Html {236 fn doc(body: &[u8]) -> Html {
234 Html::parse_document(std::str::from_utf8(body).unwrap())237 Html::parse_document(std::str::from_utf8(body).unwrap())
@@ -256,9 +259,8 @@ mod tests {
256 assert!(!is_hex_prefix("zzzz"));259 assert!(!is_hex_prefix("zzzz"));
257 }260 }
258 261
259- #[tokio::test]262+ /// The modified and added files show line numbers, with their body and file headers.
260- async fn modified_and_added_files_have_line_numbers() {263+ async fn scenario_modified_and_added(fx: &Fixture) {
261- let fx = Fixture::new(Visibility::Public).await;
262 let (status, _, body) = get(264 let (status, _, body) = get(
263 &fx.router,265 &fx.router,
264 &format!("/{OWNER}/{REPO}/commit/{}", fx.modified),266 &format!("/{OWNER}/{REPO}/commit/{}", fx.modified),
@@ -302,9 +304,8 @@ mod tests {
302 assert!(!text.contains("sig-badge"), "unsigned commit has no badge");304 assert!(!text.contains("sig-badge"), "unsigned commit has no badge");
303 }305 }
304 306
305- #[tokio::test]307+ /// The root commit has no parent, and its one added line is shown.
306- async fn root_commit_page_renders() {308+ async fn scenario_root_commit(fx: &Fixture) {
307- let fx = Fixture::new(Visibility::Public).await;
308 let (status, _, body) =309 let (status, _, body) =
309 get(&fx.router, &format!("/{OWNER}/{REPO}/commit/{}", fx.root)).await;310 get(&fx.router, &format!("/{OWNER}/{REPO}/commit/{}", fx.root)).await;
310 assert_eq!(status, 200);311 assert_eq!(status, 200);
@@ -317,14 +318,8 @@ mod tests {
317 );318 );
318 }319 }
319 320
320- #[tokio::test]321+ /// Titles follow the viewer's timezone; anonymous viewers see UTC.
321- async fn commit_title_uses_viewer_timezone() {322+ async fn scenario_title_timezone(fx: &Fixture) {
322- use topcoat::router::request::Request;
323- use topcoat::router::{Body, to_bytes};
324-
325- use crate::auth::SESSION_COOKIE;
326-
327- let fx = Fixture::new(Visibility::Public).await;
328 let tokyo = fx323 let tokyo = fx
329 .store324 .store
330 .create_user("tokyo", None, "not-a-real-hash", false)325 .create_user("tokyo", None, "not-a-real-hash", false)
@@ -378,9 +373,8 @@ mod tests {
378 assert!(!anon.contains("+09\""), "anonymous view is not Tokyo time");373 assert!(!anon.contains("+09\""), "anonymous view is not Tokyo time");
379 }374 }
380 375
381- #[tokio::test]376+ /// Bad and unknown oids are 404.
382- async fn bad_oid_is_404() {377+ async fn scenario_bad_oid(fx: &Fixture) {
383- let fx = Fixture::new(Visibility::Public).await;
384 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/commit/zzzz")).await;378 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/commit/zzzz")).await;
385 assert_eq!(status, 404);379 assert_eq!(status, 404);
386 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/commit/abc")).await;380 let (status, _, _) = get(&fx.router, &format!("/{OWNER}/{REPO}/commit/abc")).await;
@@ -390,6 +384,16 @@ mod tests {
390 assert_eq!(status, 404);384 assert_eq!(status, 404);
391 }385 }
392 386
387+ /// Every page of one public commit, on one fixture. The scenarios only read, so order is free.
388+ #[tokio::test]
389+ async fn public_commit_pages() {
390+ let fx = Fixture::new(Visibility::Public).await;
391+ scenario_modified_and_added(&fx).await;
392+ scenario_root_commit(&fx).await;
393+ scenario_title_timezone(&fx).await;
394+ scenario_bad_oid(&fx).await;
395+ }
396+
393 #[tokio::test]397 #[tokio::test]
394 async fn private_repo_is_404_for_anonymous() {398 async fn private_repo_is_404_for_anonymous() {
395 let fx = Fixture::new(Visibility::Private).await;399 let fx = Fixture::new(Visibility::Private).await;
crates/forge-web/src/pages/commits.rsmodified+20 -17
@@ -512,13 +512,9 @@ mod tests {
512 use crate::views::relative_time;512 use crate::views::relative_time;
513 513
514 #[test]514 #[test]
515- fn formats_dates() {515+ fn dates_and_relative_units_format() {
516 assert_eq!(iso_time(0), "1970-01-01T00:00:00Z");516 assert_eq!(iso_time(0), "1970-01-01T00:00:00Z");
517 assert_eq!(iso_time(1_700_000_000), "2023-11-14T22:13:20Z");517 assert_eq!(iso_time(1_700_000_000), "2023-11-14T22:13:20Z");
518- }
519-
520- #[test]
521- fn relative_units() {
522 assert_eq!(relative_time(Lang::En, 990, 1000), "just now");518 assert_eq!(relative_time(Lang::En, 990, 1000), "just now");
523 assert_eq!(519 assert_eq!(
524 relative_time(Lang::En, 10_000 - 3 * 86_400, 10_000),520 relative_time(Lang::En, 10_000 - 3 * 86_400, 10_000),
@@ -531,9 +527,8 @@ mod tests {
531 assert_eq!(url_path("a b/c#d"), "a%20b/c%23d");527 assert_eq!(url_path("a b/c#d"), "a%20b/c%23d");
532 }528 }
533 529
534- #[tokio::test]530+ /// Pages through history (50, then 5), and refuses bad pages and unknown refs.
535- async fn commits_list_and_pagination() {531+ async fn scenario_pagination(fx: &Fixture) {
536- let fx = Fixture::new(Visibility::Public).await;
537 let base = format!("/{OWNER}/{REPO}/commits/main");532 let base = format!("/{OWNER}/{REPO}/commits/main");
538 533
539 let (status, _, body) = get(&fx.router, &base).await;534 let (status, _, body) = get(&fx.router, &base).await;
@@ -565,9 +560,8 @@ mod tests {
565 assert_eq!(status, 404);560 assert_eq!(status, 404);
566 }561 }
567 562
568- #[tokio::test]563+ /// The path filter keeps only the commits that touch the file.
569- async fn path_filter_limits_history() {564+ async fn scenario_path_filter(fx: &Fixture) {
570- let fx = Fixture::new(Visibility::Public).await;
571 let (status, _, body) =565 let (status, _, body) =
572 get(&fx.router, &format!("/{OWNER}/{REPO}/commits/main/a.txt")).await;566 get(&fx.router, &format!("/{OWNER}/{REPO}/commits/main/a.txt")).await;
573 assert_eq!(status, 200);567 assert_eq!(status, 200);
@@ -579,11 +573,10 @@ mod tests {
579 assert!(html.contains("Clear filter"));573 assert!(html.contains("Clear filter"));
580 }574 }
581 575
582- #[tokio::test]576+ /// Commit status icons and contexts show on the list.
583- async fn commit_list_shows_status_icon_and_contexts() {577+ async fn scenario_status_icons(fx: &Fixture) {
584 use forge_core::store::commit_status::StatusState;578 use forge_core::store::commit_status::StatusState;
585 579
586- let fx = Fixture::new(Visibility::Public).await;
587 let repo = fx580 let repo = fx
588 .store581 .store
589 .repo_by_owner_and_name(OWNER, REPO)582 .repo_by_owner_and_name(OWNER, REPO)
@@ -636,9 +629,8 @@ mod tests {
636 assert!(html.contains("rel=\"nofollow noopener noreferrer\""));629 assert!(html.contains("rel=\"nofollow noopener noreferrer\""));
637 }630 }
638 631
639- #[tokio::test]632+ /// Gitmoji shortcodes show as emoji. This pushes one more commit, so it runs last.
640- async fn gitmoji_shortcodes_show_as_emoji() {633+ async fn scenario_gitmoji(fx: &Fixture) {
641- let fx = Fixture::new(Visibility::Public).await;
642 git(634 git(
643 &fx.work,635 &fx.work,
644 &[636 &[
@@ -676,6 +668,17 @@ mod tests {
676 assert!(html.contains("Body with 🎉 and 12:30:45"), "{html}");668 assert!(html.contains("Body with 🎉 and 12:30:45"), "{html}");
677 }669 }
678 670
671+ /// Every list scenario on one public repo. Order matters: the gitmoji scenario adds a commit on
672+ /// top, which would shift the pagination counts.
673+ #[tokio::test]
674+ async fn public_repo_commit_lists() {
675+ let fx = Fixture::new(Visibility::Public).await;
676+ scenario_pagination(&fx).await;
677+ scenario_path_filter(&fx).await;
678+ scenario_status_icons(&fx).await;
679+ scenario_gitmoji(&fx).await;
680+ }
681+
679 #[tokio::test]682 #[tokio::test]
680 async fn private_repo_is_404_for_anonymous() {683 async fn private_repo_is_404_for_anonymous() {
681 let fx = Fixture::new(Visibility::Private).await;684 let fx = Fixture::new(Visibility::Private).await;
crates/forge-web/src/pages/forgot.rsmodified+17 -12
@@ -260,6 +260,17 @@ mod tests {
260 (crate::test_support::app_router(state.clone()), state)260 (crate::test_support::app_router(state.clone()), state)
261 }261 }
262 262
263+ /// The three account flows share one app. The unknown-address scenario reads the whole outbox
264+ /// for reset mail, so it runs before the reset flow queues any.
265+ #[tokio::test]
266+ async fn forgot_and_reset_flows() {
267+ let tmp = tempfile::tempdir().expect("tempdir");
268+ let (router, state) = app(tmp.path()).await;
269+ scenario_same_answer(&router, &state).await;
270+ scenario_reset_once(&router, &state).await;
271+ scenario_weak_password(&router, &state).await;
272+ }
273+
263 /// Waits until a mail with `marker` in its body is in the outbox, and returns that body.274 /// Waits until a mail with `marker` in its body is in the outbox, and returns that body.
264 async fn wait_for_mail(state: &AppState, marker: &str) -> String {275 async fn wait_for_mail(state: &AppState, marker: &str) -> String {
265 for _ in 0..100 {276 for _ in 0..100 {
@@ -272,10 +283,8 @@ mod tests {
272 panic!("no mail with {marker}");283 panic!("no mail with {marker}");
273 }284 }
274 285
275- #[tokio::test]286+ /// Unknown and unverified addresses get the same answer, and no reset mail is queued.
276- async fn forgot_answers_the_same_for_unknown_and_unverified_addresses() {287+ async fn scenario_same_answer(router: &topcoat::router::Router, state: &AppState) {
277- let tmp = tempfile::tempdir().expect("tempdir");
278- let (router, state) = app(tmp.path()).await;
279 state288 state
280 .store289 .store
281 .create_user("frank", Some("frank@example.com"), "hash", false)290 .create_user("frank", Some("frank@example.com"), "hash", false)
@@ -296,10 +305,8 @@ mod tests {
296 assert!(mail.iter().all(|m| !m.body.contains("/reset/")));305 assert!(mail.iter().all(|m| !m.body.contains("/reset/")));
297 }306 }
298 307
299- #[tokio::test]308+ /// A reset link sets the password once; the spent link is refused.
300- async fn reset_link_works_once_and_sets_the_password() {309+ async fn scenario_reset_once(router: &topcoat::router::Router, state: &AppState) {
301- let tmp = tempfile::tempdir().expect("tempdir");
302- let (router, state) = app(tmp.path()).await;
303 let user = state310 let user = state
304 .store311 .store
305 .create_user("gina", Some("gina@example.com"), "old-hash", false)312 .create_user("gina", Some("gina@example.com"), "old-hash", false)
@@ -353,10 +360,8 @@ mod tests {
353 assert!(html.contains("This reset link is invalid"));360 assert!(html.contains("This reset link is invalid"));
354 }361 }
355 362
356- #[tokio::test]363+ /// A weak password is refused and the link stays live.
357- async fn a_weak_password_keeps_the_link_live() {364+ async fn scenario_weak_password(router: &topcoat::router::Router, state: &AppState) {
358- let tmp = tempfile::tempdir().expect("tempdir");
359- let (router, state) = app(tmp.path()).await;
360 let user = state365 let user = state
361 .store366 .store
362 .create_user("hal", Some("hal@example.com"), "old-hash", false)367 .create_user("hal", Some("hal@example.com"), "old-hash", false)
crates/forge-web/src/pages/fork.rsmodified+131 -156
@@ -286,9 +286,99 @@ mod tests {
286 .await286 .await
287 }287 }
288 288
289- #[tokio::test]289+ /// Refusals and the repo header, before anyone forks. A bad or missing token starts nothing,
290- async fn fork_copies_source_labels_and_adds_no_defaults() {290+ /// anonymous viewers go to login, a private repo is 404 to outsiders, the owner's own fork is
291- let (site, [_, bob, _]) = site().await;291+ /// a no-op, and the header offers the fork button only to a signed-in non-owner.
292+ async fn scenario_refusals(site: &Site, tahinli: &str, bob: &str, carol: &str) {
293+ let reply = send(
294+ site,
295+ "POST",
296+ "/tahinli/demo/fork",
297+ Some(bob),
298+ Some(String::new()),
299+ )
300+ .await;
301+ assert_eq!(reply.status, 403);
302+ let reply = send(
303+ site,
304+ "POST",
305+ "/tahinli/demo/fork",
306+ Some(bob),
307+ Some("csrf=wrong".into()),
308+ )
309+ .await;
310+ assert_eq!(reply.status, 403);
311+ assert!(
312+ site.store
313+ .repo_by_owner_and_name("bob", "demo")
314+ .await
315+ .expect("q")
316+ .is_none(),
317+ "nothing was created"
318+ );
319+
320+ let reply = fork(site, None).await;
321+ assert_eq!(reply.status, 303);
322+ assert!(
323+ reply
324+ .location
325+ .as_deref()
326+ .is_some_and(|l| l.starts_with("/login")),
327+ "{:?}",
328+ reply.location
329+ );
330+
331+ let reply = send(
332+ site,
333+ "POST",
334+ "/tahinli/secret/fork",
335+ Some(carol),
336+ Some(format!("csrf={CSRF}")),
337+ )
338+ .await;
339+ assert_eq!(reply.status, 404);
340+ let reply = send(
341+ site,
342+ "POST",
343+ "/tahinli/secret/fork",
344+ None,
345+ Some(format!("csrf={CSRF}")),
346+ )
347+ .await;
348+ assert_eq!(reply.status, 404, "anonymous viewers also get 404");
349+
350+ let reply = fork(site, Some(tahinli)).await;
351+ assert_eq!(reply.status, 303);
352+ assert_eq!(reply.location.as_deref(), Some("/tahinli/demo"));
353+ assert!(
354+ site.store
355+ .repo_by_owner_and_name("tahinli", "demo-1")
356+ .await
357+ .expect("q")
358+ .is_none()
359+ );
360+
361+ let reply = send(site, "GET", "/tahinli/demo", Some(carol), None).await;
362+ assert_eq!(reply.status, 200);
363+ assert!(
364+ reply.body.contains("href=\"/tahinli/demo/pulls\""),
365+ "pulls tab"
366+ );
367+ assert!(reply.body.contains("Pull requests"));
368+ assert!(
369+ reply.body.contains("action=\"/tahinli/demo/fork\""),
370+ "fork button"
371+ );
372+ let reply = send(site, "GET", "/tahinli/demo", None, None).await;
373+ assert!(
374+ !reply.body.contains("action=\"/tahinli/demo/fork\""),
375+ "no fork button when anonymous"
376+ );
377+ }
378+
379+ /// Bob's fork copies the source's labels and branches and nothing else, records one audit
380+ /// entry, and shows its source on the page.
381+ async fn scenario_fork_copies(site: &Site, bob: &str) {
292 let demo = site382 let demo = site
293 .store383 .store
294 .repo_by_owner_and_name("tahinli", "demo")384 .repo_by_owner_and_name("tahinli", "demo")
@@ -299,14 +389,26 @@ mod tests {
299 .create_label(&demo.id, "triage-me", "#123456", "only here")389 .create_label(&demo.id, "triage-me", "#123456", "only here")
300 .await390 .await
301 .expect("label");391 .expect("label");
302- let reply = fork(&site, Some(&bob)).await;392+ let reply = fork(site, Some(bob)).await;
303 assert_eq!(reply.status, 303);393 assert_eq!(reply.status, 303);
394+ assert_eq!(reply.location.as_deref(), Some("/bob/demo"));
395+
396+ let bob_id = site
397+ .store
398+ .user_by_username("bob")
399+ .await
400+ .expect("q")
401+ .expect("bob")
402+ .id;
304 let fork = site403 let fork = site
305 .store404 .store
306 .repo_by_owner_and_name("bob", "demo")405 .repo_by_owner_and_name("bob", "demo")
307 .await406 .await
308- .expect("query")407+ .expect("q")
309- .expect("fork");408+ .expect("fork row");
409+ assert_eq!(fork.fork_of.as_deref(), Some(demo.id.as_str()));
410+ assert_eq!(fork.visibility, Visibility::Public);
411+ assert_eq!(fork.owner_id, bob_id);
310 let labels: Vec<(String, String, String)> = site412 let labels: Vec<(String, String, String)> = site
311 .store413 .store
312 .list_labels(&fork.id)414 .list_labels(&fork.id)
@@ -323,37 +425,6 @@ mod tests {
323 "only here".to_string()425 "only here".to_string()
324 )]426 )]
325 );427 );
326- }
327-
328- #[tokio::test]
329- async fn fork_copies_branches_and_shows_the_source() {
330- let (site, [_, bob, _]) = site().await;
331- let reply = fork(&site, Some(&bob)).await;
332- assert_eq!(reply.status, 303);
333- assert_eq!(reply.location.as_deref(), Some("/bob/demo"));
334-
335- let bob_id = site
336- .store
337- .user_by_username("bob")
338- .await
339- .expect("q")
340- .expect("bob")
341- .id;
342- let source = site
343- .store
344- .repo_by_owner_and_name("tahinli", "demo")
345- .await
346- .expect("q")
347- .expect("source");
348- let fork = site
349- .store
350- .repo_by_owner_and_name("bob", "demo")
351- .await
352- .expect("q")
353- .expect("fork row");
354- assert_eq!(fork.fork_of.as_deref(), Some(source.id.as_str()));
355- assert_eq!(fork.visibility, Visibility::Public);
356- assert_eq!(fork.owner_id, bob_id);
357 428
358 let forked = site429 let forked = site
359 .store430 .store
@@ -387,7 +458,7 @@ mod tests {
387 vec!["refs/heads/main", "refs/tags/v1"]458 vec!["refs/heads/main", "refs/tags/v1"]
388 );459 );
389 460
390- let page = send(&site, "GET", "/bob/demo", Some(&bob), None).await;461+ let page = send(site, "GET", "/bob/demo", Some(bob), None).await;
391 assert_eq!(page.status, 200);462 assert_eq!(page.status, 200);
392 assert!(page.body.contains("forked from"), "fork line shown");463 assert!(page.body.contains("forked from"), "fork line shown");
393 assert!(464 assert!(
@@ -396,11 +467,10 @@ mod tests {
396 );467 );
397 }468 }
398 469
399- #[tokio::test]470+ /// Forking again goes to the existing fork and makes no `demo-1`.
400- async fn forking_twice_redirects_to_the_existing_fork() {471+ async fn scenario_fork_again(site: &Site, bob: &str) {
401- let (site, [_, bob, _]) = site().await;472+ assert_eq!(fork(site, Some(bob)).await.status, 303);
402- assert_eq!(fork(&site, Some(&bob)).await.status, 303);473+ let again = fork(site, Some(bob)).await;
403- let again = fork(&site, Some(&bob)).await;
404 assert_eq!(again.status, 303);474 assert_eq!(again.status, 303);
405 assert_eq!(again.location.as_deref(), Some("/bob/demo"));475 assert_eq!(again.location.as_deref(), Some("/bob/demo"));
406 assert!(476 assert!(
@@ -413,125 +483,30 @@ mod tests {
413 );483 );
414 }484 }
415 485
416- #[tokio::test]486+ /// Erin already has a `demo`, so her fork of the source takes the `-1` suffix.
417- async fn fork_name_gets_a_suffix_when_taken() {487+ async fn scenario_suffix(site: &Site) {
418- let (site, [_, bob, _]) = site().await;488+ let erin = site
419- let bob_user = site
420 .store489 .store
421- .user_by_username("bob")490+ .create_user("erin", None, "x", false)
422 .await491 .await
423- .expect("q")492+ .expect("erin");
424- .expect("bob");493+ let erin_cookie = sign_in(&site.store, &erin.id, "erin-token").await;
425 site.store494 site.store
426- .create_repo(&bob_user.id, "demo", "", Visibility::Private, "main")495+ .create_repo(&erin.id, "demo", "", Visibility::Private, "main")
427 .await496 .await
428- .expect("bob's own demo");497+ .expect("erin's own demo");
429- let reply = fork(&site, Some(&bob)).await;498+ let reply = fork(site, Some(&erin_cookie)).await;
430- assert_eq!(reply.location.as_deref(), Some("/bob/demo-1"));499+ assert_eq!(reply.location.as_deref(), Some("/erin/demo-1"));
431- }
432-
433- #[tokio::test]
434- async fn owner_forking_own_repo_is_a_no_op() {
435- let (site, [tahinli, _, _]) = site().await;
436- let reply = fork(&site, Some(&tahinli)).await;
437- assert_eq!(reply.status, 303);
438- assert_eq!(reply.location.as_deref(), Some("/tahinli/demo"));
439- assert!(
440- site.store
441- .repo_by_owner_and_name("tahinli", "demo-1")
442- .await
443- .expect("q")
444- .is_none()
445- );
446- }
447-
448- #[tokio::test]
449- async fn hidden_repo_is_404_for_a_non_collaborator() {
450- let (site, [_, _, carol]) = site().await;
451- let reply = send(
452- &site,
453- "POST",
454- "/tahinli/secret/fork",
455- Some(&carol),
456- Some(format!("csrf={CSRF}")),
457- )
458- .await;
459- assert_eq!(reply.status, 404);
460- let reply = send(
461- &site,
462- "POST",
463- "/tahinli/secret/fork",
464- None,
465- Some(format!("csrf={CSRF}")),
466- )
467- .await;
468- assert_eq!(reply.status, 404, "anonymous viewers also get 404");
469 }500 }
470 501
502+ /// Every fork scenario on one site. The refusals run first, since they assert that bob has no
503+ /// fork yet, and the fork scenarios then run in order.
471 #[tokio::test]504 #[tokio::test]
472- async fn anonymous_viewer_is_sent_to_login() {505+ async fn fork_flows() {
473- let (site, _) = site().await;506+ let (site, [tahinli, bob, carol]) = site().await;
474- let reply = fork(&site, None).await;507+ scenario_refusals(&site, &tahinli, &bob, &carol).await;
475- assert_eq!(reply.status, 303);508+ scenario_fork_copies(&site, &bob).await;
476- assert!(509+ scenario_fork_again(&site, &bob).await;
477- reply510+ scenario_suffix(&site).await;
478- .location
479- .as_deref()
480- .is_some_and(|l| l.starts_with("/login")),
481- "{:?}",
482- reply.location
483- );
484- }
485-
486- #[tokio::test]
487- async fn missing_or_wrong_csrf_is_rejected() {
488- let (site, [_, bob, _]) = site().await;
489- let reply = send(
490- &site,
491- "POST",
492- "/tahinli/demo/fork",
493- Some(&bob),
494- Some(String::new()),
495- )
496- .await;
497- assert_eq!(reply.status, 403);
498- let reply = send(
499- &site,
500- "POST",
501- "/tahinli/demo/fork",
502- Some(&bob),
503- Some("csrf=wrong".into()),
504- )
505- .await;
506- assert_eq!(reply.status, 403);
507- assert!(
508- site.store
509- .repo_by_owner_and_name("bob", "demo")
510- .await
511- .expect("q")
512- .is_none(),
513- "nothing was created"
514- );
515- }
516-
517- #[tokio::test]
518- async fn repo_header_shows_pull_requests_tab_and_fork_button() {
519- let (site, [_, bob, _]) = site().await;
520- let reply = send(&site, "GET", "/tahinli/demo", Some(&bob), None).await;
521- assert_eq!(reply.status, 200);
522- assert!(
523- reply.body.contains("href=\"/tahinli/demo/pulls\""),
524- "pulls tab"
525- );
526- assert!(reply.body.contains("Pull requests"));
527- assert!(
528- reply.body.contains("action=\"/tahinli/demo/fork\""),
529- "fork button"
530- );
531- let reply = send(&site, "GET", "/tahinli/demo", None, None).await;
532- assert!(
533- !reply.body.contains("action=\"/tahinli/demo/fork\""),
534- "no fork button when anonymous"
535- );
536 }511 }
537 }512 }
crates/forge-web/src/pages/import_tests.rsmodified+28 -15
@@ -68,9 +68,8 @@ async fn send(
68 (status, String::from_utf8_lossy(&bytes).into_owned())68 (status, String::from_utf8_lossy(&bytes).into_owned())
69 }69 }
70 70
71-#[tokio::test]71+/// The import and export pages render for a signed-in user.
72-async fn the_import_pages_render_for_a_signed_in_user() {72+async fn scenario_pages_render(fx: &Fixture) {
73- let fx = fixture().await;
74 for (uri, needle) in [73 for (uri, needle) in [
75 ("/new/import?source=git", "Import a repository"),74 ("/new/import?source=git", "Import a repository"),
76 ("/new/import?source=github", "Import a repository"),75 ("/new/import?source=github", "Import a repository"),
@@ -88,9 +87,8 @@ async fn the_import_pages_render_for_a_signed_in_user() {
88 }87 }
89 }88 }
90 89
91-#[tokio::test]90+/// Without a session, the import and export pages do not render.
92-async fn the_import_and_export_pages_need_a_session() {91+async fn scenario_need_session(fx: &Fixture) {
93- let fx = fixture().await;
94 for uri in [92 for uri in [
95 "/new/import",93 "/new/import",
96 "/new/import/bulk",94 "/new/import/bulk",
@@ -102,9 +100,8 @@ async fn the_import_and_export_pages_need_a_session() {
102 }100 }
103 }101 }
104 102
105-#[tokio::test]103+/// A POST with a bad CSRF token starts no import and no export.
106-async fn a_post_without_the_csrf_token_starts_nothing() {104+async fn scenario_csrf(fx: &Fixture) {
107- let fx = fixture().await;
108 let form = "source=git&remote=https%3A%2F%2Fexample.org%2Fa.git&csrf=wrong".to_owned();105 let form = "source=git&remote=https%3A%2F%2Fexample.org%2Fa.git&csrf=wrong".to_owned();
109 let (status, _) = send(&fx.router, "POST", "/new/import", Some(TOKEN), Some(form)).await;106 let (status, _) = send(&fx.router, "POST", "/new/import", Some(TOKEN), Some(form)).await;
110 assert_ne!(status, 303, "a bad token must not redirect to a job");107 assert_ne!(status, 303, "a bad token must not redirect to a job");
@@ -133,9 +130,8 @@ async fn a_post_without_the_csrf_token_starts_nothing() {
133 );130 );
134 }131 }
135 132
136-#[tokio::test]133+/// A private address is refused before any job exists.
137-async fn a_private_address_is_refused_before_any_job_exists() {134+async fn scenario_private_address(fx: &Fixture) {
138- let fx = fixture().await;
139 let form = format!(135 let form = format!(
140 "csrf={CSRF}&source=git&remote=https%3A%2F%2F127.0.0.1%2Fa.git&owner=tahinli&visibility=private"136 "csrf={CSRF}&source=git&remote=https%3A%2F%2F127.0.0.1%2Fa.git&owner=tahinli&visibility=private"
141 );137 );
@@ -151,9 +147,8 @@ async fn a_private_address_is_refused_before_any_job_exists() {
151 );147 );
152 }148 }
153 149
154-#[tokio::test]150+/// Another user's archive is not found. This creates an export for the owner, so it runs last.
155-async fn another_users_archive_cannot_be_downloaded() {151+async fn scenario_archive(fx: &Fixture) {
156- let fx = fixture().await;
157 let export = fx152 let export = fx
158 .store153 .store
159 .create_export(&fx.user_id, std::time::Duration::from_secs(3600))154 .create_export(&fx.user_id, std::time::Duration::from_secs(3600))
@@ -169,3 +164,21 @@ async fn another_users_archive_cannot_be_downloaded() {
169 let (status, _) = send(&fx.router, "GET", &uri, None, None).await;164 let (status, _) = send(&fx.router, "GET", &uri, None, None).await;
170 assert_ne!(status, 200);165 assert_ne!(status, 200);
171 }166 }
167+
168+/// The read-only pages, on one fixture.
169+#[tokio::test]
170+async fn import_and_export_pages_render_and_need_a_session() {
171+ let fx = fixture().await;
172+ scenario_pages_render(&fx).await;
173+ scenario_need_session(&fx).await;
174+}
175+
176+/// Writes and downloads on one fixture. The CSRF and private-address checks assert that no job
177+/// exists, so they run before the archive scenario creates an export.
178+#[tokio::test]
179+async fn import_and_export_writes_are_refused_or_scoped() {
180+ let fx = fixture().await;
181+ scenario_csrf(&fx).await;
182+ scenario_private_address(&fx).await;
183+ scenario_archive(&fx).await;
184+}