From 80211d205c810ca7f5dd80e1c1c8f9684c0f1ad9 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 5 Oct 2026 16:55:05 -0400 Subject: [PATCH 1/2] fix(cloud): show the SSO-required dialog before signing the refused account out Signing out clears the remote config, which drops sso_enabled, so presentSsoRequired after logout() saw the flag off and showed nothing. Present first, then sign out. --- src/platform/cloud/onboarding/CloudLoginView.test.ts | 10 +++++++++- .../cloud/onboarding/composables/useCloudAuthPage.ts | 5 ++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/platform/cloud/onboarding/CloudLoginView.test.ts b/src/platform/cloud/onboarding/CloudLoginView.test.ts index 67d13cb864e..1c37d125911 100644 --- a/src/platform/cloud/onboarding/CloudLoginView.test.ts +++ b/src/platform/cloud/onboarding/CloudLoginView.test.ts @@ -536,9 +536,13 @@ describe('CloudLoginView Firebase sign-in refused for SSO', () => { returnTo: '/workflows?id=7' } ])('with the flag on, $name', async ({ url, returnTo }) => { - vi.mocked(useFeatureFlags().flags).ssoEnabled = true + const flags = vi.mocked(useFeatureFlags().flags) + flags.ssoEnabled = true sessionRequiresSso.mockResolvedValue(true) await renderLoginView(url) + vi.mocked(useAuthStore().logout).mockImplementation(async () => { + flags.ssoEnabled = false + }) await signInWithFirebase() @@ -548,6 +552,10 @@ describe('CloudLoginView Firebase sign-in refused for SSO', () => { returnTo }) ) + expect( + vi.mocked(presentSsoRequired).mock.results[0].value, + 'shown before the sign-out drops the remote config that carries sso_enabled' + ).toBe(true) expect(useAuthStore().logout).toHaveBeenCalledOnce() expect(redirectAfterAuth).not.toHaveBeenCalled() }) diff --git a/src/platform/cloud/onboarding/composables/useCloudAuthPage.ts b/src/platform/cloud/onboarding/composables/useCloudAuthPage.ts index fc091e299a9..ff7315a542b 100644 --- a/src/platform/cloud/onboarding/composables/useCloudAuthPage.ts +++ b/src/platform/cloud/onboarding/composables/useCloudAuthPage.ts @@ -48,12 +48,11 @@ export function useCloudAuthPage(options: { async function onAuthSuccess() { if (flags.ssoEnabled && (await useSessionCookie().sessionRequiresSso())) { const authStore = useAuthStore() - const email = authStore.userEmail ?? undefined - await authStore.logout() presentSsoRequired({ - email, + email: authStore.userEmail ?? undefined, returnTo: getSafePreviousFullPath(route.query) ?? SSO_DEFAULT_RETURN_TO }) + await authStore.logout() return } await redirectAfterAuth() From 8ffe3257c40f0dbf1632f428257361a34f942ae0 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Mon, 5 Oct 2026 16:55:18 -0400 Subject: [PATCH 2/2] test(cloud): e2e for the SSO sign-in entry, session boot and sso_required --- browser_tests/fixtures/data/sso.ts | 31 +++ browser_tests/fixtures/webSessionFixture.ts | 12 +- .../tests/cloudSsoSessionBoot.spec.ts | 51 ++++ browser_tests/tests/cloudSsoSignIn.spec.ts | 255 ++++++++++++++++++ 4 files changed, 347 insertions(+), 2 deletions(-) create mode 100644 browser_tests/fixtures/data/sso.ts create mode 100644 browser_tests/tests/cloudSsoSessionBoot.spec.ts create mode 100644 browser_tests/tests/cloudSsoSignIn.spec.ts diff --git a/browser_tests/fixtures/data/sso.ts b/browser_tests/fixtures/data/sso.ts new file mode 100644 index 00000000000..7feeae9c8df --- /dev/null +++ b/browser_tests/fixtures/data/sso.ts @@ -0,0 +1,31 @@ +import type { + ErrorResponse, + SsoDiscoverResponse, + WebSessionResponse +} from '@comfyorg/ingest-types' + +import { WEB_SESSION } from '@e2e/fixtures/data/webSession' + +export const SSO_EMAIL = 'ada@acme.example' + +export const SSO_DISCOVERED: SsoDiscoverResponse = { + sso: true, + organization_name: 'Acme' +} + +export const NOT_SSO: SsoDiscoverResponse = { sso: false } + +export const SSO_DISCOVER_DOWN: ErrorResponse = { + code: 'internal_error', + message: 'discover is down' +} + +export const SSO_REQUIRED: ErrorResponse = { + code: 'sso_required', + message: 'This account signs in with SSO' +} + +export const SSO_WEB_SESSION: WebSessionResponse = { + ...WEB_SESSION, + user: { ...WEB_SESSION.user, sign_in_provider: 'saml.workos' } +} diff --git a/browser_tests/fixtures/webSessionFixture.ts b/browser_tests/fixtures/webSessionFixture.ts index ce02ee51f7d..48a8a44746d 100644 --- a/browser_tests/fixtures/webSessionFixture.ts +++ b/browser_tests/fixtures/webSessionFixture.ts @@ -34,6 +34,8 @@ interface TokenMint { } interface WebSessionFixtures { + /** Flags merged into both `/api/features` answers, over the backend's. */ + serverFeatures: RemoteConfig tokenMints: TokenMint[] workspaceReads: Request[] firebaseRequests: string[] @@ -41,6 +43,7 @@ interface WebSessionFixtures { } export const webSessionTest = comfyPageFixture.extend({ + serverFeatures: [{}, { option: true }], tokenMints: async ({ context }, use) => { const mints: TokenMint[] = [] context.on('request', (request) => { @@ -97,6 +100,7 @@ export const webSessionTest = comfyPageFixture.extend({ { page, context, + serverFeatures, tokenMints, workspaceReads, firebaseRequests, @@ -120,8 +124,12 @@ export const webSessionTest = comfyPageFixture.extend({ await route.fulfill( jsonRoute( credentialed - ? { ...backendFeatures, ...WEB_SESSION_FEATURES } - : { ...backendFeatures, ...WEB_SESSION_ANONYMOUS_FEATURES } + ? { ...backendFeatures, ...WEB_SESSION_FEATURES, ...serverFeatures } + : { + ...backendFeatures, + ...WEB_SESSION_ANONYMOUS_FEATURES, + ...serverFeatures + } ) ) }) diff --git a/browser_tests/tests/cloudSsoSessionBoot.spec.ts b/browser_tests/tests/cloudSsoSessionBoot.spec.ts new file mode 100644 index 00000000000..8e9e1020ecc --- /dev/null +++ b/browser_tests/tests/cloudSsoSessionBoot.spec.ts @@ -0,0 +1,51 @@ +import { expect } from '@playwright/test' + +import { SSO_WEB_SESSION } from '@e2e/fixtures/data/sso' +import { webSessionTest } from '@e2e/fixtures/webSessionFixture' +import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' + +/** The session of a person who signed in through their organization's SSO. */ +const test = webSessionTest.extend({ + page: async ({ page }, use) => { + await page.route('**/api/auth/session', async (route) => { + if (route.request().method() !== 'GET') return route.fallback() + await route.fulfill(jsonRoute(SSO_WEB_SESSION)) + }) + await use(page) + } +}) + +test.describe( + 'Cloud boot on an SSO session', + { tag: ['@cloud', '@ui'] }, + () => { + test.describe.configure({ timeout: 60_000 }) + + test.use({ + firebaseLogin: false, + serverFeatures: { sso_enabled: true } + }) + + test('a session-only SSO user boots into the app as the session user, with no Firebase traffic', async ({ + comfyPage, + firebaseRequests + }) => { + const page = comfyPage.page + await comfyPage.waitForAppReady() + expect(page.url()).not.toContain('/cloud/login') + + await comfyPage.toast.closeToasts() + await page.keyboard.press('Escape') + await page.getByRole('button', { name: 'Current user' }).click() + await expect(page.getByText(SSO_WEB_SESSION.user.email)).toBeVisible() + + expect( + await page.evaluate(() => + localStorage.getItem('Comfy.WebSession.SsoHint') + ), + 'the SSO session leaves its email for a later SSO re-entry' + ).toBe(JSON.stringify({ email: SSO_WEB_SESSION.user.email })) + expect(firebaseRequests).toEqual([]) + }) + } +) diff --git a/browser_tests/tests/cloudSsoSignIn.spec.ts b/browser_tests/tests/cloudSsoSignIn.spec.ts new file mode 100644 index 00000000000..5c066743d51 --- /dev/null +++ b/browser_tests/tests/cloudSsoSignIn.spec.ts @@ -0,0 +1,255 @@ +import { expect } from '@playwright/test' +import type { Page, Request } from '@playwright/test' + +import type { ErrorResponse, SsoDiscoverResponse } from '@comfyorg/ingest-types' + +import enMessages from '@/locales/en/main.json' with { type: 'json' } +import type { RemoteConfig } from '@/platform/remoteConfig/types' +import type { operations } from '@/types/comfyRegistryTypes' + +import { + NOT_SSO, + SSO_DISCOVERED, + SSO_DISCOVER_DOWN, + SSO_EMAIL, + SSO_REQUIRED +} from '@e2e/fixtures/data/sso' +import { comfyPageFixture } from '@e2e/fixtures/ComfyPage' +import { + CLOUD_SELF_EMAIL, + CloudAuthHelper +} from '@e2e/fixtures/helpers/CloudAuthHelper' +import { + mockCloudBoot, + preselectCloudUser +} from '@e2e/fixtures/utils/cloudBootMocks' +import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' + +const APP_URL = process.env.PLAYWRIGHT_TEST_URL || 'http://localhost:8188' +const APP_ROOT = new RegExp( + `^${APP_URL.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/?(\\?.*)?$` +) +const SSO_COPY = enMessages.auth.sso +type CreateCustomerResponse = + operations['createCustomer']['responses']['201']['content']['application/json'] + +function isPath(request: Request, pathname: string) { + return new URL(request.url()).pathname === pathname +} + +/** + * The cloud login page's SSO entry, with `sso_enabled` patched into the + * backend's own `/api/features` answer and ingest's SSO endpoints mocked at + * the network layer. Ingest's `/api/auth/sso/start` answers with a redirect + * to WorkOS; here it is fulfilled in place so the navigation is observed and + * never followed. + */ +const test = comfyPageFixture.extend<{ + ssoEnabled: boolean + cloudAuth: CloudAuthHelper + discoverRequests: Request[] + ssoStarts: Request[] +}>({ + ssoEnabled: [true, { option: true }], + discoverRequests: async ({ context }, use) => { + const requests: Request[] = [] + context.on('request', (request) => { + if (isPath(request, '/api/auth/sso/discover')) requests.push(request) + }) + await use(requests) + }, + ssoStarts: async ({ context }, use) => { + const requests: Request[] = [] + context.on('request', (request) => { + if (isPath(request, '/api/auth/sso/start')) requests.push(request) + }) + await use(requests) + }, + page: async ({ page, ssoEnabled, discoverRequests, ssoStarts }, use) => { + void discoverRequests + void ssoStarts + await mockCloudBoot(page, { features: {} }) + await page.route('**/api/features', async (route) => { + const backendFeatures: RemoteConfig = await (await route.fetch()).json() + await route.fulfill( + jsonRoute({ ...backendFeatures, sso_enabled: ssoEnabled }) + ) + }) + await preselectCloudUser(page) + await page.route('**/customers', (route) => { + if (route.request().method() !== 'POST') return route.fallback() + return route.fulfill({ + status: 201, + json: { id: 'test-customer-e2e' } satisfies CreateCustomerResponse + }) + }) + await page.route('**/api/auth/sso/start**', (route) => + route.fulfill({ status: 200, contentType: 'text/html', body: '' }) + ) + await use(page) + }, + cloudAuth: async ({ page }, use) => { + await use(new CloudAuthHelper(page)) + } +}) + +async function answerDiscover( + page: Page, + status: number, + body: SsoDiscoverResponse | ErrorResponse +) { + await page.route('**/api/auth/sso/discover', (route) => + route.fulfill({ status, json: body }) + ) +} + +async function openLogin(page: Page) { + await page.goto(APP_URL) + await expect( + page.getByRole('heading', { name: 'Log in to your account' }) + ).toBeVisible() +} + +async function signInWithEmail(page: Page) { + await openLogin(page) + await page.getByRole('button', { name: 'Use email instead' }).click() + await page.locator('#cloud-sign-in-email').fill(CLOUD_SELF_EMAIL) + await page + .locator('#cloud-sign-in-password') + .fill('correct-horse-battery-staple') + await page.locator('#cloud-sign-in-password').blur() + await page.getByRole('button', { name: 'Sign in' }).click() +} + +async function continueWithSso(page: Page, email: string) { + await openLogin(page) + await page.getByRole('button', { name: SSO_COPY.continueWithSso }).click() + await page.locator('#cloud-sso-email').fill(email) + await page.getByRole('button', { name: SSO_COPY.submit, exact: true }).click() +} + +test.describe('Cloud login SSO entry', { tag: ['@cloud', '@ui'] }, () => { + test.describe('sso_enabled off', () => { + test.use({ ssoEnabled: false }) + + test('offers no SSO entry and signs an email in through Firebase without asking discover', async ({ + page, + cloudAuth, + discoverRequests + }) => { + await answerDiscover(page, 200, SSO_DISCOVERED) + await cloudAuth.mockLiveEmailSignIn() + + await openLogin(page) + await expect( + page.getByRole('button', { name: SSO_COPY.continueWithSso }) + ).toHaveCount(0) + await signInWithEmail(page) + + await expect(page).toHaveURL(APP_ROOT, { timeout: 10_000 }) + expect(discoverRequests).toEqual([]) + }) + }) + + test.describe('sso_enabled on', () => { + test('an SSO email navigates to ingest SSO start with its email and return path', async ({ + page, + discoverRequests, + ssoStarts + }) => { + await answerDiscover(page, 200, SSO_DISCOVERED) + const start = page.waitForRequest((request) => + isPath(request, '/api/auth/sso/start') + ) + + await continueWithSso(page, SSO_EMAIL) + + const url = new URL((await start).url()) + expect({ + origin: url.origin, + email: url.searchParams.get('email'), + returnTo: url.searchParams.get('return_to'), + navigation: (await start).isNavigationRequest() + }).toEqual({ + origin: new URL(APP_URL).origin, + email: SSO_EMAIL, + returnTo: '/cloud/user-check', + navigation: true + }) + expect(discoverRequests.map((r) => r.postDataJSON())).toEqual([ + { email: SSO_EMAIL } + ]) + expect(ssoStarts).toHaveLength(1) + }) + + test('an email that does not use SSO stays on the login page with the not-SSO message', async ({ + page, + ssoStarts + }) => { + await answerDiscover(page, 200, NOT_SSO) + + await continueWithSso(page, CLOUD_SELF_EMAIL) + + await expect(page.getByText(SSO_COPY.notSso)).toBeVisible() + await expect(page).toHaveURL(/\/cloud\/login/) + expect(ssoStarts).toEqual([]) + }) + + test('a discover outage still signs a password login in through Firebase', async ({ + page, + cloudAuth, + discoverRequests, + ssoStarts + }) => { + await answerDiscover(page, 500, SSO_DISCOVER_DOWN) + await cloudAuth.mockLiveEmailSignIn() + const firebaseSignIn = page.waitForRequest((request) => + request.url().includes('accounts:signInWithPassword') + ) + + await signInWithEmail(page) + + await firebaseSignIn + await expect(page).toHaveURL(APP_ROOT, { timeout: 10_000 }) + expect(discoverRequests).toHaveLength(1) + expect(ssoStarts).toEqual([]) + }) + + test('an sso_error ingest sends back shows its message on the login page', async ({ + page + }) => { + await page.goto(`${APP_URL}/?sso_error=SSO_ORG_DISABLED`) + + await expect(page).toHaveURL( + /\/cloud\/login\?.*sso_error=SSO_ORG_DISABLED/ + ) + await expect(page.getByText(SSO_COPY.errors.orgDisabled)).toBeVisible() + }) + + test('a Firebase sign-in ingest refuses with sso_required opens the SSO dialog', async ({ + page, + cloudAuth + }) => { + await answerDiscover(page, 200, NOT_SSO) + await cloudAuth.mockLiveEmailSignIn() + await page.route('**/api/auth/session', (route) => + route.request().method() === 'POST' + ? route.fulfill({ status: 403, json: SSO_REQUIRED }) + : route.fallback() + ) + + await signInWithEmail(page) + + const dialog = page.getByRole('dialog') + await expect( + dialog.getByRole('heading', { name: SSO_COPY.required.title }) + ).toBeVisible() + await expect( + dialog.getByText( + SSO_COPY.required.bodyWithEmail.replace('{email}', CLOUD_SELF_EMAIL) + ) + ).toBeVisible() + await expect(page).toHaveURL(/\/cloud\/login/) + }) + }) +})