Skip to content

Commit 63a2f69

Browse files
committed
IS-10102 Make "initialUrl" required on LWA bootstrap
1 parent 784d1ca commit 63a2f69

7 files changed

Lines changed: 36 additions & 66 deletions

File tree

src/login-web-app/.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/login-web-app/index.html

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,28 @@
1818
</head>
1919
<body>
2020
<script>
21-
function arg(name, required) {
22-
if (required === undefined) {
23-
required = true;
24-
}
25-
21+
function arg(name) {
2622
const args = new URL(window.location.href).searchParams;
2723
const value = args.get(name);
2824
if (value) {
2925
return value;
3026
}
31-
32-
if (required) {
33-
throw new Error(`Missing argument '${name}'`);
34-
}
27+
throw new Error(`Missing argument '${name}'`);
3528
}
3629

37-
const originalUrl = arg('originalUrl');
38-
const haapi = {
39-
clientId: arg('haapi_clientId'),
40-
tokenEndpoint: arg('haapi_tokenEndpoint'),
30+
// Set the configuration object expected by the application
31+
window.__CONFIG__ = {
32+
initialUrl: arg('initialUrl'),
33+
haapi: {
34+
clientId: arg('haapi_clientId'),
35+
tokenEndpoint: arg('haapi_tokenEndpoint'),
36+
},
4137
};
4238

4339
// Change the current URL to match the original request to Identity Server, so that it looks like the
4440
// application was loaded directly by the server's template
41+
const originalUrl = arg('originalUrl');
4542
window.history.replaceState(undefined, '', originalUrl);
46-
// Set the configuration object expected by the application
47-
window.__CONFIG__ = {
48-
initialUrl: arg('initialUrl', false),
49-
haapi,
50-
};
5143
</script>
5244
<div id="root"></div>
5345
<script type="module" src="/src/main.tsx"></script>

src/login-web-app/loader-dev.vm.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
<script>
2121
const query = new URLSearchParams({
2222
originalUrl: window.location.href,
23+
initialUrl: '$_apiDrivenInitialUrl',
2324
haapi_clientId: '$_apiDrivenClientInfo.clientId',
2425
haapi_tokenEndpoint: '$_apiDrivenClientInfo.tokenEndpoint',
2526
});
26-
#if ($_apiDrivenInitialUrl)
27-
query.append('initialUrl', '$_apiDrivenInitialUrl');
28-
#end
2927

3028
const redirect = new URL('/', window.location.href);
3129
redirect.search = query.toString();

src/login-web-app/loader.vm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<body>
2020
<script>
2121
window.__CONFIG__ = {
22-
initialUrl: #if ($_apiDrivenInitialUrl) '$_apiDrivenInitialUrl' #else undefined #end,
22+
initialUrl: '$_apiDrivenInitialUrl',
2323
haapi: {
2424
clientId: '$_apiDrivenClientInfo.clientId',
2525
tokenEndpoint: '$_apiDrivenClientInfo.tokenEndpoint',

src/login-web-app/src/haapi-stepper/data-access/bootstrap-configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HaapiConfiguration } from '@curity/identityserver-haapi-web-driver';
22

33
export interface BootstrapConfiguration {
4-
initialUrl?: string;
4+
initialUrl: string;
55
haapi: HaapiConfiguration;
66
}
77

src/login-web-app/src/haapi-stepper/feature/stepper/HaapiStepper.spec.tsx

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@ import { HaapiStepperActionStep, HaapiStepperFormAction } from './haapi-stepper.
3131
import type { BootstrapConfiguration } from '../../data-access/bootstrap-configuration';
3232

3333
describe('HaapiStepper', () => {
34-
const initializationHref = 'https://example.com/auth';
3534
const initialStepType = HAAPI_STEPS.AUTHENTICATION;
3635

3736
beforeEach(() => {
3837
vi.clearAllMocks();
39-
vi.stubGlobal('location', {
40-
href: initializationHref,
41-
});
4238
mockHaapiFetchStep(initialStepType);
4339
});
4440

@@ -48,41 +44,20 @@ describe('HaapiStepper', () => {
4844
});
4945

5046
describe('Steps', () => {
51-
describe('initialization', () => {
52-
afterEach(() => {
53-
delete mockConfiguration.initialUrl;
54-
});
55-
56-
it('should initialize the first step with the current location and render the children', async () => {
57-
render(
58-
<HaapiStepper>
59-
<TestComponent />
60-
</HaapiStepper>
61-
);
62-
63-
expect(mockHaapiFetch).toHaveBeenCalledWith(initializationHref, { method: 'GET' });
64-
65-
const stepRendered = await screen.findByTestId('step-type');
66-
67-
expect(stepRendered).toHaveTextContent(initialStepType);
68-
expect(screen.queryByTestId('loading')).not.toBeInTheDocument();
69-
expect(screen.queryByTestId('error')).not.toBeInTheDocument();
70-
});
47+
it('should initialize the first step with the bootstrap initial URL and render the children', async () => {
48+
render(
49+
<HaapiStepper>
50+
<TestComponent />
51+
</HaapiStepper>
52+
);
7153

72-
it('should initialize the first step with the bootstrap initial URL', async () => {
73-
const initialUrl = 'https://example.com/other';
74-
mockConfiguration.initialUrl = initialUrl;
54+
expect(mockHaapiFetch).toHaveBeenCalledWith(mockConfiguration.initialUrl, { method: 'GET' });
7555

76-
render(
77-
<HaapiStepper>
78-
<TestComponent />
79-
</HaapiStepper>
80-
);
56+
const stepRendered = await screen.findByTestId('step-type');
8157

82-
await waitFor(() => {
83-
expect(mockHaapiFetch).toHaveBeenCalledWith(initialUrl, { method: 'GET' });
84-
});
85-
});
58+
expect(stepRendered).toHaveTextContent(initialStepType);
59+
expect(screen.queryByTestId('loading')).not.toBeInTheDocument();
60+
expect(screen.queryByTestId('error')).not.toBeInTheDocument();
8661
});
8762

8863
it('should go to the next step and provide the updated current step', async () => {
@@ -384,7 +359,7 @@ describe('HaapiStepper', () => {
384359
await goToNextStep(HAAPI_STEPS.POLLING, { bankId: true });
385360

386361
const startButton = await screen.findByRole('button', { name: 'Start BankID' });
387-
362+
388363
act(() => startButton.click());
389364

390365
await waitFor(() => {
@@ -502,8 +477,13 @@ describe('HaapiStepper', () => {
502477

503478
expect(historyData).toHaveLength(1);
504479
expect(historyData[0].step.type).toBe(initialStep);
505-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
506-
expect(historyData[0].triggeredByAction).toEqual({ ...previousStepTriggerActionKind, id: expect.anything() });
480+
expect(historyData[0].triggeredByAction).toEqual({
481+
...previousStepTriggerActionKind,
482+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
483+
id: expect.anything(),
484+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
485+
href: expect.anything(),
486+
});
507487
expect(historyData[0].triggeredByPayload).toBeUndefined();
508488

509489
await goToNextStep(secondStep);
@@ -659,7 +639,9 @@ vi.mock('../../data-access/haapi-fetch-initializer', () => {
659639
});
660640

661641
const mockConfiguration: Partial<BootstrapConfiguration> = vi.hoisted(() => {
662-
return {};
642+
return {
643+
initialUrl: 'https://example.com/auth',
644+
};
663645
});
664646
vi.mock('../../data-access/bootstrap-configuration', () => {
665647
return {

src/login-web-app/src/haapi-stepper/feature/stepper/HaapiStepper.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,8 @@ function cancelPendingOperation(pendingOperation: RefObject<AbortController | No
442442
}
443443

444444
function getInitialStepLink() {
445-
const initialUrl = configuration.initialUrl ?? window.location.href;
446445
const initialStepLink: HaapiStepperLink = {
447-
href: initialUrl,
446+
href: configuration.initialUrl,
448447
rel: 'self',
449448
type: HAAPI_STEPPER_ELEMENT_TYPES.LINK,
450449
subtype: 'initial-link',

0 commit comments

Comments
 (0)