Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add tests for content-type in oidc apis #6380

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/oidc/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
// Temporarily removed 'EdDSA' since it's not supported by browser yet
const supportedSigningAlgs = Object.freeze(['RS256', 'PS256', 'ES256', 'ES384', 'ES512'] as const);

export default function initOidc(

Check warning on line 61 in packages/core/src/oidc/init.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/oidc/init.ts#L61

[max-params] Function 'initOidc' has too many parameters (5). Maximum allowed is 4.
envSet: EnvSet,
queries: Queries,
libraries: Libraries,
Expand Down Expand Up @@ -403,7 +403,7 @@
// eslint-disable-next-line no-restricted-syntax
ctx.request.body = trySafe(() => JSON.parse(body) as unknown);
} else if (ctx.is(formUrlEncodedContentType)) {
ctx.request.body = trySafe(() => querystring.parse(body));
ctx.request.body = querystring.parse(body);

Check warning on line 406 in packages/core/src/oidc/init.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/oidc/init.ts#L406

Added line #L406 was not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,39 @@ describe('content-type: application/json compatibility', () => {
{ 'content-type': 'application/json1' }
);
});

it('should be ok when `content-type` is json but the body is malformed', async () => {
await trySafe(
api
.post('token', {
headers: {
'content-type': 'application/json',
},
body: 'this is not a json',
})
.json(),
async (error) => {
if (!(error instanceof HTTPError)) {
throw new TypeError('Error is not a HTTPError instance.');
}

// 400 means the request has been processed, we just need to ensure no 500 error
expect(error.response.status).toBe(400);
expect(await error.response.json()).toHaveProperty(
'error_description',
'no client authentication mechanism provided'
);
}
);
});

it('should be ok when `content-type` is json for GET requests', async () => {
await expect(
api.get('.well-known/openid-configuration', {
headers: {
'content-type': 'application/json',
},
})
).resolves.toBeDefined();
});
});
Loading