forge
Explore
Log in

Don't you dare go Hollow

Suspended user's token is refused over HTTP git

Browse files at this commit

3b272d42d7c89e5ebdb69993a017ca5a6ef70a24Ahmet Kaan GümüşParent: 75640ff
  • test
    • suspended user's token is refused over HTTP git
Show full message
✅ test: suspended user's token is refused over HTTP git
crates/forge-core/src/store/suspension.rsmodified+1 -1
@@ -1,4 +1,4 @@
1-//! Account suspension and the admin-only account facts (migration 0059).1+//! Account suspension and the admin-only account facts (migration 0055).
2 //!2 //!
3 //! A suspended user keeps their data but cannot sign in. The session, token and SSH key lookups3 //! A suspended user keeps their data but cannot sign in. The session, token and SSH key lookups
4 //! in `store/mod.rs` skip a suspended owner, so every transport stops at once.4 //! in `store/mod.rs` skip a suspended owner, so every transport stops at once.
crates/forge-web/tests/git_e2e.rsmodified+91 -0
@@ -564,3 +564,94 @@ async fn git_end_to_end() {
564 dumb.body564 dumb.body
565 );565 );
566 }566 }
567+
568+/// A suspended user's personal access token is refused over HTTP git: pushes and clones that
569+/// worked a moment earlier fail once an admin suspends the account.
570+#[tokio::test]
571+async fn suspended_user_token_is_refused_over_http_git() {
572+ if !tool_on_path("git") {
573+ eprintln!("SKIP git_e2e: `git` was not found on PATH");
574+ return;
575+ }
576+ let root = tempfile::Builder::new()
577+ .prefix("fe2s")
578+ .tempdir_in("/tmp")
579+ .expect("temp dir");
580+ let dir = root.path().to_path_buf();
581+ let ports = pick_ports();
582+ let config = write_config(&dir, ports);
583+ run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW);
584+ run_admin(&config, "bob", &[], BOB_PW);
585+ let (_server, ports) = launch(&dir, ports).await;
586+ let http = Http::new(ports.http);
587+
588+ // Bob makes a token and a public repo of his own, and can push to it.
589+ let bob = login(&http, "bob", BOB_PW).await;
590+ let bob_token = create_token(&http, &bob, "suspend-token").await;
591+ let page = http.get_cookie("/new", &bob).await;
592+ let csrf = input_value(&page.body, "csrf");
593+ let created = http
594+ .post_form(
595+ "/new",
596+ &[
597+ ("csrf", &csrf),
598+ ("name", "bobrepo"),
599+ ("description", ""),
600+ ("visibility", "public"),
601+ ("default_branch", "main"),
602+ ],
603+ Some(&bob),
604+ )
605+ .await;
606+ assert_eq!(created.status, 303, "create repo: {}", created.body);
607+ let url = format!(
608+ "http://bob:{bob_token}@127.0.0.1:{}/bob/bobrepo.git",
609+ ports.http
610+ );
611+ let work = dir.join("work");
612+ ok(
613+ &git(&dir, &["clone", &url, path_str(&work)], &[]),
614+ "clone before suspension",
615+ );
616+ commit_file(&work, "a.txt", "one\n", "first");
617+ ok(
618+ &git(&work, &["push", "origin", "HEAD:main"], &[]),
619+ "push before suspension",
620+ );
621+
622+ // An admin suspends bob from his account page.
623+ let tahinli = login(&http, "tahinli", TAHINLI_PW).await;
624+ let list = http.get_cookie("/admin/users", &tahinli).await;
625+ assert_eq!(list.status, 200, "GET /admin/users");
626+ let doc = scraper::Html::parse_document(&list.body);
627+ let link = scraper::Selector::parse("a[href^=\"/admin/users/\"]").expect("selector");
628+ let bob_href = doc
629+ .select(&link)
630+ .find(|a| a.text().collect::<String>().trim() == "bob")
631+ .and_then(|a| a.value().attr("href"))
632+ .expect("bob's admin link")
633+ .to_owned();
634+ let detail = http.get_cookie(&bob_href, &tahinli).await;
635+ assert_eq!(detail.status, 200, "GET {bob_href}");
636+ let csrf = input_value(&detail.body, "csrf");
637+ let res = http
638+ .post_form(
639+ &format!("{bob_href}/suspend"),
640+ &[("csrf", &csrf), ("reason", "e2e")],
641+ Some(&tahinli),
642+ )
643+ .await;
644+ assert_eq!(res.status, 303, "suspend bob: {}", res.body);
645+
646+ // The same token no longer works for a push or a clone.
647+ commit_file(&work, "b.txt", "two\n", "second");
648+ rejected(
649+ &git(&work, &["push", "origin", "HEAD:main"], &[]),
650+ "push with a suspended user's token",
651+ );
652+ let again = dir.join("again");
653+ rejected(
654+ &git(&dir, &["clone", &url, path_str(&again)], &[]),
655+ "clone with a suspended user's token",
656+ );
657+}