diff --git a/frontend/src/routes/interaction/+page.ts b/frontend/src/routes/interaction/+page.ts index b80ab00c..aa34ccdf 100644 --- a/frontend/src/routes/interaction/+page.ts +++ b/frontend/src/routes/interaction/+page.ts @@ -1,16 +1,23 @@ import OidcService from '$lib/services/oidc-service'; -import { error } from '@sveltejs/kit'; +import { getAxiosErrorMessage } from '$lib/utils/error-util'; +import { redirect } from '@sveltejs/kit'; import type { PageLoad } from './$types'; export const load: PageLoad = async ({ url }) => { const interactionSessionId = url.searchParams.get('interaction'); if (!interactionSessionId) { - error(400, 'Missing authorize interaction'); + return redirectToError('Missing authorize interaction'); } const oidcService = new OidcService(); - const interactionSession = await oidcService.getAuthorizeInteraction(interactionSessionId); + const interactionSession = await oidcService + .getAuthorizeInteraction(interactionSessionId) + .catch((e) => redirectToError(getAxiosErrorMessage(e))); return { interactionSession }; }; + +function redirectToError(errorMessage: string): never { + redirect(302, `/interaction/error?${new URLSearchParams({ error: errorMessage }).toString()}`); +} diff --git a/tests/specs/oidc.spec.ts b/tests/specs/oidc.spec.ts index ecd32619..cfa99656 100644 --- a/tests/specs/oidc.spec.ts +++ b/tests/specs/oidc.spec.ts @@ -193,6 +193,21 @@ test('Authorize new client shows Pocket ID error when user group not allowed', a ).toBeVisible(); }); +test('Unknown authorize interaction shows the interaction error page', async ({ + page +}, testInfo) => { + const relyingPartyUrl = new URL('/client-return', testInfo.project.use.baseURL).toString(); + await page.goto(`/interaction?interaction=${crypto.randomUUID()}`, { referer: relyingPartyUrl }); + + await expect(page).toHaveURL(/\/interaction\/error\?error=/); + await expect(page.getByRole('heading', { name: 'Error' })).toBeVisible(); + await expect(page.getByText('OIDC interaction not found or expired')).toBeVisible(); + await expect(page.getByRole('link', { name: 'Go back' })).toHaveAttribute( + 'href', + relyingPartyUrl + ); +}); + function createUrlParams(oidcClient: { id: string; callbackUrl: string }) { return new URLSearchParams({ client_id: oidcClient.id,