@@ -5,6 +5,7 @@ import { expect } from 'chai';
5
5
import * as sinon from 'sinon' ;
6
6
7
7
import {
8
+ type ClientSession ,
8
9
type Collection ,
9
10
MongoClient ,
10
11
type MongoDBOIDC ,
@@ -639,6 +640,73 @@ describe('OIDC Auth Spec Tests', function () {
639
640
expect ( saslStarts . length ) . to . equal ( 1 ) ;
640
641
} ) ;
641
642
} ) ;
643
+
644
+ describe ( '4.5 Reauthentication Succeeds when a Session is involved' , function ( ) {
645
+ let utilClient : MongoClient ;
646
+ let session : ClientSession ;
647
+ const callbackSpy = sinon . spy ( createCallback ( ) ) ;
648
+ // Create an OIDC configured client.
649
+ // Set a fail point for find commands of the form:
650
+ // {
651
+ // configureFailPoint: "failCommand",
652
+ // mode: {
653
+ // times: 1
654
+ // },
655
+ // data: {
656
+ // failCommands: [
657
+ // "find"
658
+ // ],
659
+ // errorCode: 391 // ReauthenticationRequired
660
+ // }
661
+ // }
662
+ // Start a new session.
663
+ // In the started session perform a find operation that succeeds.
664
+ // Assert that the callback was called 2 times (once during the connection handshake, and again during reauthentication).
665
+ // Close the session and the client.
666
+ beforeEach ( async function ( ) {
667
+ client = new MongoClient ( uriSingle , {
668
+ authMechanismProperties : {
669
+ OIDC_CALLBACK : callbackSpy
670
+ } ,
671
+ retryReads : false
672
+ } ) ;
673
+ utilClient = new MongoClient ( uriSingle , {
674
+ authMechanismProperties : {
675
+ OIDC_CALLBACK : createCallback ( )
676
+ } ,
677
+ retryReads : false
678
+ } ) ;
679
+ collection = client . db ( 'test' ) . collection ( 'test' ) ;
680
+ await utilClient
681
+ . db ( )
682
+ . admin ( )
683
+ . command ( {
684
+ configureFailPoint : 'failCommand' ,
685
+ mode : {
686
+ times : 1
687
+ } ,
688
+ data : {
689
+ failCommands : [ 'find' ] ,
690
+ errorCode : 391
691
+ }
692
+ } ) ;
693
+ session = client . startSession ( ) ;
694
+ } ) ;
695
+
696
+ afterEach ( async function ( ) {
697
+ await utilClient . db ( ) . admin ( ) . command ( {
698
+ configureFailPoint : 'failCommand' ,
699
+ mode : 'off'
700
+ } ) ;
701
+ await utilClient . close ( ) ;
702
+ await session . endSession ( ) ;
703
+ } ) ;
704
+
705
+ it ( 'successfully authenticates' , async function ( ) {
706
+ await collection . findOne ( { } , { session } ) ;
707
+ expect ( callbackSpy ) . to . have . been . calledTwice ;
708
+ } ) ;
709
+ } ) ;
642
710
} ) ;
643
711
} ) ;
644
712
0 commit comments