-
Notifications
You must be signed in to change notification settings - Fork 78
feat(FR-2594): add E2E test for SSO sToken login flow #6758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nowgnuesLee
wants to merge
1
commit into
main
Choose a base branch
from
04-16-feat_fr-2594_add_e2e_test_for_sso_stoken_login_flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−8
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // cspell:words STOKEN sToken | ||
| /** | ||
| * E2E tests for sToken-based SSO login at the root URL. | ||
| * | ||
| * Regression coverage for FR-2574 (PR #6693), which fixed three bugs that | ||
| * prevented `/?sToken=...` SSO from working: | ||
| * | ||
| * 1. Race in `useLoginOrchestration`: the orchestration effect fired | ||
| * when `isConfigLoaded` became true but before `apiEndpoint` was | ||
| * hydrated, so `connectUsingSession` bailed out on an empty endpoint | ||
| * before reaching the sToken check. | ||
| * 2. `LoginView` did `window.location.href = '/'` after `tokenLogin`, | ||
| * which dropped the sToken query param and broke the second load. | ||
| * 3. `token_login()` in `backend.ai-client-esm.ts` didn't persist | ||
| * `_loginSessionId` to localStorage, so the session was lost on | ||
| * refresh and `check_login()` returned false. | ||
| * | ||
| * Backend prerequisites | ||
| * --------------------- | ||
| * The sToken used below is signed with HS256 against a keypair that the | ||
| * target Backend.AI Manager must have provisioned. For the test to pass, | ||
| * the target Manager must: | ||
| * | ||
| * - Have the `auth-keypair` plugin enabled. | ||
| * - Have the keypair used to sign `E2E_STOKEN_JWT` provisioned and active. | ||
| * - Use a JWT secret that validates `E2E_STOKEN_JWT`. | ||
| * | ||
| * Because these preconditions do not hold in default CI or local | ||
| * environments, this suite is opt-in. Set `E2E_ENABLE_STOKEN_SSO=true` | ||
| * together with `E2E_STOKEN_JWT` and (optionally) `E2E_STOKEN_API_ENDPOINT` | ||
| * to run it. | ||
| */ | ||
| import { | ||
| modifyConfigToml, | ||
| webServerEndpoint, | ||
| webuiEndpoint, | ||
| } from '../utils/test-util'; | ||
| import { test, expect } from '@playwright/test'; | ||
|
|
||
| /** | ||
| * Opt-in guard: this suite requires a very specific Backend.AI Manager | ||
| * setup (auth-keypair plugin + pre-provisioned keypair + matching JWT | ||
| * secret), so keep it disabled by default to avoid failing standard CI | ||
| * runs. Set `E2E_ENABLE_STOKEN_SSO=true` to run it intentionally. | ||
| */ | ||
| const IS_STOKEN_SSO_E2E_ENABLED = process.env.E2E_ENABLE_STOKEN_SSO === 'true'; | ||
|
|
||
| /** | ||
| * sToken JWT used for the test. Sourced from the environment so no | ||
| * credential-shaped material needs to live in the repository. The token | ||
| * must be signed with the Manager's JWT secret and encode an access/ | ||
| * secret key pair that the `auth-keypair` plugin accepts. | ||
| */ | ||
| const STATIC_S_TOKEN = process.env.E2E_STOKEN_JWT ?? ''; | ||
|
|
||
| /** | ||
| * Backend endpoint where the auth-keypair plugin is configured and the | ||
| * matching keypair exists. Defaults to `webServerEndpoint` | ||
| * (`E2E_WEBSERVER_ENDPOINT`) so local runs work out of the box; override | ||
| * with `E2E_STOKEN_API_ENDPOINT` to point at a different backend. | ||
| */ | ||
| const S_TOKEN_API_ENDPOINT = | ||
| process.env.E2E_STOKEN_API_ENDPOINT || webServerEndpoint; | ||
|
|
||
| test.describe( | ||
| 'sToken SSO login at root URL (FR-2574)', | ||
| { | ||
| tag: ['@critical', '@auth', '@functional', '@requires-auth-keypair-plugin'], | ||
| }, | ||
| () => { | ||
|
nowgnuesLee marked this conversation as resolved.
|
||
| test.skip( | ||
| !IS_STOKEN_SSO_E2E_ENABLED || !STATIC_S_TOKEN, | ||
| 'Requires auth-keypair-enabled Backend.AI Manager with a pre-provisioned keypair and matching JWT secret. Set E2E_ENABLE_STOKEN_SSO=true and E2E_STOKEN_JWT=<signed token> to run this suite intentionally.', | ||
| ); | ||
|
|
||
| test.beforeEach(async ({ page, request }) => { | ||
| // Pre-populate apiEndpoint in config.toml so the WebUI does not | ||
| // require manual endpoint input. This is the precondition the | ||
| // PR #6693 fix relies on: orchestration only runs once both | ||
| // `isConfigLoaded` and `apiEndpoint` are non-empty, then it | ||
| // inspects the sToken in the URL and calls `tokenLogin`. | ||
| await modifyConfigToml(page, request, { | ||
| general: { | ||
| connectionMode: 'SESSION', | ||
| apiEndpoint: S_TOKEN_API_ENDPOINT, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| test('auto-logs in and strips sToken from URL when navigating to /?sToken=<token>', async ({ | ||
| page, | ||
| }) => { | ||
| await page.goto(`${webuiEndpoint}/?sToken=${STATIC_S_TOKEN}`); | ||
|
|
||
| // Success gate: orchestration must call `tokenLogin`, succeed, | ||
| // and dispatch the post-connect setup that lands the user on the | ||
| // start page. 15s accounts for config fetch + tokenLogin + GQL | ||
| // connect + React Router redirect. | ||
| await expect(page).toHaveURL(/\/start/, { timeout: 15_000 }); | ||
|
|
||
| // Bug 2 regression: after `tokenLogin`, `LoginView` calls | ||
| // `history.replaceState({}, '', '/')` instead of a full reload, | ||
| // so the sToken query parameter must be gone from the URL. | ||
| expect(page.url()).not.toContain('sToken'); | ||
|
|
||
| // The login form must NOT remain visible: orchestration should | ||
| // have detected the sToken and completed the silent login, | ||
| // bypassing manual entry entirely. | ||
| await expect(page.getByLabel('Email or Username')).toBeHidden(); | ||
|
|
||
| // Final confirmation that the user landed on an authenticated | ||
| // page and the start view rendered. | ||
| await expect( | ||
| page.getByTestId('webui-breadcrumb').getByText('Start'), | ||
| ).toBeVisible(); | ||
| }); | ||
|
nowgnuesLee marked this conversation as resolved.
|
||
|
|
||
| test('persists session after page refresh', async ({ page }) => { | ||
| // Establish the session via sToken auto-login first. | ||
| await page.goto(`${webuiEndpoint}/?sToken=${STATIC_S_TOKEN}`); | ||
| await expect(page).toHaveURL(/\/start/, { timeout: 15_000 }); | ||
| await expect( | ||
| page.getByTestId('webui-breadcrumb').getByText('Start'), | ||
| ).toBeVisible(); | ||
|
|
||
| // Refresh the page. Bug 3 regression: without the | ||
| // `localStorage.setItem('backendaiwebui.sessionid', ...)` fix in | ||
| // `token_login()`, the session id would not be persisted, so | ||
| // `check_login()` would return false on reload and the user | ||
| // would be dropped back to the login form. | ||
| await page.reload(); | ||
|
|
||
| // The login form must NOT reappear after the refresh. | ||
| await expect(page.getByLabel('Email or Username')).toBeHidden(); | ||
| // The user should still be on the start page with an active session. | ||
| await expect( | ||
| page.getByTestId('webui-breadcrumb').getByText('Start'), | ||
| ).toBeVisible(); | ||
| }); | ||
| }, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.