From c6ff627bed460080c401f277f6c50a74f50e0cea Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 8 Oct 2026 04:51:59 -0400 Subject: [PATCH 1/3] test(cloud): pin the full-page SSO return to the served consent path Adds the browser case Christian asked for on #20468: SSO start 302s to its return_to, a document load of /oauth/consent answers the server's JSON 404, and the sign-in must still reach the consent page with the same oauth_request_id. Also maps /oauth/consent/ (trailing slash) like /oauth/consent and names BE-4146 so the helper and the redirect route are removed together. --- browser_tests/tests/cloudSsoSignIn.spec.ts | 70 +++++++++++++++++++++ src/platform/auth/sso/ssoReturnPath.test.ts | 35 +++++++++++ src/platform/auth/sso/ssoReturnPath.ts | 7 ++- 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 src/platform/auth/sso/ssoReturnPath.test.ts diff --git a/browser_tests/tests/cloudSsoSignIn.spec.ts b/browser_tests/tests/cloudSsoSignIn.spec.ts index 411e17be93c..eb2a311170b 100644 --- a/browser_tests/tests/cloudSsoSignIn.spec.ts +++ b/browser_tests/tests/cloudSsoSignIn.spec.ts @@ -4,6 +4,7 @@ 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 { OAuthConsentChallenge } from '@/platform/cloud/oauth/oauthApi' import type { operations } from '@/types/comfyRegistryTypes' import { @@ -28,6 +29,24 @@ const APP_ROOT = new RegExp( `^${APP_URL.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/?(\\?.*)?$` ) const SSO_COPY = enMessages.auth.sso +const OAUTH_REQUEST_ID = '550e8400-e29b-41d4-a716-446655440000' +const CONSENT_CHALLENGE: OAuthConsentChallenge = { + oauth_request_id: OAUTH_REQUEST_ID, + csrf_token: 'csrf-token', + client_display_name: 'Comfy Desktop', + resource_display_name: 'Comfy Cloud', + redirect_uri: 'http://127.0.0.1:50632/callback', + client_application_type: 'native', + scopes: ['comfy-cloud:user:read'], + workspaces: [ + { + id: 'personal-workspace', + name: 'Personal', + type: 'personal', + role: 'owner' + } + ] +} type CreateCustomerResponse = operations['createCustomer']['responses']['201']['content']['application/json'] @@ -177,6 +196,57 @@ test.describe('Cloud login SSO entry', { tag: ['@cloud', '@ui'] }, () => { expect(ssoStarts).toHaveLength(1) }) + test('an SSO sign-in for a pending OAuth request returns to a consent page the server serves', async ({ + page + }) => { + await answerDiscover(page, 200, SSO_DISCOVERED) + await page.route('**/api/auth/sso/start**', (route) => { + const returnTo = new URL(route.request().url()).searchParams.get( + 'return_to' + ) + return route.fulfill({ + status: 302, + headers: { location: new URL(returnTo ?? '/', APP_URL).toString() } + }) + }) + await page.route('**/oauth/consent**', (route) => + route.request().resourceType() === 'document' && + new URL(route.request().url()).pathname.replace(/\/+$/, '') === + '/oauth/consent' + ? route.fulfill({ + status: 404, + json: { code: 'NOT_FOUND', message: 'Not Found' } + }) + : route.fallback() + ) + await page.route('**/oauth/authorize?**', (route) => + route.request().resourceType() === 'document' + ? route.fallback() + : route.fulfill({ status: 200, json: CONSENT_CHALLENGE }) + ) + + await page.goto( + `${APP_URL}/cloud/login?oauth_request_id=${OAUTH_REQUEST_ID}` + ) + await page.getByRole('button', { name: SSO_COPY.continueWithSso }).click() + await page.locator('#cloud-sso-email').fill(SSO_EMAIL) + await page + .getByRole('button', { name: SSO_COPY.submit, exact: true }) + .click() + + await expect( + page.getByRole('heading', { + name: enMessages.oauth.consent.title.replace( + '{client}', + CONSENT_CHALLENGE.client_display_name + ) + }) + ).toBeVisible() + expect(new URL(page.url()).searchParams.get('oauth_request_id')).toBe( + OAUTH_REQUEST_ID + ) + }) + test('an email that does not use SSO stays on the login page with the not-SSO message', async ({ page, ssoStarts diff --git a/src/platform/auth/sso/ssoReturnPath.test.ts b/src/platform/auth/sso/ssoReturnPath.test.ts new file mode 100644 index 00000000000..8b2df57e957 --- /dev/null +++ b/src/platform/auth/sso/ssoReturnPath.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it } from 'vitest' + +import { toSsoReturnPath } from '@/platform/auth/sso/ssoReturnPath' + +describe('toSsoReturnPath', () => { + it.for([ + { + name: 'the SPA-only consent path', + input: '/oauth/consent?oauth_request_id=req-1', + expected: '/cloud/oauth/consent?oauth_request_id=req-1' + }, + { + name: 'the consent path with a trailing slash', + input: '/oauth/consent/?oauth_request_id=req-1', + expected: '/cloud/oauth/consent?oauth_request_id=req-1' + }, + { + name: 'the served consent path', + input: '/cloud/oauth/consent?oauth_request_id=req-1', + expected: '/cloud/oauth/consent?oauth_request_id=req-1' + }, + { + name: 'any other app path', + input: '/workflows?id=7#top', + expected: '/workflows?id=7#top' + }, + { + name: 'a path that only starts like the consent path', + input: '/oauth/consent-help', + expected: '/oauth/consent-help' + } + ])('returns $expected for $name', ({ input, expected }) => { + expect(toSsoReturnPath(input)).toBe(expected) + }) +}) diff --git a/src/platform/auth/sso/ssoReturnPath.ts b/src/platform/auth/sso/ssoReturnPath.ts index e7435af334a..ba53e19d7ec 100644 --- a/src/platform/auth/sso/ssoReturnPath.ts +++ b/src/platform/auth/sso/ssoReturnPath.ts @@ -4,10 +4,13 @@ const SERVED_CONSENT_PATH = '/cloud/oauth/consent' /** * The path SSO's callback can land on with a full page load. The server * serves the consent page only at `/cloud/oauth/consent`, which the SPA then - * redirects; a direct `/oauth/consent` load gets a 404. + * redirects; a direct `/oauth/consent` load gets a 404. Remove together with + * that redirect route once BE-4146 serves `/oauth/consent`. */ export function toSsoReturnPath(fullPath: string): string { const url = new URL(fullPath, 'http://sso.invalid') - if (url.pathname !== SPA_ONLY_CONSENT_PATH) return fullPath + if (url.pathname.replace(/\/+$/, '') !== SPA_ONLY_CONSENT_PATH) { + return fullPath + } return `${SERVED_CONSENT_PATH}${url.search}${url.hash}` } From 4b17d9931ce3bbbef398a7fdd00f8f0643b10896 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 8 Oct 2026 12:40:32 -0400 Subject: [PATCH 2/3] test(cloud): enter the consent-return case from the app root The e2e server only serves the SPA at /, so a direct load of /cloud/login came back as a download. Start at /?oauth_request_id= (the router keeps the request id) and answer the full-page /cloud/oauth/consent load with the app, as the real server does. --- browser_tests/tests/cloudSsoSignIn.spec.ts | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/browser_tests/tests/cloudSsoSignIn.spec.ts b/browser_tests/tests/cloudSsoSignIn.spec.ts index eb2a311170b..5ddbbc78fae 100644 --- a/browser_tests/tests/cloudSsoSignIn.spec.ts +++ b/browser_tests/tests/cloudSsoSignIn.spec.ts @@ -209,25 +209,29 @@ test.describe('Cloud login SSO entry', { tag: ['@cloud', '@ui'] }, () => { headers: { location: new URL(returnTo ?? '/', APP_URL).toString() } }) }) - await page.route('**/oauth/consent**', (route) => - route.request().resourceType() === 'document' && - new URL(route.request().url()).pathname.replace(/\/+$/, '') === - '/oauth/consent' - ? route.fulfill({ - status: 404, - json: { code: 'NOT_FOUND', message: 'Not Found' } - }) - : route.fallback() - ) + // The server serves the SPA as a page only at /cloud/oauth/consent and + // answers a document load of /oauth/consent with a JSON 404. + await page.route('**/oauth/consent**', async (route) => { + const request = route.request() + if (request.resourceType() !== 'document') return route.fallback() + const path = new URL(request.url()).pathname.replace(/\/+$/, '') + if (path === '/cloud/oauth/consent') { + const app = await route.fetch({ url: `${APP_URL}/` }) + return route.fulfill({ response: app }) + } + return route.fulfill({ + status: 404, + json: { code: 'NOT_FOUND', message: 'Not Found' } + }) + }) await page.route('**/oauth/authorize?**', (route) => route.request().resourceType() === 'document' ? route.fallback() : route.fulfill({ status: 200, json: CONSENT_CHALLENGE }) ) - await page.goto( - `${APP_URL}/cloud/login?oauth_request_id=${OAUTH_REQUEST_ID}` - ) + await page.goto(`${APP_URL}/?oauth_request_id=${OAUTH_REQUEST_ID}`) + await expect(page).toHaveURL(/\/cloud\/login/) await page.getByRole('button', { name: SSO_COPY.continueWithSso }).click() await page.locator('#cloud-sso-email').fill(SSO_EMAIL) await page From d758f252f66d1193ceadaab907c6c78fed5ad3fa Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Thu, 8 Oct 2026 13:23:26 -0400 Subject: [PATCH 3/3] test(cloud): end the mocked IdP round trip with a navigation, not a 302 Playwright does not route requests that follow a redirect, so the 302 from the mocked SSO start reached the e2e server's real 404 for /cloud/oauth/consent. Answer SSO start with a page that navigates to return_to, which the consent route then serves like the real server. --- browser_tests/tests/cloudSsoSignIn.spec.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser_tests/tests/cloudSsoSignIn.spec.ts b/browser_tests/tests/cloudSsoSignIn.spec.ts index 5ddbbc78fae..b9ce16faad2 100644 --- a/browser_tests/tests/cloudSsoSignIn.spec.ts +++ b/browser_tests/tests/cloudSsoSignIn.spec.ts @@ -204,9 +204,13 @@ test.describe('Cloud login SSO entry', { tag: ['@cloud', '@ui'] }, () => { const returnTo = new URL(route.request().url()).searchParams.get( 'return_to' ) + // Playwright does not route requests that follow a redirect, so the + // IdP round trip ends in a fresh navigation to return_to instead. + const target = new URL(returnTo ?? '/', APP_URL).toString() return route.fulfill({ - status: 302, - headers: { location: new URL(returnTo ?? '/', APP_URL).toString() } + status: 200, + contentType: 'text/html', + body: `` }) }) // The server serves the SPA as a page only at /cloud/oauth/consent and