Skip to content
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 modules/auth/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ const checkOAuthUserProfile = async (profil, key, provider) => {
const oauthCallback = async (req, res, next) => {
const strategy = req.params.strategy;
// app Auth with Strategy managed on client side
if (req.body.strategy === false && req.body.key) {
if (req.body?.strategy === false && req.body?.key) {
const allowedKeys = ['id', 'sub', 'email'];
if (!allowedKeys.includes(req.body.key)) {
return responses.error(res, 422, 'Unprocessable Entity', 'Invalid provider key')();
Expand Down
19 changes: 19 additions & 0 deletions modules/auth/tests/auth.integration.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,25 @@ describe('Auth integration tests:', () => {
authenticateSpy.mockRestore();
});

test('should handle GET callback when req.body is undefined (Express 5)', async () => {
const authenticateSpy = jest.spyOn(passport, 'authenticate').mockImplementationOnce(
(strategy, callback) => () => callback(null, { id: 'mock-get-cb-user' }),
);
const cookies = {};
const redirectCalls = [];
const mockReq = { params: { strategy: 'google' } };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ LOW RISK

Nitpick: This test boilerplate for mocking the response object and tracking redirects is duplicated from lines 613-622. Extracting this into a shared helper function would simplify the test suite.

Try running the following prompt in your IDE agent:

Refactor the integration tests in modules/auth/tests/auth.integration.tests.js by creating a setupMockAuthResponse helper function that returns the cookies, redirectCalls, and mockRes object. Then, update the tests at lines 613 and 635 to use this helper.

const mockRes = {
cookie(name, val, opts) { cookies[name] = { val, opts }; return this; },
redirect(code, url) { redirectCalls.push({ code, url }); },
};

await AuthController.oauthCallback(mockReq, mockRes, () => {});

expect(cookies.TOKEN).toBeDefined();
expect(redirectCalls[0]).toMatchObject({ code: 302 });
authenticateSpy.mockRestore();
});
Comment on lines +630 to +646

test('should find an existing OAuth user via checkOAuthUserProfile', async () => {
// Create an OAuth user directly first
const createdUser = await UserService.create({
Expand Down
Loading