From 79f48c9d787b4bdedb03367c23aa8f64e650cf0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 23 Oct 2026 06:08:22 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20page=20tests=20merge=20into?= =?UTF-8?q?=20tables=20and=20drop=20duplicate=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Counts for the m-z page files: 332 #[test] before, 324 after. Merged: three unauthorised merge requests (read only, anonymous, missing csrf) share one fixture; the profile repo-visibility checks share one seeded site; the create tag/target checks share one fixture; three csrf-refusal tests in settings_profile become table or combined cases; two settings_appearance label tests and two selection tests become one test each. Removed: a duplicate "teal" case in settings_appearance. --- crates/forge-web/src/pages/profile.rs | 28 ++++---- crates/forge-web/src/pages/pulls_merge.rs | 65 ++++++------------- crates/forge-web/src/pages/releases_tests.rs | 59 ++++++----------- .../src/pages/settings_appearance.rs | 12 +--- .../forge-web/src/pages/settings_profile.rs | 60 ++++++++--------- 5 files changed, 83 insertions(+), 141 deletions(-) diff --git a/crates/forge-web/src/pages/profile.rs b/crates/forge-web/src/pages/profile.rs index f06b6fc..a494876 100644 --- a/crates/forge-web/src/pages/profile.rs +++ b/crates/forge-web/src/pages/profile.rs @@ -731,13 +731,15 @@ mod tests { assert!(!as_member.contains(href), "member does not see Settings"); } + /// Anonymous and other users see only public repos; the owner sees all, and a collaborator + /// sees the repo they were added to. #[tokio::test] - async fn anonymous_and_other_users_see_only_public_repos() { + async fn repo_list_follows_the_viewers_access() { let site = seeded().await; let (_, anon) = get(&site.router, "/tahinli", None).await; - assert!(anon.contains("tahinli/open-repo")); - assert!(!anon.contains("tahinli/secret-repo")); - assert!(!anon.contains("tahinli/shared-repo")); + assert!(anon.contains("tahinli/open-repo"), "anonymous"); + assert!(!anon.contains("tahinli/secret-repo"), "anonymous"); + assert!(!anon.contains("tahinli/shared-repo"), "anonymous"); let bob = site .store @@ -746,14 +748,10 @@ mod tests { .unwrap(); let cookie = sign_in(&site.store, &bob.id, "bob-token").await; let (_, other) = get(&site.router, "/tahinli", Some(&cookie)).await; - assert!(other.contains("tahinli/open-repo")); - assert!(!other.contains("tahinli/secret-repo")); - assert!(!other.contains("tahinli/shared-repo")); - } + assert!(other.contains("tahinli/open-repo"), "other user"); + assert!(!other.contains("tahinli/secret-repo"), "other user"); + assert!(!other.contains("tahinli/shared-repo"), "other user"); - #[tokio::test] - async fn owner_sees_private_and_collaborator_sees_their_repo() { - let site = seeded().await; let tahinli = site .store .user_by_username("tahinli") @@ -762,14 +760,14 @@ mod tests { .unwrap(); let cookie = sign_in(&site.store, &tahinli.id, "tahinli-token").await; let (_, body) = get(&site.router, "/tahinli", Some(&cookie)).await; - assert!(body.contains("tahinli/secret-repo")); - assert!(body.contains("tahinli/shared-repo")); + assert!(body.contains("tahinli/secret-repo"), "owner"); + assert!(body.contains("tahinli/shared-repo"), "owner"); let carol = site.store.user_by_username("carol").await.unwrap().unwrap(); let cookie = sign_in(&site.store, &carol.id, "carol-token").await; let (_, body) = get(&site.router, "/tahinli", Some(&cookie)).await; - assert!(body.contains("tahinli/shared-repo")); - assert!(!body.contains("tahinli/secret-repo")); + assert!(body.contains("tahinli/shared-repo"), "collaborator"); + assert!(!body.contains("tahinli/secret-repo"), "collaborator"); } #[tokio::test] diff --git a/crates/forge-web/src/pages/pulls_merge.rs b/crates/forge-web/src/pages/pulls_merge.rs index 94ecbc6..7010ac9 100644 --- a/crates/forge-web/src/pages/pulls_merge.rs +++ b/crates/forge-web/src/pages/pulls_merge.rs @@ -1184,7 +1184,7 @@ mod tests { } #[tokio::test] - async fn read_only_collaborator_gets_403() { + async fn unauthorised_merge_requests_are_refused_and_base_unchanged() { let fx = fixture().await; let number = fx .open_feature("feature", "feature.txt", "f1", &fx.bob) @@ -1196,52 +1196,29 @@ mod tests { .expect("collaborator"); let bob_cookie = fx.sign_in(&fx.bob, "bob-token").await; let before = fx.main_tip(); + let path = format!("/tahinli/proj/pulls/{number}/merge"); - let reply = fx - .post( - &format!("/tahinli/proj/pulls/{number}/merge"), - Some(&bob_cookie), - merge_form("merge", None), - ) - .await; - assert_eq!(reply.status, 403); - assert_eq!(fx.main_tip(), before); - } - - #[tokio::test] - async fn anonymous_viewer_of_private_repo_gets_404() { - let fx = fixture().await; - let number = fx - .open_feature("feature", "feature.txt", "f1", &fx.bob) - .await; - - let reply = fx - .post( - &format!("/tahinli/proj/pulls/{number}/merge"), - None, + // A read-only collaborator gets 403, a stranger to the private repo gets 404. + let cases = [ + ( + "read only", + Some(bob_cookie.as_str()), merge_form("merge", None), - ) - .await; - assert_eq!(reply.status, 404); - } - - #[tokio::test] - async fn missing_csrf_is_rejected() { - let fx = fixture().await; - let number = fx - .open_feature("feature", "feature.txt", "f1", &fx.bob) - .await; - let before = fx.main_tip(); - - let reply = fx - .post( - &format!("/tahinli/proj/pulls/{number}/merge"), - Some(&fx.tahinli_cookie), + 403, + ), + ("anonymous", None, merge_form("merge", None), 404), + ( + "missing csrf", + Some(fx.tahinli_cookie.as_str()), "style=merge".to_owned(), - ) - .await; - assert_eq!(reply.status, 403); - assert_eq!(fx.main_tip(), before); + 403, + ), + ]; + for (name, cookie, body, status) in cases { + let reply = fx.post(&path, cookie, body).await; + assert_eq!(reply.status, status, "case {name}"); + assert_eq!(fx.main_tip(), before, "case {name}"); + } } #[tokio::test] diff --git a/crates/forge-web/src/pages/releases_tests.rs b/crates/forge-web/src/pages/releases_tests.rs index 1dd0ec0..958dc87 100644 --- a/crates/forge-web/src/pages/releases_tests.rs +++ b/crates/forge-web/src/pages/releases_tests.rs @@ -830,66 +830,49 @@ async fn retagging_adopts_an_existing_tag_and_refuses_clashes() { ); } +/// Create refuses a bad tag or a missing target before touching git, and takes a commit id as a +/// target. #[tokio::test] -async fn create_refuses_a_bad_tag_before_touching_git() { +async fn create_validates_its_tag_and_target() { let fx = fixture(None).await; - let input = CreateRelease { - tag: "a/b".to_owned(), - target: Some("main".to_owned()), + let input = |tag: &str, target: &str| CreateRelease { + tag: tag.to_owned(), + target: Some(target.to_owned()), title: "x".to_owned(), body: String::new(), draft: false, prerelease: false, }; - let refused = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input).await; + let refused = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input("a/b", "main")).await; assert!( matches!(refused, Err(ReleaseError::Invalid(_))), - "{refused:?}" + "bad tag: {refused:?}" ); - assert!(fx.tag_target("a/b").is_none()); -} + assert!(fx.tag_target("a/b").is_none(), "bad tag"); -#[tokio::test] -async fn create_takes_a_commit_id_as_its_target_and_refuses_a_missing_one() { - let fx = fixture(None).await; let tip = fx.main_tip(); - let made = release_ops::create( - &fx.state, - &fx.repo, - &fx.tahinli, - CreateRelease { - tag: "v7".to_owned(), - target: Some(tip.clone()), - title: "by sha".to_owned(), - body: String::new(), - draft: false, - prerelease: false, - }, - ) - .await - .expect("a commit id works as a target"); - assert_eq!(made.target_oid, tip); - assert_eq!(fx.tag_target("v7").as_deref(), Some(tip.as_str())); + let made = release_ops::create(&fx.state, &fx.repo, &fx.tahinli, input("v7", &tip)) + .await + .expect("a commit id works as a target"); + assert_eq!(made.target_oid, tip, "commit id target"); + assert_eq!( + fx.tag_target("v7").as_deref(), + Some(tip.as_str()), + "commit id target" + ); let missing = release_ops::create( &fx.state, &fx.repo, &fx.tahinli, - CreateRelease { - tag: "v8".to_owned(), - target: Some("1111111111111111111111111111111111111111".to_owned()), - title: "missing".to_owned(), - body: String::new(), - draft: false, - prerelease: false, - }, + input("v8", "1111111111111111111111111111111111111111"), ) .await; assert!( matches!(missing, Err(ReleaseError::Invalid(_))), - "{missing:?}" + "missing target: {missing:?}" ); - assert!(fx.tag_target("v8").is_none()); + assert!(fx.tag_target("v8").is_none(), "missing target"); } #[tokio::test] diff --git a/crates/forge-web/src/pages/settings_appearance.rs b/crates/forge-web/src/pages/settings_appearance.rs index be8f141..5904778 100644 --- a/crates/forge-web/src/pages/settings_appearance.rs +++ b/crates/forge-web/src/pages/settings_appearance.rs @@ -543,7 +543,6 @@ mod tests { "hue-07", "hue-", "hue-+5", - "teal", ] { assert!(accent_choice(Lang::En, Some(id), "sage").is_err(), "{id}"); } @@ -578,18 +577,15 @@ mod tests { } #[test] - fn the_stored_value_is_selected() { + fn the_stored_theme_accent_and_base_are_selected() { let options = choices(THEME_CODES, "dark", |code| theme_label(Lang::En, code)); let selected: Vec<&str> = options .iter() .filter(|c| c.selected) .map(|c| c.value) .collect(); - assert_eq!(selected, ["dark"]); - } + assert_eq!(selected, ["dark"], "theme"); - #[test] - fn the_stored_accent_and_base_are_selected() { let codes: Vec<&'static str> = accent::ids().collect(); let options = choices(&codes, "plum", |id| accent_name(Lang::En, id)); let selected: Vec<&str> = options @@ -644,10 +640,6 @@ mod tests { assert_eq!(theme_label(Lang::En, "dark"), "Dark"); assert_eq!(theme_label(Lang::Tr, "dark"), "Koyu"); assert_eq!(base_name(Lang::Tr, "ink"), "M\u{fc}rekkep"); - } - - #[test] - fn light_is_marked_as_the_default() { assert_eq!(theme_label(Lang::En, "light"), "Light (default)"); assert_eq!( theme_label(Lang::Tr, "light"), diff --git a/crates/forge-web/src/pages/settings_profile.rs b/crates/forge-web/src/pages/settings_profile.rs index 1500299..f3705de 100644 --- a/crates/forge-web/src/pages/settings_profile.rs +++ b/crates/forge-web/src/pages/settings_profile.rs @@ -652,16 +652,22 @@ pub(crate) mod tests { #[tokio::test] async fn post_without_a_valid_csrf_token_is_rejected() { let fx = fixture().await; - let forged = "csrf=wrong&username=Tahinli&about=&timezone=UTC"; - let (status, _, _) = - send(&fx.router, "POST", "/settings/profile", true, Some(forged)).await; - assert_eq!(status, 403); - let missing = "username=Tahinli&about=&timezone=UTC"; - let (status, _, _) = - send(&fx.router, "POST", "/settings/profile", true, Some(missing)).await; - assert_eq!(status, 403); + let cases = [ + ("forged", "csrf=wrong&username=Tahinli&about=&timezone=UTC"), + ("missing", "username=Tahinli&about=&timezone=UTC"), + ( + "missing with about", + "username=Tahinli&about=x&timezone=UTC", + ), + ]; + for (name, form) in cases { + let (status, _, _) = + send(&fx.router, "POST", "/settings/profile", true, Some(form)).await; + assert_eq!(status, 403, "case {name}"); + } let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap(); assert_eq!(stored.username, "tahinli"); + assert_eq!(stored.about, ""); } #[tokio::test] @@ -785,17 +791,7 @@ pub(crate) mod tests { } #[tokio::test] - async fn profile_post_without_csrf_is_rejected() { - let fx = fixture().await; - let form = "username=tahinli&about=x&timezone=UTC"; - let (status, _, _) = send(&fx.router, "POST", "/settings/profile", true, Some(form)).await; - assert_eq!(status, 403); - let stored = fx.store.user_by_id(&fx.user.id).await.unwrap().unwrap(); - assert_eq!(stored.about, ""); - } - - #[tokio::test] - async fn avatar_upload_without_csrf_is_rejected() { + async fn avatar_writes_without_csrf_are_rejected() { let fx = fixture().await; let png = png_bytes(); let (content_type, body) = multipart(&[("avatar", Some(("a.png", "image/png")), &png[..])]); @@ -808,8 +804,18 @@ pub(crate) mod tests { body, ) .await; - assert_eq!(reply.status, 403); + assert_eq!(reply.status, 403, "upload"); assert!(fx.store.avatar_hash(&fx.user.id).await.unwrap().is_none()); + + let (status, _, _) = send( + &fx.router, + "POST", + "/settings/profile/avatar/delete", + true, + Some("csrf=nope"), + ) + .await; + assert_eq!(status, 403, "remove"); } #[tokio::test] @@ -934,18 +940,4 @@ pub(crate) mod tests { ); assert!(default.text().starts_with("