From 3b272d42d7c89e5ebdb69993a017ca5a6ef70a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 20 Oct 2026 13:28:45 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20suspended=20user's=20token?= =?UTF-8?q?=20is=20refused=20over=20HTTP=20git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-core/src/store/suspension.rs | 2 +- crates/forge-web/tests/git_e2e.rs | 91 +++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/crates/forge-core/src/store/suspension.rs b/crates/forge-core/src/store/suspension.rs index 7aa30cd..be91ec5 100644 --- a/crates/forge-core/src/store/suspension.rs +++ b/crates/forge-core/src/store/suspension.rs @@ -1,4 +1,4 @@ -//! Account suspension and the admin-only account facts (migration 0059). +//! Account suspension and the admin-only account facts (migration 0055). //! //! A suspended user keeps their data but cannot sign in. The session, token and SSH key lookups //! in `store/mod.rs` skip a suspended owner, so every transport stops at once. diff --git a/crates/forge-web/tests/git_e2e.rs b/crates/forge-web/tests/git_e2e.rs index de79e1e..00e5496 100644 --- a/crates/forge-web/tests/git_e2e.rs +++ b/crates/forge-web/tests/git_e2e.rs @@ -564,3 +564,94 @@ async fn git_end_to_end() { dumb.body ); } + +/// A suspended user's personal access token is refused over HTTP git: pushes and clones that +/// worked a moment earlier fail once an admin suspends the account. +#[tokio::test] +async fn suspended_user_token_is_refused_over_http_git() { + if !tool_on_path("git") { + eprintln!("SKIP git_e2e: `git` was not found on PATH"); + return; + } + let root = tempfile::Builder::new() + .prefix("fe2s") + .tempdir_in("/tmp") + .expect("temp dir"); + let dir = root.path().to_path_buf(); + let ports = pick_ports(); + let config = write_config(&dir, ports); + run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW); + run_admin(&config, "bob", &[], BOB_PW); + let (_server, ports) = launch(&dir, ports).await; + let http = Http::new(ports.http); + + // Bob makes a token and a public repo of his own, and can push to it. + let bob = login(&http, "bob", BOB_PW).await; + let bob_token = create_token(&http, &bob, "suspend-token").await; + let page = http.get_cookie("/new", &bob).await; + let csrf = input_value(&page.body, "csrf"); + let created = http + .post_form( + "/new", + &[ + ("csrf", &csrf), + ("name", "bobrepo"), + ("description", ""), + ("visibility", "public"), + ("default_branch", "main"), + ], + Some(&bob), + ) + .await; + assert_eq!(created.status, 303, "create repo: {}", created.body); + let url = format!( + "http://bob:{bob_token}@127.0.0.1:{}/bob/bobrepo.git", + ports.http + ); + let work = dir.join("work"); + ok( + &git(&dir, &["clone", &url, path_str(&work)], &[]), + "clone before suspension", + ); + commit_file(&work, "a.txt", "one\n", "first"); + ok( + &git(&work, &["push", "origin", "HEAD:main"], &[]), + "push before suspension", + ); + + // An admin suspends bob from his account page. + let tahinli = login(&http, "tahinli", TAHINLI_PW).await; + let list = http.get_cookie("/admin/users", &tahinli).await; + assert_eq!(list.status, 200, "GET /admin/users"); + let doc = scraper::Html::parse_document(&list.body); + let link = scraper::Selector::parse("a[href^=\"/admin/users/\"]").expect("selector"); + let bob_href = doc + .select(&link) + .find(|a| a.text().collect::().trim() == "bob") + .and_then(|a| a.value().attr("href")) + .expect("bob's admin link") + .to_owned(); + let detail = http.get_cookie(&bob_href, &tahinli).await; + assert_eq!(detail.status, 200, "GET {bob_href}"); + let csrf = input_value(&detail.body, "csrf"); + let res = http + .post_form( + &format!("{bob_href}/suspend"), + &[("csrf", &csrf), ("reason", "e2e")], + Some(&tahinli), + ) + .await; + assert_eq!(res.status, 303, "suspend bob: {}", res.body); + + // The same token no longer works for a push or a clone. + commit_file(&work, "b.txt", "two\n", "second"); + rejected( + &git(&work, &["push", "origin", "HEAD:main"], &[]), + "push with a suspended user's token", + ); + let again = dir.join("again"); + rejected( + &git(&dir, &["clone", &url, path_str(&again)], &[]), + "clone with a suspended user's token", + ); +}