shrink token.test.ts

This commit is contained in:
Olivier Chafik 2025-06-18 12:07:38 +01:00
commit 6a01d0d4a5
No known key found for this signature in database
2 changed files with 1 additions and 69 deletions

View file

@ -93,7 +93,7 @@ export async function auth(
{ serverUrl,
authorizationCode,
scope,
resourceMetadataUrl,
resourceMetadataUrl
}: {
serverUrl: string | URL;
authorizationCode?: string;

View file

@ -307,74 +307,6 @@ describe('Token Handler', () => {
);
});
it('rejects invalid resource parameter (non-URL)', async () => {
const response = await supertest(app)
.post('/token')
.type('form')
.send({
client_id: 'valid-client',
client_secret: 'valid-secret',
grant_type: 'authorization_code',
code: 'valid_code',
code_verifier: 'valid_verifier',
resource: 'not-a-url'
});
expect(response.status).toBe(400);
expect(response.body.error).toBe('invalid_request');
expect(response.body.error_description).toContain('resource');
});
it('handles authorization code exchange without resource parameter', async () => {
const mockExchangeCode = jest.spyOn(mockProvider, 'exchangeAuthorizationCode');
const response = await supertest(app)
.post('/token')
.type('form')
.send({
client_id: 'valid-client',
client_secret: 'valid-secret',
grant_type: 'authorization_code',
code: 'valid_code',
code_verifier: 'valid_verifier'
});
expect(response.status).toBe(200);
expect(mockExchangeCode).toHaveBeenCalledWith(
validClient,
'valid_code',
undefined, // code_verifier is undefined after PKCE validation
undefined, // redirect_uri
undefined // resource parameter
);
});
it('passes resource with redirect_uri', async () => {
const mockExchangeCode = jest.spyOn(mockProvider, 'exchangeAuthorizationCode');
const response = await supertest(app)
.post('/token')
.type('form')
.send({
client_id: 'valid-client',
client_secret: 'valid-secret',
grant_type: 'authorization_code',
code: 'valid_code',
code_verifier: 'valid_verifier',
redirect_uri: 'https://example.com/callback',
resource: 'https://api.example.com/resource'
});
expect(response.status).toBe(200);
expect(mockExchangeCode).toHaveBeenCalledWith(
validClient,
'valid_code',
undefined, // code_verifier is undefined after PKCE validation
'https://example.com/callback', // redirect_uri
new URL('https://api.example.com/resource') // resource parameter
);
});
it('passes through code verifier when using proxy provider', async () => {
const originalFetch = global.fetch;