From 05d479ce0a992195a7df28566773dec1785646de Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 3 Dec 2026 17:55:07 +1300 Subject: [PATCH] app/: a signed-in visit to the app's / stays in the app (sc-8900): route_by_host looks for the framework's own session cookie (laravel_session), not a separate SESSION_COOKIE default that never matched --- app/src/http/hosts.rs | 11 ++++------- app/tests/oauth.rs | 1 - app/tests/sign_in.rs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/app/src/http/hosts.rs b/app/src/http/hosts.rs index 66477b5b..2970b60c 100644 --- a/app/src/http/hosts.rs +++ b/app/src/http/hosts.rs @@ -28,9 +28,6 @@ pub struct HostUrls { pub api: Option, #[env("VISUALCI_MCP_URL")] pub mcp: Option, - /// The session cookie's name, to tell a signed-in visitor at the app's `/` from a new one - #[env("SESSION_COOKIE", default = "visualci_session")] - pub session_cookie: String, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -198,8 +195,9 @@ pub async fn route_by_host(hosts: Section, request: Request, next: Nex } return next.run(request).await; }; - // `/` on the app is the list of your organizations; without a session, the landing page - if here == Host::App && path == "/" && request.cookie(&hosts.session_cookie).is_none() { + // `/` on the app is the list of your organizations; without a session, the landing page. The session cookie is + // the framework's own (`SESSION_COOKIE`, else its default), so this can't drift from the cookie sign-in sets. + if here == Host::App && path == "/" && request.cookie(&laravel::config().session.cookie).is_none() { return Response::new(laravel::http::Redirect::to(format!("{}/", hosts.site())).status(307)) .with_header("cache-control", "no-store"); } @@ -263,11 +261,10 @@ mod tests { app: app.map(str::to_string), api: Some("https://api.visualci.com".into()), mcp: Some("https://mcp.visualci.com".into()), - session_cookie: "visualci_session".into(), }; assert!(check(&urls(None), true).is_err(), "only some of them"); assert!(check(&urls(None), false).is_ok(), "development serves every path"); - let none = HostUrls { site: None, app: None, api: None, mcp: None, session_cookie: "visualci_session".into() }; + let none = HostUrls { site: None, app: None, api: None, mcp: None }; assert!(check(&none, true).is_ok(), "one host serves everything"); assert!(check(&urls(Some("https://app.visualci.com")), true).is_ok()); // A bare host name, or the same host twice, would route nothing to it diff --git a/app/tests/oauth.rs b/app/tests/oauth.rs index c8bb5611..cfc46edb 100644 --- a/app/tests/oauth.rs +++ b/app/tests/oauth.rs @@ -172,7 +172,6 @@ fn production_stops_when_the_oauth_urls_miss_the_hosts() { app: Some("https://app.visualci.test".into()), api: Some("https://api.visualci.test".into()), mcp: Some("https://mcp.visualci.test".into()), - session_cookie: "visualci_session".into(), }; let right = config("https://mcp.visualci.test", "https://app.visualci.test/oauth/authorize"); assert!(check(&right, &hosts, true).is_ok()); diff --git a/app/tests/sign_in.rs b/app/tests/sign_in.rs index 27464ab2..d516b9c9 100644 --- a/app/tests/sign_in.rs +++ b/app/tests/sign_in.rs @@ -316,3 +316,37 @@ async fn the_development_sign_in_is_off_without_its_flag(app: Application) -> la assert_eq!(User::query().count().await?, 0); Ok(()) } + +fn four_hosts() -> Application { + app::testing::configure() + .with_envs([ + ("VISUALCI_SITE_URL", "https://visualci.test"), + ("VISUALCI_APP_URL", "https://app.visualci.test"), + ("VISUALCI_API_URL", "https://api.visualci.test"), + ("VISUALCI_MCP_URL", "https://mcp.visualci.test"), + ]) + .create() +} + +/// With the four hosts, as production runs: the site's "Sign in with GitHub" goes to the app's sign-in, and the +/// person lands on the app's `/` (their organizations), never back on the site (3 Dec 2026: the app's `/` looked for a +/// session cookie by a name the framework doesn't use, so every signed-in visit bounced to the landing page). +#[laravel::test(app = four_hosts)] +async fn signing_in_from_the_site_lands_in_the_app(app: Application) -> laravel::Result<()> { + let _github = github(); + let _social = social::fake().with(Provider::GITHUB, ada()); + let host = "app.visualci.test"; + + let start = app.get("/auth/github").header("host", host).await; + start.assert_redirect(); + let done = app.get("/auth/github/callback").header("host", host).with_cookies_from(&start).await; + done.assert_redirect_to("/"); + // The app's front page, signed in: the app itself, not the landing page + let front = app.get("/").header("host", host).with_cookies_from(&done).await; + front.assert_ok(); + assert!(front.headers().get("location").is_none(), "no redirect to the site"); + app.get("/auth/session").header("host", host).with_cookies_from(&done).await.assert_json_path("signed_in", true); + // Signed out, the app's front page is still the landing page + app.get("/").header("host", host).await.assert_redirect_to("https://visualci.test/"); + Ok(()) +}