forge
Explore
Log in

Don't you dare go Hollow

Page tests share their fixtures and merge into tables

Browse files at this commit

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

Counts for the three page files: releases_tests 22 -> 9, repo 15 -> 9,
repo_secrets 7 -> 5 (44 -> 23 tests).

Merged: release scenarios share one fixture per group with unique tags
and releases; the blob-count check runs first in its fixture. The repo
read-only pages and 404 checks share one fixture. Secret refusals share
one fixture, and the value-leak check runs before the language switch.

Kept separate: the three release live-stream tests, the repo push-banner
tests (push events accumulate in a shared repo), and the pure
names_follow_the_pattern test.
crates/forge-web/src/pages/releases_tests.rsmodified+448 -425
@@ -214,9 +214,39 @@ impl Fixture {
214 }214 }
215 }215 }
216 216
217+/// The release's own fields, unchanged, with no tag change.
218+fn keep(rel: &Release) -> EditRelease {
219+ EditRelease {
220+ title: rel.title.clone(),
221+ body: rel.body.clone(),
222+ draft: rel.draft,
223+ prerelease: rel.prerelease,
224+ tag: None,
225+ target: None,
226+ }
227+}
228+
229+/// Adds a commit on top of `main` and points branch `next` at it. Returns the new commit.
230+fn second_commit(fx: &Fixture) -> String {
231+ let tree = git(&fx.bare, &["rev-parse", "refs/heads/main^{tree}"]);
232+ let next = git(
233+ &fx.bare,
234+ &["commit-tree", &tree, "-p", &fx.main_tip(), "-m", "two"],
235+ );
236+ git(&fx.bare, &["update-ref", "refs/heads/next", &next]);
237+ next
238+}
239+
240+// Each test below builds one fixture and runs its scenarios in order. Scenarios use their own
241+// tags and releases so they do not interfere, and the blob-count check in the size-cap test runs
242+// first, before any blob exists in its fixture.
243+
217 #[tokio::test]244 #[tokio::test]
218-async fn drafts_are_hidden_from_readers_and_visible_to_writers() {245+async fn drafts_and_permissions_share_one_repo() {
219 let fx = fixture(None).await;246 let fx = fixture(None).await;
247+
248+ // Drafts: readers see the published release only, owners see the draft too.
249+ {
220 let published = fx.release("v1.0", false).await;250 let published = fx.release("v1.0", false).await;
221 let draft = fx.release("v2.0", true).await;251 let draft = fx.release("v2.0", true).await;
222 let draft_asset = fx252 let draft_asset = fx
@@ -249,7 +279,7 @@ async fn drafts_are_hidden_from_readers_and_visible_to_writers() {
249 Vec::new(),279 Vec::new(),
250 )280 )
251 .await;281 .await;
252- assert_eq!(anon_draft.status, 404);282+ assert_eq!(anon_draft.status, 404, "anonymous draft page");
253 let anon_download = send(283 let anon_download = send(
254 &fx.app,284 &fx.app,
255 "GET",285 "GET",
@@ -287,10 +317,9 @@ async fn drafts_are_hidden_from_readers_and_visible_to_writers() {
287 assert_eq!(published.tag, "v1.0");317 assert_eq!(published.tag, "v1.0");
288 }318 }
289 319
290-#[tokio::test]320+ // Readers cannot create, edit, upload or delete.
291-async fn readers_cannot_create_edit_upload_or_delete() {321+ {
292- let fx = fixture(None).await;322+ let rel = fx.release("v3.0", false).await;
293- let rel = fx.release("v1.0", false).await;
294 323
295 let create = send(324 let create = send(
296 &fx.app,325 &fx.app,
@@ -321,7 +350,7 @@ async fn readers_cannot_create_edit_upload_or_delete() {
321 form(&[("csrf", CSRF), ("title", "hacked"), ("body", "")]),350 form(&[("csrf", CSRF), ("title", "hacked"), ("body", "")]),
322 )351 )
323 .await;352 .await;
324- assert_ne!(edit.status, 303);353+ assert_ne!(edit.status, 303, "a reader cannot edit");
325 assert_eq!(354 assert_eq!(
326 fx.store355 fx.store
327 .release(&rel.id)356 .release(&rel.id)
@@ -329,11 +358,11 @@ async fn readers_cannot_create_edit_upload_or_delete() {
329 .expect("read")358 .expect("read")
330 .expect("row")359 .expect("row")
331 .title,360 .title,
332- "Release v1.0"361+ "Release v3.0"
333 );362 );
334 363
335 let upload = fx.upload(&rel.id, "a.bin", b"data", &fx.bob_cookie).await;364 let upload = fx.upload(&rel.id, "a.bin", b"data", &fx.bob_cookie).await;
336- assert_ne!(upload.status, 303);365+ assert_ne!(upload.status, 303, "a reader cannot upload");
337 assert!(366 assert!(
338 fx.store367 fx.store
339 .list_release_assets(&rel.id)368 .list_release_assets(&rel.id)
@@ -351,13 +380,29 @@ async fn readers_cannot_create_edit_upload_or_delete() {
351 form(&[("csrf", CSRF), ("confirm", "on")]),380 form(&[("csrf", CSRF), ("confirm", "on")]),
352 )381 )
353 .await;382 .await;
354- assert_ne!(delete.status, 303);383+ assert_ne!(delete.status, 303, "a reader cannot delete");
355 assert!(fx.store.release(&rel.id).await.expect("read").is_some());384 assert!(fx.store.release(&rel.id).await.expect("read").is_some());
356 }385 }
357 386
387+ // The repo home shows the latest release card and links to the releases tab.
388+ {
389+ fx.release("v0.9-beta", false).await;
390+ let home = send(&fx.app, "GET", "/tahinli/proj", None, None, Vec::new()).await;
391+ assert_eq!(home.status, 200);
392+ assert!(home.text().contains("Latest release"));
393+ assert!(
394+ home.text().contains("/tahinli/proj/releases"),
395+ "the tabs link to releases"
396+ );
397+ }
398+}
399+
358 #[tokio::test]400 #[tokio::test]
359-async fn a_missing_tag_is_created_as_a_lightweight_tag_on_the_branch_head() {401+async fn creating_a_release_takes_and_validates_its_tag_and_target() {
360 let fx = fixture(None).await;402 let fx = fixture(None).await;
403+
404+ // A missing tag is created as a lightweight tag on the branch head.
405+ {
361 let reply = send(406 let reply = send(
362 &fx.app,407 &fx.app,
363 "POST",408 "POST",
@@ -390,9 +435,8 @@ async fn a_missing_tag_is_created_as_a_lightweight_tag_on_the_branch_head() {
390 assert!(release.published_at.is_some());435 assert!(release.published_at.is_some());
391 }436 }
392 437
393-#[tokio::test]438+ // An existing tag is used as it is and never moved.
394-async fn an_existing_tag_is_used_as_it_is_and_never_moved() {439+ {
395- let fx = fixture(None).await;
396 git(&fx.bare, &["tag", "v0.9", "refs/heads/main"]);440 git(&fx.bare, &["tag", "v0.9", "refs/heads/main"]);
397 let before = fx.tag_target("v0.9");441 let before = fx.tag_target("v0.9");
398 let reply = send(442 let reply = send(
@@ -409,382 +453,136 @@ async fn an_existing_tag_is_used_as_it_is_and_never_moved() {
409 ]),453 ]),
410 )454 )
411 .await;455 .await;
412- assert_eq!(reply.status, 303);456+ assert_eq!(reply.status, 303, "existing tag");
413- assert_eq!(fx.tag_target("v0.9"), before);457+ assert_eq!(fx.tag_target("v0.9"), before, "existing tag is not moved");
414 }458 }
415 459
416-#[tokio::test]460+ // Create refuses a bad tag or a missing target before touching git, and takes a commit id as
417-async fn upload_then_download_round_trips_and_counts() {461+ // a target.
418- let fx = fixture(None).await;462+ {
419- let rel = fx.release("v1.0", false).await;463+ let input = |tag: &str, target: &str| CreateRelease {
420- let payload = b"<html>not rendered</html>";464+ tag: tag.to_owned(),
421- let reply = fx465+ target: Some(target.to_owned()),
422- .upload(&rel.id, "app.bin", payload, &fx.tahinli_cookie)466+ title: "x".to_owned(),
423- .await;467+ body: String::new(),
424- assert_eq!(reply.status, 303, "body: {}", reply.text());468+ draft: false,
469+ prerelease: false,
470+ };
471+ let refused =
472+ release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input("a/b", "main")).await;
425 assert!(473 assert!(
426- reply474+ matches!(refused, Err(ReleaseError::Invalid(_))),
427- .location475+ "bad tag: {refused:?}"
428- .unwrap_or_default()
429- .contains("notice=asset-uploaded")
430 );476 );
477+ assert!(fx.tag_target("a/b").is_none(), "bad tag");
431 478
432- let row = fx479+ let tip = fx.main_tip();
433- .store480+ let made = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input("v7", &tip))
434- .release_asset(&rel.id, "app.bin")
435 .await481 .await
436- .expect("read")482+ .expect("a commit id works as a target");
437- .expect("asset row");483+ assert_eq!(made.target_oid, tip, "commit id target");
438- assert_eq!(row.size, payload.len() as u64);484+ assert_eq!(
439- let digest = {485+ fx.tag_target("v7").as_deref(),
440- use sha2::{Digest, Sha256};486+ Some(tip.as_str()),
441- hex::encode(Sha256::digest(payload))487+ "commit id target"
442- };488+ );
443- assert_eq!(row.sha256, digest);
444 489
445- for expected in 1..=2u64 {490+ let missing = release_ops::create(
446- let got = send(491+ &fx.state,
447- &fx.app,492+ &fx.repo,
448- "GET",493+ &fx.tahinli,
449- "/tahinli/proj/releases/download/v1.0/app.bin",494+ input("v8", "1111111111111111111111111111111111111111"),
450- None,
451- None,
452- Vec::new(),
453 )495 )
454 .await;496 .await;
455- assert_eq!(got.status, 200);497+ assert!(
456- assert_eq!(got.body, payload);498+ matches!(missing, Err(ReleaseError::Invalid(_))),
457- assert_eq!(499+ "missing target: {missing:?}"
458- got.headers
459- .get("content-disposition")
460- .and_then(|v| v.to_str().ok()),
461- Some("attachment; filename=\"app.bin\"")
462- );
463- assert_eq!(
464- got.headers
465- .get("x-content-type-options")
466- .and_then(|v| v.to_str().ok()),
467- Some("nosniff")
468 );500 );
469- let counted = fx501+ assert!(fx.tag_target("v8").is_none(), "missing target");
470- .store
471- .release_asset(&rel.id, "app.bin")
472- .await
473- .expect("read")
474- .expect("row");
475- assert_eq!(counted.download_count, expected);
476 }502 }
477 }503 }
478 504
479 #[tokio::test]505 #[tokio::test]
480-async fn a_csrf_mismatch_on_upload_is_refused_and_stores_nothing() {506+async fn retagging_rules_hold_for_published_and_draft_releases() {
481 let fx = fixture(None).await;507 let fx = fixture(None).await;
508+
509+ // A published release moves to a new tag and keeps the old git tag.
510+ {
511+ git(&fx.bare, &["tag", "v1.0", "refs/heads/main"]);
482 let rel = fx.release("v1.0", false).await;512 let rel = fx.release("v1.0", false).await;
483- let (content_type, body) = crate::pages::settings_profile::tests::multipart(&[513+ let edit = EditRelease {
484- ("csrf", None, b"wrong"),514+ tag: Some("v1.1".to_owned()),
485- ("file", Some(("a.bin", "application/octet-stream")), b"data"),515+ ..keep(&rel)
486- ]);516+ };
487- let reply = send(517+ let moved = release_ops::update(&fx.state, &fx.repo, &fx.tahinli, &rel, edit)
488- &fx.app,518+ .await
489- "POST",519+ .expect("retag");
490- &format!("/tahinli/proj/releases/{}/assets", rel.id),520+ assert_eq!(moved.tag, "v1.1");
491- Some(&fx.tahinli_cookie),521+ assert_eq!(moved.target_oid, fx.main_tip());
492- Some(&content_type),522+ assert_eq!(
493- body,523+ fx.tag_target("v1.1").as_deref(),
494- )524+ Some(fx.main_tip().as_str())
495- .await;525+ );
496- assert_ne!(reply.status, 303);526+ assert!(fx.tag_target("v1.0").is_some(), "the old git tag is kept");
497 assert!(527 assert!(
498 fx.store528 fx.store
499- .list_release_assets(&rel.id)529+ .release_by_tag(&fx.repo.id, "v1.0")
500 .await530 .await
501- .expect("assets")531+ .expect("read")
502- .is_empty()532+ .is_none(),
533+ "the old tag no longer names a release"
503 );534 );
504 }535 }
505 536
506-#[tokio::test]537+ // A published tag cannot be moved in place, but a draft can.
507-async fn an_upload_over_the_size_cap_is_refused_and_leaves_no_blob() {538+ {
508- let fx = fixture(Some(1)).await;539+ git(&fx.bare, &["tag", "v2.0", "refs/heads/main"]);
509- let rel = fx.release("v1.0", false).await;540+ let next = second_commit(&fx);
510- let big = vec![7u8; 1024 * 1024 + 4096];541+ let published = fx.release("v2.0", false).await;
511- let reply = fx542+ let move_published = EditRelease {
512- .upload(&rel.id, "big.bin", &big, &fx.tahinli_cookie)543+ target: Some("next".to_owned()),
513- .await;544+ ..keep(&published)
514- assert_eq!(reply.status, 303);545+ };
546+ let refused =
547+ release_ops::update(&fx.state, &fx.repo, &fx.tahinli, &published, move_published).await;
515 assert!(548 assert!(
516- reply549+ matches!(refused, Err(ReleaseError::Invalid(_))),
517- .location550+ "{refused:?}"
518- .unwrap_or_default()
519- .contains("notice=asset-too-large"),
520- "the cap refuses the file"
521 );551 );
522- assert!(552+ assert_eq!(
523- fx.store553+ fx.tag_target("v2.0").as_deref(),
524- .list_release_assets(&rel.id)554+ Some(fx.main_tip().as_str()),
525- .await555+ "published tag stays put"
526- .expect("assets")
527- .is_empty()
528 );556 );
529- let assets_dir = fx.state.config.data_dir.join("blobs").join("assets");
530- let leftovers = std::fs::read_dir(&assets_dir)
531- .map(|entries| entries.count())
532- .unwrap_or(0);
533- assert_eq!(leftovers, 0, "no partial blob is left behind");
534-}
535 557
536-#[tokio::test]558+ let draft = fx
537-async fn deleting_a_release_keeps_the_tag_and_removes_its_assets() {
538- let fx = fixture(None).await;
539- git(&fx.bare, &["tag", "v1.0", "refs/heads/main"]);
540- let rel = fx.release("v1.0", false).await;
541- let up = fx
542- .upload(&rel.id, "gone.bin", b"bytes", &fx.tahinli_cookie)
543- .await;
544- assert_eq!(up.status, 303);
545- let asset = fx
546 .store559 .store
547- .release_asset(&rel.id, "gone.bin")560+ .create_release(&forge_core::releases::NewRelease {
561+ repo_id: &fx.repo.id,
562+ tag: "v3.0",
563+ target_oid: &fx.main_tip(),
564+ title: "draft",
565+ body: "",
566+ draft: true,
567+ prerelease: false,
568+ author_id: &fx.tahinli.id,
569+ })
548 .await570 .await
549- .expect("read")571+ .expect("draft");
550- .expect("row");572+ git(&fx.bare, &["tag", "v3.0", "refs/heads/main"]);
551- let blob = crate::blobs::asset_key(&asset.id);573+ let move_draft = EditRelease {
552- assert!(fx.state.blobs.read(&blob).await.expect("read").is_some());574+ target: Some("next".to_owned()),
553-575+ ..keep(&draft)
554- let reply = send(576+ };
555- &fx.app,577+ let moved = release_ops::update(&fx.state, &fx.repo, &fx.tahinli, &draft, move_draft)
556- "POST",578+ .await
557- &format!("/tahinli/proj/releases/{}/delete", rel.id),579+ .expect("draft moves");
558- Some(&fx.tahinli_cookie),580+ assert_eq!(moved.target_oid, next);
559- Some(FORM_TYPE),581+ assert_eq!(fx.tag_target("v3.0"), Some(next));
560- form(&[("csrf", CSRF), ("confirm", "on")]),
561- )
562- .await;
563- assert_eq!(reply.status, 303);
564- assert!(fx.store.release(&rel.id).await.expect("read").is_none());
565- assert!(fx.tag_target("v1.0").is_some(), "the git tag survives");
566- assert!(
567- fx.state.blobs.read(&blob).await.expect("read").is_none(),
568- "the blob is gone"
569- );
570- let download = send(
571- &fx.app,
572- "GET",
573- "/tahinli/proj/releases/download/v1.0/gone.bin",
574- None,
575- None,
576- Vec::new(),
577- )
578- .await;
579- assert_eq!(download.status, 404);
580 }582 }
581 583
582-#[tokio::test]584+ // Retagging adopts an existing tag and refuses clashes and bad names.
583-async fn the_latest_release_card_shows_on_the_repo_home() {585+ {
584- let fx = fixture(None).await;
585- fx.release("v1.0", false).await;
586- fx.release("v0.9-beta", false).await;
587- let home = send(&fx.app, "GET", "/tahinli/proj", None, None, Vec::new()).await;
588- assert_eq!(home.status, 200);
589- assert!(home.text().contains("Latest release"));
590- assert!(
591- home.text().contains("/tahinli/proj/releases"),
592- "the tabs link to releases"
593- );
594-}
595-
596-/// The release's own fields, unchanged, with no tag change.
597-fn keep(rel: &Release) -> EditRelease {
598- EditRelease {
599- title: rel.title.clone(),
600- body: rel.body.clone(),
601- draft: rel.draft,
602- prerelease: rel.prerelease,
603- tag: None,
604- target: None,
605- }
606-}
607-
608-/// Adds a commit on top of `main` and points branch `next` at it. Returns the new commit.
609-fn second_commit(fx: &Fixture) -> String {
610- let tree = git(&fx.bare, &["rev-parse", "refs/heads/main^{tree}"]);
611- let next = git(
612- &fx.bare,
613- &["commit-tree", &tree, "-p", &fx.main_tip(), "-m", "two"],
614- );
615- git(&fx.bare, &["update-ref", "refs/heads/next", &next]);
616- next
617-}
618-
619-#[tokio::test]
620-async fn a_second_upload_under_the_same_name_replaces_the_file() {
621- let fx = fixture(None).await;
622- let rel = fx.release("v1.0", false).await;
623- let first = fx
624- .upload(&rel.id, "app.bin", b"first", &fx.tahinli_cookie)
625- .await;
626- assert_eq!(first.status, 303);
627- let before = fx
628- .store
629- .release_asset(&rel.id, "app.bin")
630- .await
631- .expect("read")
632- .expect("row");
633- fx.store
634- .count_asset_download(&before.id)
635- .await
636- .expect("count");
637-
638- let second = fx
639- .upload(&rel.id, "app.bin", b"second bytes", &fx.tahinli_cookie)
640- .await;
641- assert!(
642- second
643- .location
644- .unwrap_or_default()
645- .contains("notice=asset-replaced"),
646- "a same-name upload replaces instead of refusing"
647- );
648- let assets = fx.store.list_release_assets(&rel.id).await.expect("assets");
649- assert_eq!(assets.len(), 1, "still one asset of that name");
650- let after = &assets[0];
651- assert_ne!(after.id, before.id, "the new file has its own blob");
652- assert_eq!(after.size, 12);
653- assert_eq!(after.download_count, 1, "the download counter survives");
654- assert!(
655- fx.state
656- .blobs
657- .read(&asset_key(&before.id))
658- .await
659- .expect("read")
660- .is_none(),
661- "the replaced blob is deleted"
662- );
663- let got = send(
664- &fx.app,
665- "GET",
666- "/tahinli/proj/releases/download/v1.0/app.bin",
667- None,
668- None,
669- Vec::new(),
670- )
671- .await;
672- assert_eq!(got.body, b"second bytes");
673-}
674-
675-#[tokio::test]
676-async fn a_refused_replacement_keeps_the_old_file() {
677- let fx = fixture(Some(1)).await;
678- let rel = fx.release("v1.0", false).await;
679- fx.upload(&rel.id, "app.bin", b"keep me", &fx.tahinli_cookie)
680- .await;
681- let big = vec![7u8; 1024 * 1024 + 4096];
682- let reply = fx
683- .upload(&rel.id, "app.bin", &big, &fx.tahinli_cookie)
684- .await;
685- assert!(
686- reply
687- .location
688- .unwrap_or_default()
689- .contains("notice=asset-too-large")
690- );
691- let row = fx
692- .store
693- .release_asset(&rel.id, "app.bin")
694- .await
695- .expect("read")
696- .expect("row");
697- assert_eq!(row.size, 7);
698- let got = send(
699- &fx.app,
700- "GET",
701- "/tahinli/proj/releases/download/v1.0/app.bin",
702- None,
703- None,
704- Vec::new(),
705- )
706- .await;
707- assert_eq!(got.body, b"keep me");
708-}
709-
710-#[tokio::test]
711-async fn a_published_release_moves_to_a_new_tag_and_keeps_the_old_git_tag() {
712- let fx = fixture(None).await;
713- git(&fx.bare, &["tag", "v1.0", "refs/heads/main"]);
714- let rel = fx.release("v1.0", false).await;
715- let edit = EditRelease {
716- tag: Some("v1.1".to_owned()),
717- ..keep(&rel)
718- };
719- let moved = release_ops::update(&fx.state, &fx.repo, &fx.tahinli, &rel, edit)
720- .await
721- .expect("retag");
722- assert_eq!(moved.tag, "v1.1");
723- assert_eq!(moved.target_oid, fx.main_tip());
724- assert_eq!(
725- fx.tag_target("v1.1").as_deref(),
726- Some(fx.main_tip().as_str())
727- );
728- assert!(fx.tag_target("v1.0").is_some(), "the old git tag is kept");
729- assert!(
730- fx.store
731- .release_by_tag(&fx.repo.id, "v1.0")
732- .await
733- .expect("read")
734- .is_none()
735- );
736-}
737-
738-#[tokio::test]
739-async fn a_published_tag_cannot_be_moved_in_place_but_a_draft_can() {
740- let fx = fixture(None).await;
741- git(&fx.bare, &["tag", "v2.0", "refs/heads/main"]);
742- let next = second_commit(&fx);
743- let published = fx.release("v2.0", false).await;
744- let move_published = EditRelease {
745- target: Some("next".to_owned()),
746- ..keep(&published)
747- };
748- let refused =
749- release_ops::update(&fx.state, &fx.repo, &fx.tahinli, &published, move_published).await;
750- assert!(
751- matches!(refused, Err(ReleaseError::Invalid(_))),
752- "{refused:?}"
753- );
754- assert_eq!(
755- fx.tag_target("v2.0").as_deref(),
756- Some(fx.main_tip().as_str())
757- );
758-
759- let draft = fx
760- .store
761- .create_release(&forge_core::releases::NewRelease {
762- repo_id: &fx.repo.id,
763- tag: "v3.0",
764- target_oid: &fx.main_tip(),
765- title: "draft",
766- body: "",
767- draft: true,
768- prerelease: false,
769- author_id: &fx.tahinli.id,
770- })
771- .await
772- .expect("draft");
773- git(&fx.bare, &["tag", "v3.0", "refs/heads/main"]);
774- let move_draft = EditRelease {
775- target: Some("next".to_owned()),
776- ..keep(&draft)
777- };
778- let moved = release_ops::update(&fx.state, &fx.repo, &fx.tahinli, &draft, move_draft)
779- .await
780- .expect("draft moves");
781- assert_eq!(moved.target_oid, next);
782- assert_eq!(fx.tag_target("v3.0"), Some(next));
783-}
784-
785-#[tokio::test]
786-async fn retagging_adopts_an_existing_tag_and_refuses_clashes() {
787- let fx = fixture(None).await;
788 git(&fx.bare, &["tag", "v0.9", "refs/heads/main"]);586 git(&fx.bare, &["tag", "v0.9", "refs/heads/main"]);
789 let next = second_commit(&fx);587 let next = second_commit(&fx);
790 let draft = fx.release("v5", true).await;588 let draft = fx.release("v5", true).await;
@@ -794,7 +592,8 @@ async fn retagging_adopts_an_existing_tag_and_refuses_clashes() {
794 target: Some("next".to_owned()),592 target: Some("next".to_owned()),
795 ..keep(&draft)593 ..keep(&draft)
796 };594 };
797- let refused = release_ops::update(&fx.state, &fx.repo, &fx.tahinli, &draft, clash_target).await;595+ let refused =
596+ release_ops::update(&fx.state, &fx.repo, &fx.tahinli, &draft, clash_target).await;
798 assert!(597 assert!(
799 matches!(refused, Err(ReleaseError::Invalid(_))),598 matches!(refused, Err(ReleaseError::Invalid(_))),
800 "{refused:?}"599 "{refused:?}"
@@ -829,55 +628,14 @@ async fn retagging_adopts_an_existing_tag_and_refuses_clashes() {
829 "{invalid:?}"628 "{invalid:?}"
830 );629 );
831 }630 }
832-
833-/// Create refuses a bad tag or a missing target before touching git, and takes a commit id as a
834-/// target.
835-#[tokio::test]
836-async fn create_validates_its_tag_and_target() {
837- let fx = fixture(None).await;
838- let input = |tag: &str, target: &str| CreateRelease {
839- tag: tag.to_owned(),
840- target: Some(target.to_owned()),
841- title: "x".to_owned(),
842- body: String::new(),
843- draft: false,
844- prerelease: false,
845- };
846- let refused = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input("a/b", "main")).await;
847- assert!(
848- matches!(refused, Err(ReleaseError::Invalid(_))),
849- "bad tag: {refused:?}"
850- );
851- assert!(fx.tag_target("a/b").is_none(), "bad tag");
852-
853- let tip = fx.main_tip();
854- let made = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input("v7", &tip))
855- .await
856- .expect("a commit id works as a target");
857- assert_eq!(made.target_oid, tip, "commit id target");
858- assert_eq!(
859- fx.tag_target("v7").as_deref(),
860- Some(tip.as_str()),
861- "commit id target"
862- );
863-
864- let missing = release_ops::create(
865- &fx.state,
866- &fx.repo,
867- &fx.tahinli,
868- input("v8", "1111111111111111111111111111111111111111"),
869- )
870- .await;
871- assert!(
872- matches!(missing, Err(ReleaseError::Invalid(_))),
873- "missing target: {missing:?}"
874- );
875- assert!(fx.tag_target("v8").is_none(), "missing target");
876 }631 }
877 632
878 #[tokio::test]633 #[tokio::test]
879-async fn the_edit_page_shows_tag_and_target_controls_and_hides_the_target_once_published() {634+async fn the_edit_page_and_its_form_follow_the_publish_state() {
880 let fx = fixture(None).await;635 let fx = fixture(None).await;
636+
637+ // The edit page shows tag and target controls, and hides the target once published.
638+ {
881 let draft = fx.release("v1.0", true).await;639 let draft = fx.release("v1.0", true).await;
882 let published = fx.release("v2.0", false).await;640 let published = fx.release("v2.0", false).await;
883 641
@@ -916,11 +674,10 @@ async fn the_edit_page_shows_tag_and_target_controls_and_hides_the_target_once_p
916 );674 );
917 }675 }
918 676
919-#[tokio::test]677+ // A published release can be retagged through the form and keeps its commit.
920-async fn a_published_release_can_be_retagged_through_the_form_and_keeps_its_commit() {678+ {
921- let fx = fixture(None).await;679+ git(&fx.bare, &["tag", "v4.0", "refs/heads/main"]);
922- git(&fx.bare, &["tag", "v2.0", "refs/heads/main"]);680+ let published = fx.release("v4.0", false).await;
923- let published = fx.release("v2.0", false).await;
924 let reply = send(681 let reply = send(
925 &fx.app,682 &fx.app,
926 "POST",683 "POST",
@@ -929,9 +686,9 @@ async fn a_published_release_can_be_retagged_through_the_form_and_keeps_its_comm
929 Some(FORM_TYPE),686 Some(FORM_TYPE),
930 form(&[687 form(&[
931 ("csrf", CSRF),688 ("csrf", CSRF),
932- ("tag", "v2.1"),689+ ("tag", "v4.1"),
933 ("target", ""),690 ("target", ""),
934- ("title", "Release v2.0"),691+ ("title", "Release v4.0"),
935 ("body", "notes"),692 ("body", "notes"),
936 ]),693 ]),
937 )694 )
@@ -944,21 +701,26 @@ async fn a_published_release_can_be_retagged_through_the_form_and_keeps_its_comm
944 .await701 .await
945 .expect("read")702 .expect("read")
946 .expect("row");703 .expect("row");
947- assert_eq!(moved.tag, "v2.1");704+ assert_eq!(moved.tag, "v4.1");
948- assert_eq!(fx.tag_target("v2.1"), Some(fx.main_tip()));705+ assert_eq!(fx.tag_target("v4.1"), Some(fx.main_tip()));
949 assert_eq!(706 assert_eq!(
950- fx.tag_target("v2.0"),707+ fx.tag_target("v4.0"),
951 Some(fx.main_tip()),708 Some(fx.main_tip()),
952 "old git tag kept"709 "old git tag kept"
953 );710 );
954 }711 }
955 712
956-#[tokio::test]713+ // A published target move is refused on the page, and the typed values stay.
957-async fn a_published_target_move_is_refused_on_the_page_and_the_typed_values_stay() {714+ {
958- let fx = fixture(None).await;715+ git(&fx.bare, &["tag", "v5.0", "refs/heads/main"]);
959- git(&fx.bare, &["tag", "v2.0", "refs/heads/main"]);
960 second_commit(&fx);716 second_commit(&fx);
961- let published = fx.release("v2.0", false).await;717+ fx.release("v5.0", false).await;
718+ let published = fx
719+ .store
720+ .release_by_tag(&fx.repo.id, "v5.0")
721+ .await
722+ .expect("read")
723+ .expect("row");
962 let reply = send(724 let reply = send(
963 &fx.app,725 &fx.app,
964 "POST",726 "POST",
@@ -967,7 +729,7 @@ async fn a_published_target_move_is_refused_on_the_page_and_the_typed_values_sta
967 Some(FORM_TYPE),729 Some(FORM_TYPE),
968 form(&[730 form(&[
969 ("csrf", CSRF),731 ("csrf", CSRF),
970- ("tag", "v2.0"),732+ ("tag", "v5.0"),
971 ("target", "next"),733 ("target", "next"),
972 ("title", "Typed title"),734 ("title", "Typed title"),
973 ("body", "notes"),735 ("body", "notes"),
@@ -986,13 +748,134 @@ async fn a_published_target_move_is_refused_on_the_page_and_the_typed_values_sta
986 html.contains("Typed title"),748 html.contains("Typed title"),
987 "the typed title stays: {html}"749 "the typed title stays: {html}"
988 );750 );
989- assert_eq!(fx.tag_target("v2.0"), Some(fx.main_tip()));751+ assert_eq!(fx.tag_target("v5.0"), Some(fx.main_tip()));
752+ }
990 }753 }
991 754
992 #[tokio::test]755 #[tokio::test]
993-async fn replace_keeps_the_asset_name_whatever_the_new_file_is_called() {756+async fn asset_upload_replace_download_delete_and_csrf_rules() {
994 let fx = fixture(None).await;757 let fx = fixture(None).await;
758+
759+ // Upload then download round-trips the bytes and counts each download.
760+ {
995 let rel = fx.release("v1.0", false).await;761 let rel = fx.release("v1.0", false).await;
762+ let payload = b"<html>not rendered</html>";
763+ let reply = fx
764+ .upload(&rel.id, "app.bin", payload, &fx.tahinli_cookie)
765+ .await;
766+ assert_eq!(reply.status, 303, "body: {}", reply.text());
767+ assert!(
768+ reply
769+ .location
770+ .unwrap_or_default()
771+ .contains("notice=asset-uploaded")
772+ );
773+
774+ let row = fx
775+ .store
776+ .release_asset(&rel.id, "app.bin")
777+ .await
778+ .expect("read")
779+ .expect("asset row");
780+ assert_eq!(row.size, payload.len() as u64);
781+ let digest = {
782+ use sha2::{Digest, Sha256};
783+ hex::encode(Sha256::digest(payload))
784+ };
785+ assert_eq!(row.sha256, digest);
786+
787+ for expected in 1..=2u64 {
788+ let got = send(
789+ &fx.app,
790+ "GET",
791+ "/tahinli/proj/releases/download/v1.0/app.bin",
792+ None,
793+ None,
794+ Vec::new(),
795+ )
796+ .await;
797+ assert_eq!(got.status, 200);
798+ assert_eq!(got.body, payload);
799+ assert_eq!(
800+ got.headers
801+ .get("content-disposition")
802+ .and_then(|v| v.to_str().ok()),
803+ Some("attachment; filename=\"app.bin\"")
804+ );
805+ assert_eq!(
806+ got.headers
807+ .get("x-content-type-options")
808+ .and_then(|v| v.to_str().ok()),
809+ Some("nosniff")
810+ );
811+ let counted = fx
812+ .store
813+ .release_asset(&rel.id, "app.bin")
814+ .await
815+ .expect("read")
816+ .expect("row");
817+ assert_eq!(counted.download_count, expected, "download counter");
818+ }
819+ }
820+
821+ // A same-name upload replaces the file and keeps its download counter.
822+ {
823+ let rel = fx.release("v1.1", false).await;
824+ let first = fx
825+ .upload(&rel.id, "app.bin", b"first", &fx.tahinli_cookie)
826+ .await;
827+ assert_eq!(first.status, 303);
828+ let before = fx
829+ .store
830+ .release_asset(&rel.id, "app.bin")
831+ .await
832+ .expect("read")
833+ .expect("row");
834+ fx.store
835+ .count_asset_download(&before.id)
836+ .await
837+ .expect("count");
838+
839+ let second = fx
840+ .upload(&rel.id, "app.bin", b"second bytes", &fx.tahinli_cookie)
841+ .await;
842+ assert!(
843+ second
844+ .location
845+ .unwrap_or_default()
846+ .contains("notice=asset-replaced"),
847+ "a same-name upload replaces instead of refusing"
848+ );
849+ let assets = fx.store.list_release_assets(&rel.id).await.expect("assets");
850+ assert_eq!(assets.len(), 1, "still one asset of that name");
851+ let after = &assets[0];
852+ assert_ne!(after.id, before.id, "the new file has its own blob");
853+ assert_eq!(after.size, 12);
854+ assert_eq!(after.download_count, 1, "the download counter survives");
855+ assert!(
856+ fx.state
857+ .blobs
858+ .read(&asset_key(&before.id))
859+ .await
860+ .expect("read")
861+ .is_none(),
862+ "the replaced blob is deleted"
863+ );
864+ let got = send(
865+ &fx.app,
866+ "GET",
867+ "/tahinli/proj/releases/download/v1.1/app.bin",
868+ None,
869+ None,
870+ Vec::new(),
871+ )
872+ .await;
873+ assert_eq!(got.body, b"second bytes");
874+ }
875+
876+ // Replacing by asset name keeps the name, whatever the new file is called.
877+ {
878+ let rel = fx.release("v1.2", false).await;
996 let first = fx879 let first = fx
997 .upload(&rel.id, "app.bin", b"first", &fx.tahinli_cookie)880 .upload(&rel.id, "app.bin", b"first", &fx.tahinli_cookie)
998 .await;881 .await;
@@ -1044,7 +927,7 @@ async fn replace_keeps_the_asset_name_whatever_the_new_file_is_called() {
1044 let got = send(927 let got = send(
1045 &fx.app,928 &fx.app,
1046 "GET",929 "GET",
1047- "/tahinli/proj/releases/download/v1.0/app.bin",930+ "/tahinli/proj/releases/download/v1.2/app.bin",
1048 None,931 None,
1049 None,932 None,
1050 Vec::new(),933 Vec::new(),
@@ -1053,6 +936,146 @@ async fn replace_keeps_the_asset_name_whatever_the_new_file_is_called() {
1053 assert_eq!(got.body, b"second bytes");936 assert_eq!(got.body, b"second bytes");
1054 }937 }
1055 938
939+ // A wrong CSRF token on upload is refused and stores nothing.
940+ {
941+ let rel = fx.release("v1.3", false).await;
942+ let (content_type, body) = crate::pages::settings_profile::tests::multipart(&[
943+ ("csrf", None, b"wrong"),
944+ ("file", Some(("a.bin", "application/octet-stream")), b"data"),
945+ ]);
946+ let reply = send(
947+ &fx.app,
948+ "POST",
949+ &format!("/tahinli/proj/releases/{}/assets", rel.id),
950+ Some(&fx.tahinli_cookie),
951+ Some(&content_type),
952+ body,
953+ )
954+ .await;
955+ assert_ne!(reply.status, 303, "csrf mismatch");
956+ assert!(
957+ fx.store
958+ .list_release_assets(&rel.id)
959+ .await
960+ .expect("assets")
961+ .is_empty()
962+ );
963+ }
964+
965+ // Deleting a release keeps its git tag and removes its assets and blobs.
966+ {
967+ git(&fx.bare, &["tag", "v1.4", "refs/heads/main"]);
968+ let rel = fx.release("v1.4", false).await;
969+ let up = fx
970+ .upload(&rel.id, "gone.bin", b"bytes", &fx.tahinli_cookie)
971+ .await;
972+ assert_eq!(up.status, 303);
973+ let asset = fx
974+ .store
975+ .release_asset(&rel.id, "gone.bin")
976+ .await
977+ .expect("read")
978+ .expect("row");
979+ let blob = crate::blobs::asset_key(&asset.id);
980+ assert!(fx.state.blobs.read(&blob).await.expect("read").is_some());
981+
982+ let reply = send(
983+ &fx.app,
984+ "POST",
985+ &format!("/tahinli/proj/releases/{}/delete", rel.id),
986+ Some(&fx.tahinli_cookie),
987+ Some(FORM_TYPE),
988+ form(&[("csrf", CSRF), ("confirm", "on")]),
989+ )
990+ .await;
991+ assert_eq!(reply.status, 303);
992+ assert!(fx.store.release(&rel.id).await.expect("read").is_none());
993+ assert!(fx.tag_target("v1.4").is_some(), "the git tag survives");
994+ assert!(
995+ fx.state.blobs.read(&blob).await.expect("read").is_none(),
996+ "the blob is gone"
997+ );
998+ let download = send(
999+ &fx.app,
1000+ "GET",
1001+ "/tahinli/proj/releases/download/v1.4/gone.bin",
1002+ None,
1003+ None,
1004+ Vec::new(),
1005+ )
1006+ .await;
1007+ assert_eq!(download.status, 404, "a deleted asset does not download");
1008+ }
1009+}
1010+
1011+#[tokio::test]
1012+async fn the_size_cap_refuses_new_and_replacement_uploads() {
1013+ let fx = fixture(Some(1)).await;
1014+ let big = vec![7u8; 1024 * 1024 + 4096];
1015+
1016+ // Runs first: no blob may exist yet, so the blob directory must stay empty.
1017+ {
1018+ let rel = fx.release("v1.0", false).await;
1019+ let reply = fx
1020+ .upload(&rel.id, "big.bin", &big, &fx.tahinli_cookie)
1021+ .await;
1022+ assert_eq!(reply.status, 303);
1023+ assert!(
1024+ reply
1025+ .location
1026+ .unwrap_or_default()
1027+ .contains("notice=asset-too-large"),
1028+ "the cap refuses the file"
1029+ );
1030+ assert!(
1031+ fx.store
1032+ .list_release_assets(&rel.id)
1033+ .await
1034+ .expect("assets")
1035+ .is_empty()
1036+ );
1037+ let assets_dir = fx.state.config.data_dir.join("blobs").join("assets");
1038+ let leftovers = std::fs::read_dir(&assets_dir)
1039+ .map(|entries| entries.count())
1040+ .unwrap_or(0);
1041+ assert_eq!(leftovers, 0, "no partial blob is left behind");
1042+ }
1043+
1044+ // A refused replacement keeps the old file.
1045+ {
1046+ let rel = fx.release("v1.1", false).await;
1047+ fx.upload(&rel.id, "app.bin", b"keep me", &fx.tahinli_cookie)
1048+ .await;
1049+ let reply = fx
1050+ .upload(&rel.id, "app.bin", &big, &fx.tahinli_cookie)
1051+ .await;
1052+ assert!(
1053+ reply
1054+ .location
1055+ .unwrap_or_default()
1056+ .contains("notice=asset-too-large"),
1057+ "an oversized replacement is refused"
1058+ );
1059+ let row = fx
1060+ .store
1061+ .release_asset(&rel.id, "app.bin")
1062+ .await
1063+ .expect("read")
1064+ .expect("row");
1065+ assert_eq!(row.size, 7, "the old size stays");
1066+ let got = send(
1067+ &fx.app,
1068+ "GET",
1069+ "/tahinli/proj/releases/download/v1.1/app.bin",
1070+ None,
1071+ None,
1072+ Vec::new(),
1073+ )
1074+ .await;
1075+ assert_eq!(got.body, b"keep me", "the old bytes stay");
1076+ }
1077+}
1078+
1056 /// The live streams of the release list and a release page: a change from another session wakes1079 /// The live streams of the release list and a release page: a change from another session wakes
1057 /// them, and a reader without the access the page needs gets the page's 404.1080 /// them, and a reader without the access the page needs gets the page's 404.
1058 mod live_tests {1081 mod live_tests {
crates/forge-web/src/pages/repo.rsmodified+25 -46
@@ -635,10 +635,15 @@ mod tests {
635 (status, String::from_utf8_lossy(&bytes).into_owned())635 (status, String::from_utf8_lossy(&bytes).into_owned())
636 }636 }
637 637
638+ // The read-only tests below share one fixture: they only read the demo repo, so each scenario
639+ // sees the same pristine contents.
640+
638 #[tokio::test]641 #[tokio::test]
639- async fn home_renders_tree_clone_popover_and_readme() {642+ async fn demo_pages_render_from_the_repo_contents() {
640 let dir = tempfile::tempdir().unwrap();643 let dir = tempfile::tempdir().unwrap();
641 let (router, _) = fixture(dir.path()).await;644 let (router, _) = fixture(dir.path()).await;
645+
646+ // Home renders the README, the tree, the clone popover and the archive links.
642 let (status, body) = get(&router, "/tahinli/demo").await;647 let (status, body) = get(&router, "/tahinli/demo").await;
643 assert_eq!(status, 200);648 assert_eq!(status, 200);
644 assert!(body.contains("Hello from the README"), "README rendered");649 assert!(body.contains("Hello from the README"), "README rendered");
@@ -658,12 +663,8 @@ mod tests {
658 );663 );
659 assert!(body.contains("/tahinli/demo/archive/main.tar.gz"));664 assert!(body.contains("/tahinli/demo/archive/main.tar.gz"));
660 assert!(body.contains("/tahinli/demo/branches"));665 assert!(body.contains("/tahinli/demo/branches"));
661- }
662 666
663- #[tokio::test]667+ // Trees list their entries and link to subtrees and blobs.
664- async fn tree_lists_entries() {
665- let dir = tempfile::tempdir().unwrap();
666- let (router, _) = fixture(dir.path()).await;
667 let (status, body) = get(&router, "/tahinli/demo/tree/main/src").await;668 let (status, body) = get(&router, "/tahinli/demo/tree/main/src").await;
668 assert_eq!(status, 200);669 assert_eq!(status, 200);
669 assert!(body.contains("main.rs"));670 assert!(body.contains("main.rs"));
@@ -671,24 +672,16 @@ mod tests {
671 let (status, body) = get(&router, "/tahinli/demo/tree/main").await;672 let (status, body) = get(&router, "/tahinli/demo/tree/main").await;
672 assert_eq!(status, 200);673 assert_eq!(status, 200);
673 assert!(body.contains("/tahinli/demo/tree/main/docs"));674 assert!(body.contains("/tahinli/demo/tree/main/docs"));
674- }
675 675
676- #[tokio::test]676+ // Rust source is highlighted with line anchors.
677- async fn blob_highlights_rust_source() {
678- let dir = tempfile::tempdir().unwrap();
679- let (router, _) = fixture(dir.path()).await;
680 let (status, body) = get(&router, "/tahinli/demo/blob/main/src/main.rs").await;677 let (status, body) = get(&router, "/tahinli/demo/blob/main/src/main.rs").await;
681 assert_eq!(status, 200);678 assert_eq!(status, 200);
682 assert!(body.contains("id=\"L1\""));679 assert!(body.contains("id=\"L1\""));
683 assert!(body.contains("href=\"#L2\""));680 assert!(body.contains("href=\"#L2\""));
684 assert!(body.contains("<span class="), "syntax classes applied");681 assert!(body.contains("<span class="), "syntax classes applied");
685 assert!(body.contains("/assets/highlight.css?v="));682 assert!(body.contains("/assets/highlight.css?v="));
686- }
687 683
688- #[tokio::test]684+ // Markdown renders unless the viewer asks for the plain source.
689- async fn markdown_blob_renders_unless_plain() {
690- let dir = tempfile::tempdir().unwrap();
691- let (router, _) = fixture(dir.path()).await;
692 let (status, body) = get(&router, "/tahinli/demo/blob/main/docs/guide.md").await;685 let (status, body) = get(&router, "/tahinli/demo/blob/main/docs/guide.md").await;
693 assert_eq!(status, 200);686 assert_eq!(status, 200);
694 assert!(687 assert!(
@@ -699,19 +692,29 @@ mod tests {
699 assert_eq!(status, 200);692 assert_eq!(status, 200);
700 assert!(body.contains("file-table"), "source shown as lines");693 assert!(body.contains("file-table"), "source shown as lines");
701 assert!(!body.contains("markdown-body"), "not rendered");694 assert!(!body.contains("markdown-body"), "not rendered");
702- }
703 695
704- #[tokio::test]696+ // Binary blobs show their size instead of content.
705- async fn binary_blob_shows_size() {
706- let dir = tempfile::tempdir().unwrap();
707- let (router, _) = fixture(dir.path()).await;
708 let (status, body) = get(&router, "/tahinli/demo/blob/main/data.bin").await;697 let (status, body) = get(&router, "/tahinli/demo/blob/main/data.bin").await;
709 assert_eq!(status, 200);698 assert_eq!(status, 200);
710 assert!(body.contains("Binary file, 3 bytes"));699 assert!(body.contains("Binary file, 3 bytes"));
700+
701+ // Fixed segment routes win over the repo catch-all.
702+ let (status, body) = get(&router, "/tahinli/demo/branches").await;
703+ assert_eq!(status, 200);
704+ assert!(body.contains("default"), "default branch marked");
705+ let (status, body) = get(&router, "/tahinli/demo/tags").await;
706+ assert_eq!(status, 200);
707+ assert!(body.contains("Nothing here yet"));
708+ let (status, body) = get(&router, "/tahinli/demo/tree/main").await;
709+ assert_eq!(status, 200);
710+ assert!(body.contains("README.md"));
711+ let (status, body) = get(&router, "/tahinli/demo").await;
712+ assert_eq!(status, 200);
713+ assert!(body.contains("Hello from the README"));
711 }714 }
712 715
713 #[tokio::test]716 #[tokio::test]
714- async fn unknown_refs_and_paths_are_404() {717+ async fn missing_paths_and_private_repos_are_404_for_anonymous() {
715 let dir = tempfile::tempdir().unwrap();718 let dir = tempfile::tempdir().unwrap();
716 let (router, _) = fixture(dir.path()).await;719 let (router, _) = fixture(dir.path()).await;
717 for uri in [720 for uri in [
@@ -724,12 +727,6 @@ mod tests {
724 let (status, _) = get(&router, uri).await;727 let (status, _) = get(&router, uri).await;
725 assert_eq!(status, 404, "{uri}");728 assert_eq!(status, 404, "{uri}");
726 }729 }
727- }
728-
729- #[tokio::test]
730- async fn private_repo_is_404_for_anonymous() {
731- let dir = tempfile::tempdir().unwrap();
732- let (router, _) = fixture(dir.path()).await;
733 for uri in [730 for uri in [
734 "/tahinli/secret",731 "/tahinli/secret",
735 "/tahinli/secret/tree/main",732 "/tahinli/secret/tree/main",
@@ -742,24 +739,6 @@ mod tests {
742 }739 }
743 }740 }
744 741
745- #[tokio::test]
746- async fn fixed_segment_routes_win_over_the_repo_catch_all() {
747- let dir = tempfile::tempdir().unwrap();
748- let (router, _) = fixture(dir.path()).await;
749- let (status, body) = get(&router, "/tahinli/demo/branches").await;
750- assert_eq!(status, 200);
751- assert!(body.contains("default"), "default branch marked");
752- let (status, body) = get(&router, "/tahinli/demo/tags").await;
753- assert_eq!(status, 200);
754- assert!(body.contains("Nothing here yet"));
755- let (status, body) = get(&router, "/tahinli/demo/tree/main").await;
756- assert_eq!(status, 200);
757- assert!(body.contains("README.md"));
758- let (status, body) = get(&router, "/tahinli/demo").await;
759- assert_eq!(status, 200);
760- assert!(body.contains("Hello from the README"));
761- }
762-
763 const ZERO_OID: &str = "0000000000000000000000000000000000000000";742 const ZERO_OID: &str = "0000000000000000000000000000000000000000";
764 const OID: &str = "1111111111111111111111111111111111111111";743 const OID: &str = "1111111111111111111111111111111111111111";
765 const BANNER: &str = "had recent pushes";744 const BANNER: &str = "had recent pushes";
crates/forge-web/src/pages/repo_secrets.rsmodified+35 -33
@@ -493,10 +493,15 @@ mod tests {
493 }493 }
494 }494 }
495 495
496+ /// Refusals share one fixture and must leave the store empty: a write collaborator and an
497+ /// outsider get 404, anonymous users never see the page, and a POST without a valid CSRF
498+ /// token is forbidden.
496 #[tokio::test]499 #[tokio::test]
497- async fn non_admin_gets_404_and_anonymous_is_sent_to_login() {500+ async fn refusals_store_nothing_and_leave_the_page_alone() {
498 let dir = tempfile::tempdir().expect("tempdir");501 let dir = tempfile::tempdir().expect("tempdir");
499 let (store, app, repo) = fixture(dir.path()).await;502 let (store, app, repo) = fixture(dir.path()).await;
503+
504+ // A write collaborator is not an admin; an outsider gets 404 too.
500 let (status, _, _) = send(&app, "GET", PAGE, Some("bob-token"), &[], None).await;505 let (status, _, _) = send(&app, "GET", PAGE, Some("bob-token"), &[], None).await;
501 assert_eq!(status, 404, "a write collaborator is not an admin");506 assert_eq!(status, 404, "a write collaborator is not an admin");
502 let (status, _, _) = send(&app, "GET", PAGE, Some("carol-token"), &[], None).await;507 let (status, _, _) = send(&app, "GET", PAGE, Some("carol-token"), &[], None).await;
@@ -510,7 +515,7 @@ mod tests {
510 None,515 None,
511 )516 )
512 .await;517 .await;
513- assert_eq!(status, 404);518+ assert_eq!(status, 404, "a collaborator cannot set a secret");
514 let (status, _, _) = send(519 let (status, _, _) = send(
515 &app,520 &app,
516 "POST",521 "POST",
@@ -520,16 +525,12 @@ mod tests {
520 None,525 None,
521 )526 )
522 .await;527 .await;
523- assert_eq!(status, 404);528+ assert_eq!(status, 404, "an outsider cannot delete a secret");
524 assert!(names(&store, &repo).await.is_empty(), "nothing was stored");529 assert!(names(&store, &repo).await.is_empty(), "nothing was stored");
525 let (status, _, _) = send(&app, "GET", PAGE, None, &[], None).await;530 let (status, _, _) = send(&app, "GET", PAGE, None, &[], None).await;
526 assert_ne!(status, 200, "anonymous users do not see the page");531 assert_ne!(status, 200, "anonymous users do not see the page");
527- }
528 532
529- #[tokio::test]533+ // A POST without a valid CSRF token is forbidden and stores nothing.
530- async fn post_without_a_valid_csrf_token_is_forbidden() {
531- let dir = tempfile::tempdir().expect("tempdir");
532- let (store, app, repo) = fixture(dir.path()).await;
533 let (status, _, _) = send(534 let (status, _, _) = send(
534 &app,535 &app,
535 "POST",536 "POST",
@@ -539,7 +540,7 @@ mod tests {
539 Some("wrong-token"),540 Some("wrong-token"),
540 )541 )
541 .await;542 .await;
542- assert_eq!(status, 403);543+ assert_eq!(status, 403, "a wrong csrf token");
543 let (status, _, _) = send(544 let (status, _, _) = send(
544 &app,545 &app,
545 "POST",546 "POST",
@@ -549,12 +550,17 @@ mod tests {
549 Some(""),550 Some(""),
550 )551 )
551 .await;552 .await;
552- assert_eq!(status, 403);553+ assert_eq!(status, 403, "an empty csrf token on delete");
553- assert!(names(&store, &repo).await.is_empty());554+ assert!(
555+ names(&store, &repo).await.is_empty(),
556+ "csrf refusals store nothing"
557+ );
554 }558 }
555 559
560+ /// The value never comes back in any response, and the page follows the owner's language.
561+ /// Runs in one fixture: the English checks come before the language is switched.
556 #[tokio::test]562 #[tokio::test]
557- async fn value_never_appears_in_any_response() {563+ async fn values_never_leak_and_the_page_follows_the_language() {
558 let dir = tempfile::tempdir().expect("tempdir");564 let dir = tempfile::tempdir().expect("tempdir");
559 let (store, app, repo) = fixture(dir.path()).await;565 let (store, app, repo) = fixture(dir.path()).await;
560 let (status, location, body) = send(566 let (status, location, body) = send(
@@ -592,6 +598,23 @@ mod tests {
592 "no echo after a validation error"598 "no echo after a validation error"
593 );599 );
594 assert_eq!(names(&store, &repo).await.len(), 1);600 assert_eq!(names(&store, &repo).await.len(), 1);
601+
602+ // Turkish viewers see the Turkish heading.
603+ let tahinli = store
604+ .user_by_username("tahinli")
605+ .await
606+ .expect("lookup")
607+ .expect("tahinli");
608+ store
609+ .set_ui_prefs(&tahinli.id, "auto", "tr")
610+ .await
611+ .expect("set language");
612+ let (status, _, body) = send(&app, "GET", PAGE, Some("tahinli-token"), &[], None).await;
613+ assert_eq!(status, 200);
614+ assert!(
615+ body.contains("Gizli anahtar ekle veya güncelle"),
616+ "Turkish heading"
617+ );
595 }618 }
596 619
597 #[tokio::test]620 #[tokio::test]
@@ -692,25 +715,4 @@ mod tests {
692 .await;715 .await;
693 assert!(location.is_some_and(|l| l.contains("notice=missing")));716 assert!(location.is_some_and(|l| l.contains("notice=missing")));
694 }717 }
695-
696- #[tokio::test]
697- async fn turkish_viewer_sees_turkish_heading() {
698- let dir = tempfile::tempdir().expect("tempdir");
699- let (store, app, _repo) = fixture(dir.path()).await;
700- let tahinli = store
701- .user_by_username("tahinli")
702- .await
703- .expect("lookup")
704- .expect("tahinli");
705- store
706- .set_ui_prefs(&tahinli.id, "auto", "tr")
707- .await
708- .expect("set language");
709- let (status, _, body) = send(&app, "GET", PAGE, Some("tahinli-token"), &[], None).await;
710- assert_eq!(status, 200);
711- assert!(
712- body.contains("Gizli anahtar ekle veya güncelle"),
713- "Turkish heading"
714- );
715- }
716 }718 }