-
-
Notifications
You must be signed in to change notification settings - Fork 10
chore: audit polish — migration test scoping, dead fallback, OAuth guard test, failure counters #3960
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
Merged
Merged
chore: audit polish — migration test scoping, dead fallback, OAuth guard test, failure counters #3960
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
modules/auth/tests/auth.oauthCall.realPassportGuard.unit.tests.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /** | ||
| * Module dependencies. | ||
| */ | ||
| import { jest, describe, test, expect } from '@jest/globals'; | ||
| import { setupAuthControllerMocks } from './fixtures/auth-controller.mock-setup.js'; | ||
|
|
||
| /** | ||
| * Regression guard (issue #3954): every test in auth.oauthCall.controller.unit.tests.js | ||
| * replaces `passport` wholesale via `jest.unstable_mockModule` and stubs `_strategy` as | ||
| * a `jest.fn()` — so if a future passport upgrade renames or removes the private | ||
| * `_strategy` API that isEnabledOAuthProvider() relies on (see auth.controller.js), none | ||
| * of those mocks would notice; production would silently 404 every OAuth login while | ||
| * that whole suite kept passing green. | ||
| * | ||
| * This test uses the REAL `passport` package, registers a trivial strategy via the real | ||
| * `passport.use()`, and asserts the guard recognizes it through the real `_strategy` | ||
| * lookup (only `passport.authenticate` itself is stubbed, since the trivial strategy's | ||
| * `authenticate()` is never meant to run a full handshake). | ||
| * | ||
| * Deliberately kept in its OWN file rather than added to | ||
| * auth.oauthCall.controller.unit.tests.js: `jest.unstable_mockModule('passport', ...)` | ||
| * mock-factory registrations are sticky for the lifetime of a test FILE — they survive | ||
| * `jest.resetModules()` — so a real-passport test placed after any mocked-passport test | ||
| * in the same file would still resolve `import('passport')` to the stale mock. A | ||
| * dedicated file gives this test a clean module registry with no prior passport mock. | ||
| */ | ||
| describe('auth.controller oauthCall — isEnabledOAuthProvider against a REAL passport strategy:', () => { | ||
| test('a strategy registered via the real passport.use() is recognized by the guard and delegated to', async () => { | ||
| setupAuthControllerMocks({ realPassport: true }); | ||
|
|
||
| const { default: passport } = await import('passport'); | ||
|
|
||
| class TrivialStrategy { | ||
| constructor(name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| // Never actually invoked in this test — passport.authenticate() is stubbed | ||
| // below, so the guard-focused assertions never reach a real handshake. | ||
| authenticate() { | ||
| this.fail({ message: 'trivial strategy stub — not exercised by this guard test' }); | ||
| } | ||
| } | ||
| passport.use(new TrivialStrategy('google')); | ||
| const authenticateMiddleware = jest.fn(); | ||
| jest.spyOn(passport, 'authenticate').mockReturnValue(authenticateMiddleware); | ||
|
|
||
| const { default: AuthController } = await import('../../../modules/auth/controllers/auth.controller.js'); | ||
|
|
||
| const req = { params: { strategy: 'google' } }; | ||
| const res = {}; | ||
| const next = jest.fn(); | ||
|
|
||
| AuthController.oauthCall(req, res, next); | ||
|
|
||
| expect(passport.authenticate).toHaveBeenCalledWith('google', { session: false }); | ||
| expect(authenticateMiddleware).toHaveBeenCalledWith(req, res, next); | ||
| expect(next).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.