Skip to content

Commit 8c99c22

Browse files
test(auth): cover invalid OAuth callback validation path
1 parent 1ae9393 commit 8c99c22

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

modules/auth/controllers/auth.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ const oauthCall = (req, res, next) => {
109109

110110
/**
111111
* @desc Endpoint to save oAuthProfile
112-
* @param {Object} req - Express request object
113-
* @param {Object} providerUserProfile
114-
* @param {Function} done - done
112+
* @param {Object} profil - OAuth user profile object
113+
* @param {string} key - Provider key to lookup `providerData`
114+
* @param {string} provider - OAuth provider name
115115
*/
116116
const checkOAuthUserProfile = async (profil, key, provider) => {
117117
// check if user exist

modules/auth/tests/auth.integration.tests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,24 @@ describe('Auth integration tests:', () => {
550550
}
551551
});
552552

553+
test('should return 422 when client-side OAuth callback receives an invalid profile', async () => {
554+
const result = await agent
555+
.post('/api/auth/google/callback')
556+
.send({
557+
strategy: false,
558+
key: 'id',
559+
value: 'cb-app-auth-id-invalid-999',
560+
firstName: '',
561+
lastName: 'Callback',
562+
email: 'oauthcb-invalid@test.com',
563+
})
564+
.expect(422);
565+
566+
expect(result.body.type).toBe('error');
567+
expect(result.body.message).toMatch(/^Schema validation error/);
568+
expect(result.body.description).toEqual(expect.any(String));
569+
});
570+
553571
test('should set tokenCookieOptions and redirect on classic web oAuth success', async () => {
554572
const mockUserId = 'mock-oauth-user-id-123';
555573
const authenticateSpy = jest.spyOn(passport, 'authenticate').mockImplementationOnce(

0 commit comments

Comments
 (0)