Skip to content

Commit 5d310d4

Browse files
committed
test(oidc-client): cover dispatchAuthorizeµ error branches via authorize.background()
1 parent 56cada9 commit 5d310d4

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

packages/oidc-client/src/lib/client.store.test.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,87 @@ describe('authorize.url() with PAR enabled', async () => {
400400
});
401401
});
402402

403+
describe('authorize.background() dispatch error branches', async () => {
404+
const standardConfig: OidcConfig = {
405+
clientId: '123456789',
406+
redirectUri: 'https://example.com/callback.html',
407+
scope: 'openid profile',
408+
serverConfig: {
409+
wellknown: 'https://api.example.com/wellknown',
410+
},
411+
responseType: 'code',
412+
};
413+
414+
beforeEach(() => {
415+
customStorage.remove(storageKey);
416+
});
417+
418+
it('surfaces CONFIGURATION_ERROR without a redirectUrl', async () => {
419+
server.use(
420+
http.post('*/as/authorize', async () =>
421+
HttpResponse.json(
422+
{ error: 'invalid_request', error_description: 'misconfigured client' },
423+
{ status: 400 },
424+
),
425+
),
426+
);
427+
428+
const oidcClient = await oidc({ config: standardConfig, storage: customStorageConfig });
429+
if ('error' in oidcClient) throw new Error('Error creating OIDC Client');
430+
431+
const result = await oidcClient.authorize.background();
432+
if (!('error' in result)) expect.fail('Expected error, got success');
433+
434+
expect(result.error).toBe('CONFIGURATION_ERROR');
435+
expect(result.type).toBe('network_error');
436+
expect('redirectUrl' in result).toBe(false);
437+
});
438+
439+
it('builds redirectUrl for non-configuration authorize errors (details array)', async () => {
440+
server.use(
441+
http.post('*/as/authorize', async () =>
442+
HttpResponse.json(
443+
{
444+
details: [{ code: 'access_denied', message: 'user denied consent' }],
445+
},
446+
{ status: 403 },
447+
),
448+
),
449+
);
450+
451+
const oidcClient = await oidc({ config: standardConfig, storage: customStorageConfig });
452+
if ('error' in oidcClient) throw new Error('Error creating OIDC Client');
453+
454+
const result = await oidcClient.authorize.background();
455+
if (!('error' in result)) expect.fail('Expected error, got success');
456+
457+
expect(result.error).toBe('access_denied');
458+
expect(result.type).toBe('auth_error');
459+
expect('redirectUrl' in result).toBe(true);
460+
if ('redirectUrl' in result) {
461+
expect(typeof result.redirectUrl).toBe('string');
462+
expect(result.redirectUrl).toContain('authorize');
463+
}
464+
});
465+
466+
it('returns Unknown_Error when authorize response body lacks authorizeResponse', async () => {
467+
server.use(
468+
http.post('*/as/authorize', async () =>
469+
HttpResponse.json({ unexpected: 'shape' }, { status: 200 }),
470+
),
471+
);
472+
473+
const oidcClient = await oidc({ config: standardConfig, storage: customStorageConfig });
474+
if ('error' in oidcClient) throw new Error('Error creating OIDC Client');
475+
476+
const result = await oidcClient.authorize.background();
477+
if (!('error' in result)) expect.fail('Expected error, got success');
478+
479+
expect(result.error).toBe('Unknown_Error');
480+
expect(result.type).toBe('unknown_error');
481+
});
482+
});
483+
403484
describe('PAR factory validation', async () => {
404485
it('returns argument_error when wellknown requires PAR but config.par is explicitly false', async () => {
405486
server.use(

0 commit comments

Comments
 (0)