Merge pull request #1184 from warmbly/feat/gmail-signin-follows-backend

feat: show Google mailbox sign-in whenever the backend allows it and remove the dashboard flag
This commit is contained in:
Matthew Meszaros
2026-11-07 10:34:55 +00:00
committed by GitHub
26 changed files with 78 additions and 138 deletions
-2
View File
@@ -438,8 +438,6 @@ BILLING_PROVIDER=none
# BOX_GOOGLE_CLIENT_SECRET=
# Optional backend kill switch; unset enables connects when both keys are set.
# BOX_GOOGLE_OAUTH_CONNECT=false
# Dashboard visibility, independent of backend availability. Off by default.
WARMBLY_GMAIL_OAUTH_CONNECT=false
# Redirect URI: <API_PUBLIC_URL>/addresses/outlook/callback
# BOX_OUTLOOK_CLIENT_ID=
# BOX_OUTLOOK_CLIENT_SECRET=
@@ -107,7 +107,6 @@ test("renders the imported production settings with the real dashboard entrypoin
runInNewContext(readFileSync(output, "utf8"), { window });
assert.equal(window.__WARMBLY_ENV__.API_URL, "production-WARMBLY_API_URL");
assert.equal(window.__WARMBLY_ENV__.TURNSTILE_KEY, "production-WARMBLY_TURNSTILE_KEY");
assert.equal(window.__WARMBLY_ENV__.GMAIL_OAUTH_CONNECT, "production-WARMBLY_GMAIL_OAUTH_CONNECT");
assert.equal(window.__WARMBLY_ENV__.COMPANY_LOGOS, 'logos "quoted"\\path');
} finally {
rmSync(work, { recursive: true, force: true });
+1 -2
View File
@@ -117,7 +117,7 @@ services:
UPDATER_URL: none
BOX_GOOGLE_CLIENT_ID: ${BOX_GOOGLE_CLIENT_ID:-}
BOX_GOOGLE_CLIENT_SECRET: ${BOX_GOOGLE_CLIENT_SECRET:-}
BOX_GOOGLE_OAUTH_CONNECT: ${BOX_GOOGLE_OAUTH_CONNECT:-false}
BOX_GOOGLE_OAUTH_CONNECT: ${BOX_GOOGLE_OAUTH_CONNECT:-}
BOX_OUTLOOK_CLIENT_ID: ${BOX_OUTLOOK_CLIENT_ID:-}
BOX_OUTLOOK_CLIENT_SECRET: ${BOX_OUTLOOK_CLIENT_SECRET:-}
volumes:
@@ -228,7 +228,6 @@ services:
environment:
WARMBLY_API_URL: ${API_PUBLIC_URL:?}
WARMBLY_APP_URL: ${APP_URL:?}
WARMBLY_GMAIL_OAUTH_CONNECT: ${BOX_GOOGLE_OAUTH_CONNECT:-false}
WEBSOCKET_URL: wss://${REALTIME_HOST:?}/socket/websocket
depends_on:
backend: { condition: service_healthy }
-1
View File
@@ -685,7 +685,6 @@ services:
environment:
WARMBLY_API_URL: ${API_PUBLIC_URL:-http://${PUBLIC_HOST:-localhost}:8080}
WARMBLY_APP_URL: ${APP_URL:-http://${PUBLIC_HOST:-localhost}:5173}
WARMBLY_GMAIL_OAUTH_CONNECT: ${WARMBLY_GMAIL_OAUTH_CONNECT:-false}
# Cloudflare's always-pass test key keeps the widget satisfied while
# captcha is off server-side. Set WARMBLY_TURNSTILE_KEY to your site key
# when you set CAPTCHA_PROVIDER=turnstile.
+2 -2
View File
@@ -571,7 +571,7 @@ Folders (on campaigns), tags (on mailboxes) and labels (on contacts, inbox conve
These never accept an API key. They depend on a human-bound session: billing flows, governance, OAuth onboarding, websocket bootstrap, and operational destruction.
With [multiple dashboards sharing a backend](/development/configuration/#google-sign-in-per-dashboard-deployment), password-reset and invitation emails and billing returns use the initiating browser's exact configured dashboard origin. Without a trusted origin they use the primary dashboard. Mailbox, administrator-grant, integration and Slack identity OAuth callbacks recover their target from live server-side state, never from callback query parameters. Expired or consumed routing state is not forwarded to another dashboard.
With [multiple dashboards sharing a backend](/development/configuration/#multiple-dashboards-on-one-backend), password-reset and invitation emails and billing returns use the initiating browser's exact configured dashboard origin. Without a trusted origin they use the primary dashboard. Mailbox, administrator-grant, integration and Slack identity OAuth callbacks recover their target from live server-side state, never from callback query parameters. Expired or consumed routing state is not forwarded to another dashboard.
- `POST /auth/login`, `/auth/login/confirm`, `/auth/register`, `/auth/register/confirm`, `/auth/refresh`, `/auth/reset-password`, `/auth/reset-password/session`, `/auth/reset-password/confirm`
- `POST /auth/2fa/verify` (exchange a pending login challenge and a single-use authenticator or recovery code for a session; an authenticator step at or before the last accepted step answers `two_fa_code_used`, while unavailable verification answers a server error)
@@ -644,7 +644,7 @@ A completed sign-in counts as a confirmation for the first five minutes of the s
Alongside them, `api_url` is this API's own public base (for a copyable example that names the right server), and `brand` is who the deployment says it is: `name`, and `website_url`, `website_label`, `terms_url`, `privacy_url` and `support_email`, each omitted when unset. On a self-hosted instance that configured no `EMAIL_BRAND_*` only `name` is present, and a client should render no link at all rather than substituting one of its own. See [configuration](/development/configuration/).
`GET /auth/config` also carries `gmail_oauth_connect` (boolean): whether a new Gmail mailbox may be connected with Google sign-in. Both `BOX_GOOGLE_CLIENT_ID` and `BOX_GOOGLE_CLIENT_SECRET` are required. With them set, the capability defaults to `true`; explicit `BOX_GOOGLE_OAUTH_CONNECT=false` or an invalid value disables it. When `false`, offer the app-password route (`POST /emails/onboarding/smtp-imap` against Gmail's servers) rather than start an OAuth round trip that returns `mailbox_gmail_oauth_disabled`. The dashboard additionally requires its deployment-local [frontend opt-in](/development/configuration/#google-sign-in-per-dashboard-deployment) to show Google sign-in. Existing Google sign-in mailboxes are unaffected either way.
`GET /auth/config` also carries `gmail_oauth_connect` (boolean): whether a new Gmail mailbox may be connected with Google sign-in. Both `BOX_GOOGLE_CLIENT_ID` and `BOX_GOOGLE_CLIENT_SECRET` are required. With them set, the capability defaults to `true`; explicit `BOX_GOOGLE_OAUTH_CONNECT=false` or an invalid value disables it. When `false`, offer the app-password route (`POST /emails/onboarding/smtp-imap` against Gmail's servers) rather than start an OAuth round trip that returns `mailbox_gmail_oauth_disabled`. The dashboard offers Google sign-in when this is `true`, and also on an instance linked to Warmbly Cloud, where the consent runs on Warmbly Cloud's client instead of a local one. Existing Google sign-in mailboxes are unaffected either way.
`GET /auth/config` also carries `app_attest` (boolean): whether this server accepts an [App Attest proof](/api/reference/account-org/#app-attest-native-apps) from the native app in place of a Turnstile token on `POST /auth/login`, `/auth/register`, `/auth/reset-password` and `/auth/reset-password/confirm`. Read it with `captcha`: no captcha means nothing to send, a captcha with `app_attest` means the app sends a proof, and a captcha without it means email and password sign-in is unavailable in the app.
+2 -2
View File
@@ -638,7 +638,7 @@ A `400` with `code: "google_personal_app_password"` comes from `POST /emails/onb
#### `mailbox_oauth_return_origin`
A `400` with `code: "mailbox_oauth_return_origin"` means a Google or Microsoft mailbox connect or reauthorization came from a dashboard origin the backend does not allow. Add its exact HTTP(S) origin to `CORS_ALLOW_ORIGINS`, as in [shared-backend dashboard configuration](/development/configuration/#google-sign-in-per-dashboard-deployment). A wildcard is not an OAuth return allowlist.
A `400` with `code: "mailbox_oauth_return_origin"` means a Google or Microsoft mailbox connect or reauthorization came from a dashboard origin the backend does not allow. Add its exact HTTP(S) origin to `CORS_ALLOW_ORIGINS`, as in [shared-backend dashboard configuration](/development/configuration/#multiple-dashboards-on-one-backend). A wildcard is not an OAuth return allowlist.
### 401 Unauthorized
@@ -745,7 +745,7 @@ A `403` whose `code` is `mailbox_gmail_oauth_disabled` comes from `POST /emails/
**How to fix:**
- Connect the mailbox through `POST /emails/onboarding/smtp-imap` with `smtp.gmail.com:465` and `imap.gmail.com:993`, both TLS, and a Google app password. See [Gmail and Google Workspace](/guides/mailboxes/#gmail-and-google-workspace)
- An instance with its own Google app must set both `BOX_GOOGLE_CLIENT_ID` and `BOX_GOOGLE_CLIENT_SECRET`. Leave `BOX_GOOGLE_OAUTH_CONNECT` unset or set it to `true`, then enable the [dashboard visibility flag](/development/configuration/#google-sign-in-per-dashboard-deployment) on the deployments that should offer Google sign-in
- An instance with its own Google app must set both `BOX_GOOGLE_CLIENT_ID` and `BOX_GOOGLE_CLIENT_SECRET`. Leave `BOX_GOOGLE_OAUTH_CONNECT` unset or set it to `true`; the dashboard then offers Google sign-in
#### `google_delegation_retired`
@@ -613,31 +613,14 @@ Needed on the backend **and** every worker: the backend starts the OAuth flow, a
|---|---|---|
| `BOX_GOOGLE_CLIENT_ID`, `BOX_GOOGLE_CLIENT_SECRET` | The Google app used by Gmail mailboxes connected with per-mailbox Google sign-in. Both are required to enable new connects. Keep them set while any mailbox uses Google sign-in. Also carries a Workspace administrator's domain proof when `GOOGLE_CLIENT_ID` is not set. Redirect URI is your API base plus `/addresses/google/callback`. Until Google verifies the client it is limited to 100 new users, except on Workspace domains whose administrator marks it Trusted under Manage Third-Party App Access, and an **Internal** client in your own organization; members see the client ID in the connect dialog and as `google_mailbox_client_id` on `GET /emails/grants/config`. The consent screen needs `https://mail.google.com/` and `gmail.settings.basic` ([setup](/development/deployment-guide/#gmail-and-google-workspace)) | unset |
| `BOX_GOOGLE_APP_NAME` | The app name on the consent screen of the `BOX_GOOGLE_*` client. An inbox vendor that signs in to Google mailboxes for Warmbly checks it against the client ID (Zapmail refuses a mismatch), so set it to the name your Google Cloud project shows | `Warmbly` |
| `BOX_GOOGLE_OAUTH_CONNECT` | Optional backend kill switch for new Gmail OAuth connects. Unset enables the capability when both Google mailbox credentials are present; explicit `false` or an invalid value disables it. Existing Google sign-in mailboxes keep working and can re-authorize either way. Announced as `gmail_oauth_connect` on `GET /v1/auth/config` | enabled when configured |
| `BOX_GOOGLE_OAUTH_CONNECT` | Optional backend kill switch for new Gmail OAuth connects. Unset enables the capability when both Google mailbox credentials are present; explicit `false` or an invalid value disables it. Existing Google sign-in mailboxes keep working and can re-authorize either way. Announced as `gmail_oauth_connect` on `GET /v1/auth/config`, which is what the dashboard reads to offer Google sign-in | enabled when configured |
| `BOX_OUTLOOK_CLIENT_ID`, `BOX_OUTLOOK_CLIENT_SECRET` | Connect Outlook and Microsoft 365 mailboxes. Redirect URI is your API base plus `/addresses/outlook/callback` | unset |
Plain SMTP and IMAP mailboxes need none of this. If a worker is missing these values, the mailbox connects fine and then silently stops about an hour later, when its first access token expires.
### Google sign-in per dashboard deployment
### Multiple dashboards on one backend
The dashboard has a separate visibility flag. It affects only **per-mailbox Google sign-in** in the connect dialog and mailbox import, not Microsoft sign-in, Google dashboard login or Workspace whole-domain grants.
| Variable | Where to set it | Default |
|---|---|---|
| `WARMBLY_GMAIL_OAUTH_CONNECT` | Dashboard container environment or Cloudflare Pages environment. Set to `true` to offer Google mailbox sign-in when the backend supports it | `false` |
| `VITE_GMAIL_OAUTH_CONNECT` | `web/.env` for local Vite or a direct Vite build. Runtime configuration takes precedence | `false` |
Two dashboard deployments can share one backend and set this flag differently. For example:
```dotenv
# Public dashboard environment
WARMBLY_GMAIL_OAUTH_CONNECT=false
# Assessment dashboard environment (a separate deployment)
WARMBLY_GMAIL_OAUTH_CONNECT=true
```
Both dashboards point `WARMBLY_API_URL` at the same API and set `WARMBLY_APP_URL` to their own dashboard URL. Containers generate `/config.js` at startup, so no second image is needed. Cloudflare Pages renders it during `build:pages`; set the variable on the intended Pages project and redeploy.
Several dashboard deployments can share one backend. Each points `WARMBLY_API_URL` at the same API and sets `WARMBLY_APP_URL` to its own dashboard URL. Containers generate `/config.js` at startup, so no second image is needed. Cloudflare Pages renders it during `build:pages`; set the variables on the intended Pages project and redeploy.
The customer dashboard also generates a Content Security Policy from the same deployment settings. Static bootstrap scripts and styles use build-generated hashes; scripts and styles injected as markup are not generally allowed. API, Sentry and PostHog origins are derived from their configured URLs. Before nginx starts, the dashboard reads the public `/v1/auth/config` endpoint at its configured API URL and allows only the exact `websocket_url` origin. Existing backend `WEBSOCKET_URL` configuration therefore needs no duplicate CSP setting. If `WEBSOCKET_URL` is also passed into the web container, it supplies the origin directly without an HTTP request.
@@ -653,30 +636,13 @@ On the shared backend, keep `APP_URL` as the primary dashboard and add both exac
Email/password login, OTP/2FA, signup, logout and ordinary dashboard navigation use local routes. Password-reset and invitation emails initiated from an allowlisted dashboard link back to that dashboard. Stripe checkout, credit top-ups, billing portal and warmup-plan returns use the initiating dashboard and retain safe same-origin paths. Requests without a trusted browser origin use the primary dashboard.
For Warmbly's hosted assessment dashboard, the shared backend needs both of these origins:
Each additional dashboard also needs:
```dotenv
APP_URL=https://app.warmbly.com
CORS_ALLOW_ORIGINS=https://app.warmbly.com,https://tac-security-assessment.warmbly.com
```
- its hostname allowed on the Cloudflare Turnstile widget. A widget restricted to one hostname does not cover a sibling. Keep CAPTCHA enabled.
- its origin appended to the realtime service's `CHECK_ORIGIN_HOSTS`, preserving the existing origins. The API origin allowlist does not configure websocket origin checks.
- the existing `WEBAUTHN_RP_ID`, unchanged. Changing it invalidates every registered passkey. If it is the primary dashboard's hostname, use email/password on a sibling hostname; if it is a shared parent domain and both origins are allowed for WebAuthn, existing passkeys work on both dashboards.
This is an environment example, not a built-in allowlist. Preserve any other existing origins, such as the admin dashboard: append `https://tac-security-assessment.warmbly.com` to the current `CORS_ALLOW_ORIGINS` value rather than replacing the list. On Railway, update the backend service's variable and redeploy it; changing the frontend variable or merging code does not update the live backend environment. Keep `APP_URL` and `APP_ORIGIN` pointing at the primary dashboard, not the assessment dashboard. The assessment frontend sets `WARMBLY_APP_URL=https://tac-security-assessment.warmbly.com` and `WARMBLY_GMAIL_OAUTH_CONNECT=true`.
Before giving assessors access:
- Set the assessment frontend's `WARMBLY_API_URL` to the shared API, and use an exact `WARMBLY_APP_URL` origin without a trailing slash.
- Allow the assessment hostname on the existing Cloudflare Turnstile widget. A widget restricted to `app.warmbly.com` does not cover its sibling assessment hostname. Keep CAPTCHA enabled.
- Append the assessment origin to the realtime service's `CHECK_ORIGIN_HOSTS`, preserving its existing origins. The API origin allowlist does not configure websocket origin checks.
- For password-only assessor accounts, use **Admin > Testers**, or turn on **Skip emailed sign-in code** on an existing account's page under **Users**. These accounts are exempt from the emailed login-code step, but still use CAPTCHA and existing permission checks. Accounts with 2FA enabled still need their second factor.
- Keep the existing `WEBAUTHN_RP_ID` unchanged. An `app.warmbly.com` passkey RP ID cannot serve a sibling assessment hostname, and changing it invalidates existing credentials. Reviewers can use email/password; passkey support across both hosts needs a separate migration decision.
This is not a global rewrite of every primary-dashboard link. Dashboard Google/Apple/OIDC login remains primary-dashboard routed; assessment reviewers should use email/password. Server-generated notifications, Slack-launched links, CLI/bootstrap links and self-hosted Cloud broker returns retain their canonical instance routing. Cloud broker return origins remain bound to the registered instance, not the hosted assessment dashboard.
Existing Google OAuth mailboxes can still re-authorize with the frontend flag off. App-password and SMTP/IMAP options stay available. When linked to Warmbly Cloud, Google consent is brokered by Cloud rather than the local backend, but the frontend opt-in is still required.
<Callout type="warn" title="Visibility is not authorization">
Hiding the button does not prevent an authenticated client from calling the API. Use `BOX_GOOGLE_OAUTH_CONNECT=false` to disable new Google OAuth connects on the backend. A frontend flag does not change Google's restricted-scope verification or security assessment requirements, and a second dashboard on the same backend shares its data. Agree the assessment scope and reviewer account with your assessor before scanning.
</Callout>
This is not a global rewrite of every primary-dashboard link. Dashboard Google/Apple/OIDC login remains primary-dashboard routed. Server-generated notifications, Slack-launched links, CLI/bootstrap links and self-hosted Cloud broker returns retain their canonical instance routing. Cloud broker return origins remain bound to the registered instance.
### Optional hosted static edge
+1 -1
View File
@@ -142,7 +142,7 @@ Confirm `https://api.example.com/health` responds successfully, the dashboard op
SMTP/IMAP mailbox connections require no Google or Microsoft app registration. Their TLS certificates are verified by this stack. Do not disable verification to work around provider settings.
For OAuth mailbox connections, the file also passes `BOX_GOOGLE_CLIENT_ID`, `BOX_GOOGLE_CLIENT_SECRET`, `BOX_GOOGLE_OAUTH_CONNECT`, `BOX_OUTLOOK_CLIENT_ID`, and `BOX_OUTLOOK_CLIENT_SECRET` to the appropriate services. Gmail's UI switch follows `BOX_GOOGLE_OAUTH_CONNECT`. Set up your own provider application and the callback URLs documented under [configuration](/development/configuration/), then redeploy. These are mailbox-connection clients, not sign-in-with-Google credentials.
For OAuth mailbox connections, the file also passes `BOX_GOOGLE_CLIENT_ID`, `BOX_GOOGLE_CLIENT_SECRET`, `BOX_GOOGLE_OAUTH_CONNECT`, `BOX_OUTLOOK_CLIENT_ID`, and `BOX_OUTLOOK_CLIENT_SECRET` to the appropriate services. With the Google client set, the dashboard offers Google mailbox sign-in unless `BOX_GOOGLE_OAUTH_CONNECT=false`. Set up your own provider application and the callback URLs documented under [configuration](/development/configuration/), then redeploy. These are mailbox-connection clients, not sign-in-with-Google credentials.
## Updates, backups, and existing data
@@ -465,7 +465,7 @@ Nothing to configure. Add the mailbox in the dashboard with its host, port, user
### Gmail and Google Workspace
Nothing to configure by default: the connect dialog walks users through a Google app password over `smtp.gmail.com` and `imap.gmail.com`, which is how personal Gmail always connects; see [the mailbox guide](/guides/mailboxes/#personal-gmail). For Google Workspace, set up the Google OAuth client below: each domain's administrator marks it Trusted, then each mailbox signs in with Google, see [Google Workspace with Google sign-in](/guides/mailboxes/#google-workspace-with-google-sign-in). Domain-wide delegation through a service account is legacy and serves only grants already made, so an instance that configured only the service account can no longer set up a new domain. The client also serves the mailboxes already connected with Google sign-in, both refreshing their tokens and re-authorizing them when Google invalidates a grant. Offering it to new mailboxes also needs the [dashboard flag](/development/configuration/#google-sign-in-per-dashboard-deployment).
Nothing to configure by default: the connect dialog walks users through a Google app password over `smtp.gmail.com` and `imap.gmail.com`, which is how personal Gmail always connects; see [the mailbox guide](/guides/mailboxes/#personal-gmail). For Google Workspace, set up the Google OAuth client below: each domain's administrator marks it Trusted, then each mailbox signs in with Google, see [Google Workspace with Google sign-in](/guides/mailboxes/#google-workspace-with-google-sign-in). Domain-wide delegation through a service account is legacy and serves only grants already made, so an instance that configured only the service account can no longer set up a new domain. The client also serves the mailboxes already connected with Google sign-in, both refreshing their tokens and re-authorizing them when Google invalidates a grant.
<Steps>
+1 -1
View File
@@ -157,7 +157,7 @@ Each mailbox is labelled with where it is hosted and how it signs in. The [API](
A Google row whose password is not a 16-letter app password is flagged in the preview before anything is tried: Google refuses the account password over IMAP and SMTP. On an instance that connects new Gmail mailboxes with Google sign-in (`gmail_oauth_connect` in `GET /auth/config`), such a row waits for sign-in instead, like a Microsoft row.
Google rows waiting for Google sign-in offer a **Sign in** action only on deployments where [Google mailbox OAuth is enabled](/development/configuration/#google-sign-in-per-dashboard-deployment), and never for a personal Gmail address, which connects with an app password. Otherwise use **Fix** on the row to give it a 16-letter app password, which connects it over IMAP and SMTP with Google's servers, or use an admin grant the workspace already holds for the domain. Microsoft sign-in is unaffected by that flag.
Google rows waiting for Google sign-in offer a **Sign in** action on instances that connect new Gmail mailboxes with Google sign-in or are linked to Warmbly Cloud (which runs the consent on its own app), and never for a personal Gmail address, which connects with an app password. Otherwise use **Fix** on the row to give it a 16-letter app password, which connects it over IMAP and SMTP with Google's servers, or use an admin grant the workspace already holds for the domain.
### Microsoft
+1 -1
View File
@@ -190,7 +190,7 @@ The administrator does this in the Google Admin console:
Then connect each mailbox: choose **Add account > Google > Sign in with Google**, enter the mailbox's address, choose **Continue with Google** and approve the consent screen. When the Google window closes without connecting, the dialog shows the client ID again with what to ask the administrator. The same client ID is reported as `google_mailbox_client_id` by `GET /emails/grants/config`. On a self-hosted instance linked to Warmbly Cloud, the consent runs on Warmbly Cloud's own app, so the dialog shows no client ID.
This option is deployment-dependent; an administrator can enable it with the [dashboard configuration flag](/development/configuration/#google-sign-in-per-dashboard-deployment). If it is hidden, use an app password instead. Existing Google sign-in mailboxes keep working and can re-authorize even when new Google sign-in connects are disabled.
This option appears when the instance has a Google mailbox client configured and `BOX_GOOGLE_OAUTH_CONNECT` is unset or true; an explicit `false` or an invalid value turns new connects off (see [configuration](/development/configuration/)). An instance linked to Warmbly Cloud offers it either way, through Warmbly Cloud's app. If it is hidden, use an app password instead. Existing Google sign-in mailboxes keep working and can re-authorize even when new Google sign-in connects are disabled.
#### Whole Workspace domain with delegation
+1 -1
View File
@@ -63,7 +63,7 @@ In the **Invite teammates** box, paste or type addresses into **Emails**, separa
Warmbly sends one invitation per address and reports results as "Invited 2 · 1 failed". Invalid addresses are skipped and called out. The chips clear when the batch finishes.
When several trusted dashboards share one backend, invitation emails link back to the dashboard that sent the invitation. Copying an invitation link also keeps that dashboard's hostname. See [multi-dashboard configuration](/development/configuration/#google-sign-in-per-dashboard-deployment).
When several trusted dashboards share one backend, invitation emails link back to the dashboard that sent the invitation. Copying an invitation link also keeps that dashboard's hostname. See [multi-dashboard configuration](/development/configuration/#multiple-dashboards-on-one-backend).
An invitation works for 48 hours. A self-hosted instance can shorten that, but not lengthen it.
+11 -11
View File
@@ -10,16 +10,16 @@ import (
func TestBillingReturnURLUsesInitiatingDashboard(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
const assessment = "https://tac-security-assessment.warmbly.com"
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
const second = "https://second.example.com"
const fallback = "/app/settings/billing"
for _, tt := range []struct{ origin, raw, want string }{
{assessment, assessment + "/app/settings/billing/ai-credits?topup=success", assessment + "/app/settings/billing/ai-credits?topup=success"},
{assessment, "/app/settings/billing?checkout=done", assessment + "/app/settings/billing?checkout=done"},
{assessment, "", assessment + fallback},
{assessment, "https://app.warmbly.com" + fallback, assessment + fallback},
{second, second + "/app/settings/billing/ai-credits?topup=success", second + "/app/settings/billing/ai-credits?topup=success"},
{second, "/app/settings/billing?checkout=done", second + "/app/settings/billing?checkout=done"},
{second, "", second + fallback},
{second, "https://app.warmbly.com" + fallback, second + fallback},
{"", "https://app.warmbly.com" + fallback, "https://app.warmbly.com" + fallback},
{"", assessment + fallback, "https://app.warmbly.com" + fallback},
{"", second + fallback, "https://app.warmbly.com" + fallback},
{"https://evil.example.com", "/app/settings/billing", "https://app.warmbly.com" + fallback},
} {
ctx := config.WithDashboardOrigin(context.Background(), tt.origin)
@@ -27,12 +27,12 @@ func TestBillingReturnURLUsesInitiatingDashboard(t *testing.T) {
t.Errorf("origin %q URL %q = %q, want %q", tt.origin, tt.raw, got, tt.want)
}
}
ctx := config.WithDashboardOrigin(context.Background(), assessment)
ctx := config.WithDashboardOrigin(context.Background(), second)
for _, raw := range []string{
"https://evil.example.com/", "//evil.example.com", "/\\evil.example.com", "https://tac-security-assessment.warmbly.com.evil.example.com/",
"https://evil@tac-security-assessment.warmbly.com/", "http://tac-security-assessment.warmbly.com/", "https://tac-security-assessment.warmbly.com:444/", "javascript:alert(1)", "/path\nother", "/%zz",
"https://evil.example.com/", "//evil.example.com", "/\\evil.example.com", "https://second.example.com.evil.example.com/",
"https://evil@second.example.com/", "http://second.example.com/", "https://second.example.com:444/", "javascript:alert(1)", "/path\nother", "/%zz",
} {
if got := billingReturnURL(ctx, raw, fallback); got != assessment+fallback {
if got := billingReturnURL(ctx, raw, fallback); got != second+fallback {
t.Errorf("unsafe URL %q returned %q", raw, got)
}
}
@@ -27,9 +27,9 @@ func (s *returnOriginService) OAuthReturnOrigin(_ context.Context, state string)
func TestMailboxCallbacksUseStateBoundDashboard(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.warmbly.com,https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.warmbly.com,https://second.example.com")
for _, tt := range []struct{ name, origin, want string }{
{"assessment", "https://tac-security-assessment.warmbly.com", "https://tac-security-assessment.warmbly.com"},
{"second dashboard", "https://second.example.com", "https://second.example.com"},
{"primary dashboard", "https://app.warmbly.com", "https://app.warmbly.com"},
{"missing or expired state", "", ""},
{"untrusted origin", "https://evil.example.com", ""},
@@ -116,8 +116,8 @@ func (s *integrationReturnOriginService) OAuthReturnOrigin(_ context.Context, _
func TestIntegrationCallbackUsesStateBoundDashboard(t *testing.T) {
t.Setenv("APP_ORIGIN", "")
t.Setenv("APP_URL", "https://app.acme.io")
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
for _, origin := range []string{"https://app.acme.io", "https://tac-security-assessment.warmbly.com", "https://evil.example.com", ""} {
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
for _, origin := range []string{"https://app.acme.io", "https://second.example.com", "https://evil.example.com", ""} {
h := &Handler{IntegrationService: &integrationReturnOriginService{origin: origin}}
w := serve(t, h.IntegrationOAuthCallback, "/cb?state=s&code=c")
want := origin
@@ -12,12 +12,12 @@ import (
func TestDashboardOriginMiddleware(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
r := gin.New()
r.Use(DashboardOriginMiddleware())
r.GET("/", func(c *gin.Context) { c.String(http.StatusOK, config.DashboardBaseURL(c.Request.Context())) })
for _, tt := range []struct{ origin, want string }{
{"https://tac-security-assessment.warmbly.com", "https://tac-security-assessment.warmbly.com"},
{"https://second.example.com", "https://second.example.com"},
{"https://evil.example.com", "https://app.warmbly.com"},
{"", "https://app.warmbly.com"},
} {
+4 -4
View File
@@ -331,9 +331,9 @@ func serviceAccountKey(t *testing.T, tokenURL string) []byte {
func TestGrantOriginBoundToUnconsumedState(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
s, p, _, _, _ := newTestService(t)
ctx := config.WithDashboardOrigin(context.Background(), "https://tac-security-assessment.warmbly.com")
ctx := config.WithDashboardOrigin(context.Background(), "https://second.example.com")
org, user := uuid.New(), uuid.New()
holdLegacyGoogle(t, s, org)
g, xerr := s.StartGoogle(ctx, org, user, "acme.io", "admin@acme.io")
@@ -345,7 +345,7 @@ func TestGrantOriginBoundToUnconsumedState(t *testing.T) {
t.Fatal(xerr)
}
for _, state := range []string{g.State, ms} {
if got := s.OAuthReturnOrigin(context.Background(), state); got != "https://tac-security-assessment.warmbly.com" {
if got := s.OAuthReturnOrigin(context.Background(), state); got != "https://second.example.com" {
t.Fatalf("origin = %q", got)
}
st, ok := p.states.Peek(ctx, "mailbox_grant_state:"+state)
@@ -353,7 +353,7 @@ func TestGrantOriginBoundToUnconsumedState(t *testing.T) {
t.Fatal("routing must preserve identity and PKCE state")
}
}
if s.MicrosoftSigninURL(context.Background(), ms) == "" || s.OAuthReturnOrigin(ctx, ms) != "https://tac-security-assessment.warmbly.com" {
if s.MicrosoftSigninURL(context.Background(), ms) == "" || s.OAuthReturnOrigin(ctx, ms) != "https://second.example.com" {
t.Fatal("second Microsoft sign-in must retain origin")
}
p.states.Take(ctx, "mailbox_grant_state:"+ms)
+10 -10
View File
@@ -27,7 +27,7 @@ func TestLegacyMailboxStateUsesPrimaryDashboard(t *testing.T) {
t.Cleanup(func() { _ = c.Close() })
t.Setenv("APP_URL", "https://app.warmbly.com/")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
svc := &emailService{r: c}
ctx := context.Background()
for _, provider := range []string{"gmail", "outlook"} {
@@ -46,7 +46,7 @@ func TestLegacyMailboxStateUsesPrimaryDashboard(t *testing.T) {
func TestOAuthStartRejectsUntrustedReturnOrigin(t *testing.T) {
t.Setenv("APP_URL", "https://app.example.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://assessment.example.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
svc := &emailService{}
org := uuid.New()
for _, tt := range []struct {
@@ -54,8 +54,8 @@ func TestOAuthStartRejectsUntrustedReturnOrigin(t *testing.T) {
web bool
}{
{"https://evil.example.com", true},
{"https://assessment.example.com/path", true},
{"https://assessment.example.com", false},
{"https://second.example.com/path", true},
{"https://second.example.com", false},
} {
if _, xerr := svc.OAuthStart(context.Background(), uuid.NewString(), &org, models.InboxProviderGoogle, "", tt.web, tt.origin); xerr != errx.ErrEmailOnboardReturnOrigin {
t.Fatalf("untrusted return origin should fail before storing state, got %v", xerr)
@@ -66,7 +66,7 @@ func TestOAuthStartRejectsUntrustedReturnOrigin(t *testing.T) {
func TestOAuthReauthRejectsUntrustedGoogleReturnOrigin(t *testing.T) {
t.Setenv("APP_URL", "https://app.example.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://assessment.example.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
svc, repo, _, _ := reauthFixture("gmail", "owner@example.com")
_, xerr := svc.OAuthReauth(context.Background(), repo.account.UserID, repo.account.OrganizationID, repo.account.ID, "https://evil.example.com")
if xerr != errx.ErrEmailOnboardReturnOrigin {
@@ -94,7 +94,7 @@ func TestMailboxOAuthOriginStaysBoundToSingleUseState(t *testing.T) {
t.Cleanup(func() { _ = c.Close() })
t.Setenv("APP_URL", "https://app.example.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://assessment.example.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
t.Setenv("BOX_GOOGLE_CLIENT_ID", "client")
t.Setenv("BOX_GOOGLE_CLIENT_SECRET", "secret")
t.Setenv("BOX_GOOGLE_OAUTH_CONNECT", "")
@@ -110,23 +110,23 @@ func TestMailboxOAuthOriginStaysBoundToSingleUseState(t *testing.T) {
var xerr *errx.Error
if reauth {
t.Setenv("BOX_GOOGLE_OAUTH_CONNECT", "false")
resp, xerr = svc.OAuthReauth(ctx, repo.account.UserID, repo.account.OrganizationID, repo.account.ID, "https://assessment.example.com")
resp, xerr = svc.OAuthReauth(ctx, repo.account.UserID, repo.account.OrganizationID, repo.account.ID, "https://second.example.com")
} else {
t.Setenv("BOX_GOOGLE_OAUTH_CONNECT", "")
resp, xerr = svc.OAuthStart(ctx, repo.account.UserID, repo.account.OrganizationID, models.InboxProvider(provider), "", true, "https://assessment.example.com")
resp, xerr = svc.OAuthStart(ctx, repo.account.UserID, repo.account.OrganizationID, models.InboxProvider(provider), "", true, "https://second.example.com")
}
if xerr != nil {
t.Fatal(xerr)
}
t.Cleanup(func() { _ = c.Del(ctx, onboardingStateKey(resp.State)).Err() })
if origin := svc.OAuthReturnOrigin(ctx, resp.State); origin != "https://assessment.example.com" {
if origin := svc.OAuthReturnOrigin(ctx, resp.State); origin != "https://second.example.com" {
t.Fatalf("state-bound origin = %q", origin)
}
if svc.OAuthReturnOrigin(ctx, "w.unknown") != "" || svc.OAuthReturnOrigin(ctx, "native") != "" {
t.Fatal("unknown or native state must not select a dashboard")
}
sess, xerr := svc.takeOnboardingState(ctx, resp.State)
if xerr != nil || sess.ReturnOrigin != "https://assessment.example.com" || sess.CodeVerifier == "" || sess.UserID != repo.account.UserID || (sess.EmailAccountID != nil) != reauth {
if xerr != nil || sess.ReturnOrigin != "https://second.example.com" || sess.CodeVerifier == "" || sess.UserID != repo.account.UserID || (sess.EmailAccountID != nil) != reauth {
t.Fatalf("callback metadata lookup must preserve the finish state: %+v, %v", sess, xerr)
}
if svc.OAuthReturnOrigin(ctx, resp.State) != "" {
@@ -37,12 +37,12 @@ func (r *originRepo) SetConnectionStatus(context.Context, uuid.UUID, models.Inte
func TestIntegrationStartAndReauthBindDashboardOrigin(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
t.Setenv("HUBSPOT_OAUTH_CLIENT_ID", "client")
t.Setenv("HUBSPOT_OAUTH_CLIENT_SECRET", "secret")
r := &originRepo{}
s := &service{repo: r, oauth: NewOAuthManager()}
ctx := config.WithDashboardOrigin(context.Background(), "https://tac-security-assessment.warmbly.com")
ctx := config.WithDashboardOrigin(context.Background(), "https://second.example.com")
org, user := uuid.New(), uuid.New()
for _, reauth := range []bool{false, true} {
var resp *models.IntegrationOAuthStartResponse
@@ -55,7 +55,7 @@ func TestIntegrationStartAndReauthBindDashboardOrigin(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if got := s.OAuthReturnOrigin(context.Background(), resp.State); got != "https://tac-security-assessment.warmbly.com" {
if got := s.OAuthReturnOrigin(context.Background(), resp.State); got != "https://second.example.com" {
t.Fatalf("origin = %q", got)
}
if r.state.UserID != user || r.state.OrganizationID != org || r.state.UsedAt != nil {
@@ -79,6 +79,6 @@ func TestIntegrationStartAndReauthBindDashboardOrigin(t *testing.T) {
if s.OAuthReturnOrigin(ctx, resp.State) != "" {
t.Fatal("removed origin must not route")
}
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
}
}
+4 -4
View File
@@ -13,12 +13,12 @@ import (
func TestSlackVerifyCallbackOriginIsStateBound(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
s := &Service{guard: newGuard(nil)}
ctx := context.Background()
blob, _ := json.Marshal(verifyState{ReturnOrigin: "https://tac-security-assessment.warmbly.com"})
blob, _ := json.Marshal(verifyState{ReturnOrigin: "https://second.example.com"})
s.guard.put(ctx, verifyKey("state"), string(blob), time.Minute)
if s.OAuthReturnOrigin(ctx, "state") != "https://tac-security-assessment.warmbly.com" || s.guard.get(ctx, verifyKey("state")) == "" {
if s.OAuthReturnOrigin(ctx, "state") != "https://second.example.com" || s.guard.get(ctx, verifyKey("state")) == "" {
t.Fatal("routing must preserve verification state")
}
if s.OAuthReturnOrigin(ctx, "unknown") != "" {
@@ -28,7 +28,7 @@ func TestSlackVerifyCallbackOriginIsStateBound(t *testing.T) {
if s.OAuthReturnOrigin(ctx, "state") != "" {
t.Fatal("consumed state must not route")
}
for _, origin := range []string{"https://evil.example.com", "https://tac-security-assessment.warmbly.com/path"} {
for _, origin := range []string{"https://evil.example.com", "https://second.example.com/path"} {
blob, _ := json.Marshal(verifyState{ReturnOrigin: origin})
s.guard.put(ctx, verifyKey("state"), string(blob), time.Minute)
if s.OAuthReturnOrigin(ctx, "state") != "" {
+11 -11
View File
@@ -10,9 +10,9 @@ import (
func TestDashboardEmailLinks(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.warmbly.com,https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.warmbly.com,https://second.example.com")
for _, tt := range []struct{ origin, want string }{
{"https://tac-security-assessment.warmbly.com", "https://tac-security-assessment.warmbly.com"},
{"https://second.example.com", "https://second.example.com"},
{"https://app.warmbly.com", "https://app.warmbly.com"},
{"", "https://app.warmbly.com"},
{"https://evil.example.com", "https://app.warmbly.com"},
@@ -41,11 +41,11 @@ func TestPasswordResetLinkKeepsTheTokenOutOfTheQuery(t *testing.T) {
func TestPrimaryDashboardOriginAndRevalidation(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com/")
t.Setenv("APP_ORIGIN", "")
t.Setenv("CORS_ALLOW_ORIGINS", "https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://second.example.com")
if got := PrimaryDashboardOrigin(); got != "https://app.warmbly.com" {
t.Fatalf("primary origin = %q", got)
}
ctx := WithDashboardOrigin(context.Background(), "https://tac-security-assessment.warmbly.com")
ctx := WithDashboardOrigin(context.Background(), "https://second.example.com")
t.Setenv("CORS_ALLOW_ORIGINS", "*")
if DashboardOriginFromContext(ctx) != "" || DashboardBaseURL(ctx) != "https://app.warmbly.com" {
t.Fatal("removed origin must not remain trusted")
@@ -56,12 +56,12 @@ func TestSharedBackendDashboardOrigins(t *testing.T) {
t.Setenv("APP_URL", "https://app.warmbly.com")
t.Setenv("APP_ORIGIN", "")
t.Setenv("WEBSOCKET_URL", "wss://rt.example.com/socket/websocket")
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.warmbly.com, https://admin.example.com,https://tac-security-assessment.warmbly.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.warmbly.com, https://admin.example.com,https://second.example.com")
cfg, err := (&Config{Env: "prod"}).LoadApiConfig(context.Background())
if err != nil {
t.Fatal(err)
}
want := []string{"https://app.warmbly.com", "https://admin.example.com", "https://tac-security-assessment.warmbly.com"}
want := []string{"https://app.warmbly.com", "https://admin.example.com", "https://second.example.com"}
if !slices.Equal(cfg.AllowedOrigins, want) {
t.Fatalf("API origins = %v, want %v", cfg.AllowedOrigins, want)
}
@@ -71,21 +71,21 @@ func TestSharedBackendDashboardOrigins(t *testing.T) {
}
}
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.warmbly.com,https://admin.example.com")
if got := DashboardOrigin("https://tac-security-assessment.warmbly.com"); got != "" {
t.Fatal("assessment origin must be explicitly configured, not hard-coded")
if got := DashboardOrigin("https://second.example.com"); got != "" {
t.Fatal("a second dashboard origin must be explicitly configured, not hard-coded")
}
}
func TestDashboardOrigin(t *testing.T) {
t.Setenv("APP_URL", "https://app.example.com")
t.Setenv("APP_ORIGIN", "https://primary.example.com")
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.example.com, https://assessment.example.com,http://localhost:5173")
for _, value := range []string{"https://app.example.com", "https://primary.example.com", "https://assessment.example.com", "http://localhost:5173"} {
t.Setenv("CORS_ALLOW_ORIGINS", "https://app.example.com, https://second.example.com,http://localhost:5173")
for _, value := range []string{"https://app.example.com", "https://primary.example.com", "https://second.example.com", "http://localhost:5173"} {
if got := DashboardOrigin(value); got != value {
t.Errorf("DashboardOrigin(%q) = %q", value, got)
}
}
for _, value := range []string{"", "null", "*", "https://evil.example.com", "https://assessment.example.com.evil.test", "http://assessment.example.com", "https://assessment.example.com:444", "https://assessment.example.com/", "https://assessment.example.com/redirect", "https://assessment.example.com?x=1", "https://assessment.example.com?", "https://assessment.example.com#fragment", "https://user@assessment.example.com", "javascript:alert(1)"} {
for _, value := range []string{"", "null", "*", "https://evil.example.com", "https://second.example.com.evil.test", "http://second.example.com", "https://second.example.com:444", "https://second.example.com/", "https://second.example.com/redirect", "https://second.example.com?x=1", "https://second.example.com?", "https://second.example.com#fragment", "https://user@second.example.com", "javascript:alert(1)"} {
if got := DashboardOrigin(value); got != "" {
t.Errorf("DashboardOrigin(%q) = %q, want empty", value, got)
}
-2
View File
@@ -9,8 +9,6 @@ const at = (local: string, domain: string) => `${local}@${domain}`;
const MAILBOX_EMAIL = at("dev.outbound", "warmbly.test");
async function enableGoogleSignin(page: Page) {
await page.route("**/config.js", (route) =>
route.fulfill({ contentType: "text/javascript", body: 'window.__WARMBLY_ENV__ = { GMAIL_OAUTH_CONNECT: "true" };' }));
await page.route("**/v1/auth/config", async (route) => {
const response = await route.fetch();
await route.fulfill({ response, json: { ...await response.json(), gmail_oauth_connect: true } });
-1
View File
@@ -1,4 +1,3 @@
VITE_APP_URL="http://localhost:5173"
VITE_API_URL="http://localhost:8080"
VITE_TURNSTILE_KEY="1x00000000000000000000AA"
VITE_GMAIL_OAUTH_CONNECT="false"
-1
View File
@@ -23,7 +23,6 @@ window.__WARMBLY_ENV__ = {
API_URL: "$(js "${WARMBLY_API_URL:-}")",
APP_URL: "$(js "${WARMBLY_APP_URL:-}")",
TURNSTILE_KEY: "$(js "${WARMBLY_TURNSTILE_KEY:-}")",
GMAIL_OAUTH_CONNECT: "$(js "${WARMBLY_GMAIL_OAUTH_CONNECT:-}")",
BETA_NOTICE: "$(js "${WARMBLY_BETA_NOTICE:-}")",
SENTRY_DSN: "$(js "${WARMBLY_SENTRY_DSN:-}")",
SENTRY_ENVIRONMENT: "$(js "${WARMBLY_SENTRY_ENVIRONMENT:-}")",
+8 -23
View File
@@ -1,5 +1,7 @@
import { renderHook } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import useGmailOAuthConnect from "./useGmailOAuthConnect";
const auth = vi.hoisted(() => ({ gmail_oauth_connect: false }));
vi.mock("@/lib/api/hooks/auth/useAuthConfig", () => ({
@@ -7,33 +9,16 @@ vi.mock("@/lib/api/hooks/auth/useAuthConfig", () => ({
}));
beforeEach(() => {
vi.resetModules();
delete window.__WARMBLY_ENV__;
vi.stubEnv("VITE_GMAIL_OAUTH_CONNECT", undefined);
auth.gmail_oauth_connect = false;
});
afterEach(() => {
vi.unstubAllEnvs();
delete window.__WARMBLY_ENV__;
});
describe("Google mailbox OAuth deployment capability", () => {
describe("Google mailbox sign-in availability", () => {
it.each([
{ name: "defaults off even with backend support", backend: true, expected: false },
{ name: "uses runtime opt-in with backend support", runtime: "true", backend: true, expected: true },
{ name: "respects backend disable", runtime: "true", backend: false, expected: false },
{ name: "uses Vite opt-in in development", build: "true", backend: true, expected: true },
{ name: "runtime off overrides a build-time opt-in", runtime: "false", build: "true", backend: true, expected: false },
{ name: "ignores an invalid frontend setting", runtime: "invalid", backend: true, expected: false },
{ name: "trims a true frontend setting", runtime: " TRUE ", backend: true, expected: true },
{ name: "requires frontend opt-in for Cloud", viaCloud: true, backend: false, expected: false },
{ name: "allows opted-in Cloud-brokered consent", runtime: "true", viaCloud: true, backend: false, expected: true },
])("$name", async ({ runtime, build, backend, viaCloud, expected }) => {
window.__WARMBLY_ENV__ = { GMAIL_OAUTH_CONNECT: runtime };
vi.stubEnv("VITE_GMAIL_OAUTH_CONNECT", build);
{ name: "shows when the backend allows it", backend: true, expected: true },
{ name: "hides when the backend disables it", backend: false, expected: false },
{ name: "shows for Cloud-brokered consent", viaCloud: true, backend: false, expected: true },
])("$name", ({ backend, viaCloud, expected }) => {
auth.gmail_oauth_connect = backend;
const { default: useGmailOAuthConnect } = await import("./useGmailOAuthConnect");
const { result, unmount } = renderHook(() => useGmailOAuthConnect(viaCloud));
expect(result.current).toBe(expected);
unmount();
+2 -2
View File
@@ -1,7 +1,7 @@
import useAuthConfig from "@/lib/api/hooks/auth/useAuthConfig";
import { GMAIL_OAUTH_CONNECT } from "@/lib/information";
// The backend decides; Cloud-brokered consent runs on Warmbly Cloud's client, not this instance's.
export default function useGmailOAuthConnect(viaCloud = false): boolean {
const { config } = useAuthConfig();
return GMAIL_OAUTH_CONNECT && (viaCloud || config.gmail_oauth_connect === true);
return viaCloud || config.gmail_oauth_connect === true;
}
-2
View File
@@ -8,8 +8,6 @@ export const API_URL = runtimeEnv("API_URL", import.meta.env.VITE_API_URL);
// (no path), so this is the single place the /v1 prefix is applied.
export const API_BASE_URL = `${API_URL}/v1`;
export const TURNSTILE_KEY = runtimeEnv("TURNSTILE_KEY", import.meta.env.VITE_TURNSTILE_KEY);
// Visibility only; the backend still decides whether a new mailbox can connect.
export const GMAIL_OAUTH_CONNECT = runtimeEnv("GMAIL_OAUTH_CONNECT", import.meta.env.VITE_GMAIL_OAUTH_CONNECT, "false").trim().toLowerCase() === "true";
// Shown once in a dialog and then as a header pill. Empty means this is not a
// preview deployment and nothing renders, which is what production wants