Commit 997c51d
authored
fix(auth): guard OAuth :strategy route — 404 unknown/disabled + stateless authenticate (#3947)
* fix(auth): guard OAuth :strategy route — 404 unknown/disabled + stateless authenticate
oauthCall and oauthCallback passed req.params.strategy straight into
passport.authenticate() with no validation: an unknown strategy made
passport throw synchronously ("Unknown authentication strategy") -> 500,
and a registered-but-unguarded provider defaulted to session:true, which
fails on this stateless JWT stack (no express-session mounted).
Add isEnabledOAuthProvider(), shared by both routes: allowlisted (in
ALLOWED_PROVIDERS) AND actually registered with passport
(passport._strategy(strategy)) -> otherwise reject with a clean 404
(OAUTH_PROVIDER_NOT_FOUND) before ever reaching passport.authenticate().
oauthCall now also passes { session: false } explicitly.
Update the invitations alias-shadow test to assert on the new deliberate
404 (code) instead of "not 404", and add strategy-registration stubs to
the existing oauthCallback integration tests so they keep exercising the
post-authenticate path. New unit tests cover unknown/disabled/enabled
strategies for oauthCall.
* test(auth): cover oauthCallback 404 guard + restore session-mint regression test
Adversarial review of the #3900 guard diff found the oauthCallback
reject branch had zero coverage (all 6 existing tests stub _strategy
truthy) and that the pre-existing "should NOT mint a session" security
regression test was silently defeated: since google is unregistered in
test config, the new guard now 404s before the request ever reaches the
post-authenticate identity-trust logic the test protects.
- Add oauthCallback guard-reject unit tests (unknown + allowlisted-but-
unregistered strategy), mirroring the existing oauthCall coverage.
- Stub passport._strategy + passport.authenticate in the session-mint
regression test so it again reaches the post-auth "no user" branch
instead of short-circuiting at the guard; assert the redirect carries
the no-user error, never OAUTH_PROVIDER_NOT_FOUND.
- Reuse the existing 'oAuth, unsupported provider' AppError message for
both new guards instead of a fresh string, for consistency.
- Add a describe-scoped afterEach(jest.restoreAllMocks()) safety net so
a failing assertion mid-test can't leak a stubbed spy into later
tests (clearMocks alone doesn't restore spy implementations).
* test(auth): extract shared oauth controller mock setup into a fixture (CodeRabbit #3947)
Deduplicates ~85 lines of identical jest.unstable_mockModule setup that was
copy-pasted across the oauthCall and oauthCallback describe blocks' beforeEach
hooks into a single setupAuthControllerMocks() helper, called from both.
Placed under tests/fixtures/ (matching lib/middlewares/tests/fixtures/) so
Jest's testPathIgnorePatterns keeps it out of testMatch — a tests/helpers/
name would have made Jest try to run it as its own (empty) test suite.1 parent 9558e22 commit 997c51d
5 files changed
Lines changed: 365 additions & 13 deletions
File tree
- modules
- auth
- controllers
- tests
- fixtures
- invitations/tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
442 | 467 | | |
443 | 468 | | |
444 | 469 | | |
| |||
447 | 472 | | |
448 | 473 | | |
449 | 474 | | |
450 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
451 | 480 | | |
452 | 481 | | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | 482 | | |
461 | 483 | | |
462 | 484 | | |
| |||
659 | 681 | | |
660 | 682 | | |
661 | 683 | | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
662 | 687 | | |
663 | 688 | | |
664 | 689 | | |
665 | 690 | | |
666 | 691 | | |
667 | | - | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
668 | 697 | | |
669 | 698 | | |
670 | 699 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
558 | 558 | | |
559 | 559 | | |
560 | 560 | | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
561 | 570 | | |
562 | 571 | | |
563 | 572 | | |
| |||
625 | 634 | | |
626 | 635 | | |
627 | 636 | | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
628 | 649 | | |
629 | 650 | | |
630 | 651 | | |
| |||
649 | 670 | | |
650 | 671 | | |
651 | 672 | | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
652 | 679 | | |
| 680 | + | |
| 681 | + | |
653 | 682 | | |
654 | 683 | | |
655 | 684 | | |
656 | 685 | | |
657 | 686 | | |
658 | 687 | | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
659 | 693 | | |
660 | 694 | | |
661 | 695 | | |
| |||
675 | 709 | | |
676 | 710 | | |
677 | 711 | | |
| 712 | + | |
678 | 713 | | |
679 | 714 | | |
680 | 715 | | |
| 716 | + | |
681 | 717 | | |
682 | 718 | | |
683 | 719 | | |
| |||
694 | 730 | | |
695 | 731 | | |
696 | 732 | | |
| 733 | + | |
697 | 734 | | |
698 | 735 | | |
699 | 736 | | |
700 | 737 | | |
701 | 738 | | |
| 739 | + | |
702 | 740 | | |
703 | 741 | | |
704 | 742 | | |
| |||
743 | 781 | | |
744 | 782 | | |
745 | 783 | | |
| 784 | + | |
746 | 785 | | |
747 | 786 | | |
748 | 787 | | |
| |||
751 | 790 | | |
752 | 791 | | |
753 | 792 | | |
| 793 | + | |
754 | 794 | | |
755 | 795 | | |
756 | 796 | | |
| |||
781 | 821 | | |
782 | 822 | | |
783 | 823 | | |
| 824 | + | |
784 | 825 | | |
785 | 826 | | |
786 | 827 | | |
| 828 | + | |
787 | 829 | | |
788 | 830 | | |
789 | 831 | | |
| |||
805 | 847 | | |
806 | 848 | | |
807 | 849 | | |
| 850 | + | |
808 | 851 | | |
809 | 852 | | |
810 | 853 | | |
| 854 | + | |
811 | 855 | | |
812 | 856 | | |
813 | 857 | | |
| |||
851 | 895 | | |
852 | 896 | | |
853 | 897 | | |
| 898 | + | |
854 | 899 | | |
855 | 900 | | |
856 | 901 | | |
| |||
Lines changed: 166 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
0 commit comments