Stabilize U
This commit is contained in:
142
src/Web/StellaOps.Web/e2e/fixtures/auth.fixture.ts
Normal file
142
src/Web/StellaOps.Web/e2e/fixtures/auth.fixture.ts
Normal file
@@ -0,0 +1,142 @@
|
||||
import { test as base, expect, Page } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* StubAuthSession shape matches src/app/testing/auth-fixtures.ts.
|
||||
* The Angular APP_INITIALIZER in app.config.ts reads
|
||||
* `window.__stellaopsTestSession` and calls seedAuthSession() to
|
||||
* populate the AuthSessionStore before guards execute.
|
||||
*/
|
||||
interface StubAuthSession {
|
||||
subjectId: string;
|
||||
tenant: string;
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
/** Admin session with all major scopes for unrestricted route access. */
|
||||
const adminTestSession: StubAuthSession = {
|
||||
subjectId: 'e2e-admin-user',
|
||||
tenant: 'tenant-default',
|
||||
scopes: [
|
||||
'admin',
|
||||
'ui.read',
|
||||
'ui.admin',
|
||||
'orch:read',
|
||||
'orch:operate',
|
||||
'orch:quota',
|
||||
'orch:backfill',
|
||||
'policy:read',
|
||||
'policy:write',
|
||||
'policy:author',
|
||||
'policy:review',
|
||||
'policy:approve',
|
||||
'policy:operate',
|
||||
'policy:simulate',
|
||||
'policy:audit',
|
||||
'exception:read',
|
||||
'exception:write',
|
||||
'exception:approve',
|
||||
'release:read',
|
||||
'release:write',
|
||||
'release:publish',
|
||||
'analytics.read',
|
||||
'graph:read',
|
||||
'graph:write',
|
||||
'graph:admin',
|
||||
'sbom:read',
|
||||
'sbom:write',
|
||||
'scanner:read',
|
||||
'vex:read',
|
||||
'vex:export',
|
||||
'advisory:read',
|
||||
'scheduler:read',
|
||||
'scheduler:operate',
|
||||
'findings:read',
|
||||
'exceptions:read',
|
||||
],
|
||||
};
|
||||
|
||||
export const test = base.extend<{ authenticatedPage: Page }>({
|
||||
authenticatedPage: async ({ page }, use) => {
|
||||
// Intercept branding endpoint that can return 500 in dev/Docker
|
||||
await page.route('**/console/branding**', (route) => {
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
tenantId: 'tenant-default',
|
||||
productName: 'Stella Ops',
|
||||
logoUrl: null,
|
||||
theme: 'default',
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
// Intercept OIDC authorize to prevent redirect loops
|
||||
await page.route('**/connect/authorize**', (route) => {
|
||||
route.fulfill({ status: 200, body: '' });
|
||||
});
|
||||
|
||||
// Intercept console profile/introspect calls that fire after session seed
|
||||
await page.route('**/console/profile**', (route) => {
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
subjectId: adminTestSession.subjectId,
|
||||
username: 'qa-tester',
|
||||
displayName: 'QA Test User',
|
||||
tenant: adminTestSession.tenant,
|
||||
roles: ['admin'],
|
||||
scopes: adminTestSession.scopes,
|
||||
audiences: ['stellaops'],
|
||||
authenticationMethods: ['pwd'],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/console/token/introspect**', (route) => {
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
active: true,
|
||||
tenant: adminTestSession.tenant,
|
||||
subject: adminTestSession.subjectId,
|
||||
clientId: 'stellaops-console',
|
||||
scopes: adminTestSession.scopes,
|
||||
audiences: ['stellaops'],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/console/tenants**', (route) => {
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
tenants: [
|
||||
{
|
||||
id: adminTestSession.tenant,
|
||||
displayName: 'Default Tenant',
|
||||
status: 'active',
|
||||
isolationMode: 'shared',
|
||||
defaultRoles: ['admin'],
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
// Inject test session via addInitScript so it is available
|
||||
// before any Angular code runs (APP_INITIALIZER reads it).
|
||||
await page.addInitScript((session: StubAuthSession) => {
|
||||
(window as any).__stellaopsTestSession = session;
|
||||
}, adminTestSession);
|
||||
|
||||
await use(page);
|
||||
},
|
||||
});
|
||||
|
||||
export { expect } from '@playwright/test';
|
||||
export { adminTestSession };
|
||||
export type { StubAuthSession };
|
||||
Reference in New Issue
Block a user