Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions app/src/http/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ pub struct HostUrls {
pub api: Option<String>,
#[env("VISUALCI_MCP_URL")]
pub mcp: Option<String>,
/// 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)]
Expand Down Expand Up @@ -198,8 +195,9 @@ pub async fn route_by_host(hosts: Section<HostUrls>, 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");
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/tests/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
34 changes: 34 additions & 0 deletions app/tests/sign_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Loading