@@ -14,6 +14,7 @@ import {
1414 type OIDCResponse
1515} from '../../../src' ;
1616import { type MongoDBOIDC , type OIDCCallbackFunction } from '../../../src/cmap/auth/mongodb_oidc' ;
17+ import { getEnvironmentData } from 'node:worker_threads' ;
1718
1819const createCallback = ( tokenFile = 'test_user1' , expiresInSeconds ?: number , extraFields ?: any ) => {
1920 return async ( params : OIDCCallbackParams ) => {
@@ -61,6 +62,13 @@ const getClientOptions = (callbackSpy?: OIDCCallbackFunction) => {
6162 return options ;
6263} ;
6364
65+ const getProviderLookupProperties = ( callbackSpy ?: OIDCCallbackFunction ) => {
66+ if ( isCallbackTest && callbackSpy ) {
67+ return { OIDC_CALLBACK : callbackSpy } ;
68+ }
69+ return { ENVIRONMENT : process . env . ENVIRONMENT } ;
70+ }
71+
6472const getClient = ( extraOptions : MongoClientOptions = { } , callbackSpy ?: OIDCCallbackFunction ) => {
6573 const options = getClientOptions ( callbackSpy ) ;
6674 const mergedOptions = extraOptions ? { ...options , ...extraOptions } : options ;
@@ -91,8 +99,7 @@ describe('OIDC Auth Spec Tests', function () {
9199 } ) ;
92100
93101 it ( 'successfully authenticates' , async function ( ) {
94- const error = await collection . findOne ( ) . catch ( error => error ) ;
95- expect ( error ) . to . not . exist ;
102+ await collection . findOne ( ) ;
96103 if ( isCallbackTest ) {
97104 expect ( callbackSpy ) . to . have . been . calledOnce ;
98105 }
@@ -112,8 +119,7 @@ describe('OIDC Auth Spec Tests', function () {
112119
113120 it ( 'only calls the callback once' , async function ( ) {
114121 for ( let i = 0 ; i < 100 ; i ++ ) {
115- const error = await collection . findOne ( ) . catch ( error => error ) ;
116- expect ( error ) . to . not . exist ;
122+ await collection . findOne ( ) ;
117123 }
118124 if ( isCallbackTest ) {
119125 expect ( callbackSpy ) . to . have . been . calledOnce ;
@@ -220,16 +226,16 @@ describe('OIDC Auth Spec Tests', function () {
220226 // Close the client.
221227 beforeEach ( function ( ) {
222228 client = getClient ( { } , callbackSpy ) ;
223- const provider = client . s . authProviders . getOrCreateProvider ( 'MONGODB-OIDC' , {
224- OIDC_CALLBACK : callbackSpy
225- } ) as MongoDBOIDC ;
229+ const provider = client . s . authProviders . getOrCreateProvider (
230+ 'MONGODB-OIDC' ,
231+ getProviderLookupProperties ( callbackSpy )
232+ ) as MongoDBOIDC ;
226233 provider . workflow . cache . put ( { idpServerResponse : { accessToken : 'bad' } } ) ;
227234 collection = client . db ( 'test' ) . collection ( 'test' ) ;
228235 } ) ;
229236
230237 it ( 'successfully authenticates' , async function ( ) {
231- const error = await collection . findOne ( ) . catch ( error => error ) ;
232- expect ( error ) . to . not . exist ;
238+ await collection . findOne ( ) ;
233239 if ( isCallbackTest ) {
234240 expect ( callbackSpy ) . to . have . been . calledOnce ;
235241 }
@@ -288,12 +294,7 @@ describe('OIDC Auth Spec Tests', function () {
288294 // Close the client.
289295 beforeEach ( async function ( ) {
290296 client = getClient ( { } , callbackSpy ) ;
291- utilClient = new MongoClient ( uriSingle , {
292- authMechanismProperties : {
293- OIDC_CALLBACK : createCallback ( )
294- } ,
295- retryReads : false
296- } ) ;
297+ utilClient = getClient ( { } , callbackSpy ) ;
297298 collection = client . db ( 'test' ) . collection ( 'test' ) ;
298299 await utilClient
299300 . db ( )
@@ -378,12 +379,7 @@ describe('OIDC Auth Spec Tests', function () {
378379 // Close the client.
379380 beforeEach ( async function ( ) {
380381 client = getClient ( { } , callbackSpy ) ;
381- utilClient = new MongoClient ( uriSingle , {
382- authMechanismProperties : {
383- OIDC_CALLBACK : createCallback ( )
384- } ,
385- retryReads : false
386- } ) ;
382+ utilClient = getClient ( { } , callbackSpy ) ;
387383 collection = client . db ( 'test' ) . collection ( 'test' ) ;
388384 await utilClient
389385 . db ( )
@@ -439,12 +435,7 @@ describe('OIDC Auth Spec Tests', function () {
439435 // Close the client.
440436 beforeEach ( async function ( ) {
441437 client = getClient ( { promoteValues : false } , callbackSpy ) ;
442- utilClient = new MongoClient ( uriSingle , {
443- authMechanismProperties : {
444- OIDC_CALLBACK : createCallback ( )
445- } ,
446- retryReads : false
447- } ) ;
438+ utilClient = getClient ( { promoteValues : false } , callbackSpy ) ;
448439 collection = client . db ( 'test' ) . collection ( 'test' ) ;
449440 await utilClient
450441 . db ( )
@@ -501,8 +492,8 @@ describe('OIDC Auth Spec Tests', function () {
501492 // Close the client.
502493 beforeEach ( async function ( ) {
503494 if ( ! isCallbackTest ) {
504- this . skipReason = 'Callback validation tests only run in test environment' ;
505- this . skip ( ) ;
495+ this . test . skipReason = 'Callback validation tests only run in test environment' ;
496+ this . test . skip ( ) ;
506497 }
507498 client = getClient ( { } , callbackSpy ) ;
508499 utilClient = new MongoClient ( uriSingle , {
@@ -565,8 +556,8 @@ describe('OIDC Auth Spec Tests', function () {
565556 // Close the client.
566557 beforeEach ( async function ( ) {
567558 if ( ! isCallbackTest ) {
568- this . skipReason = 'Callback validation tests only run in test environment' ;
569- this . skip ( ) ;
559+ this . test . skipReason = 'Callback validation tests only run in test environment' ;
560+ this . test . skip ( ) ;
570561 }
571562 client = getClient ( { } , callbackSpy ) ;
572563 utilClient = new MongoClient ( uriSingle , {
@@ -637,13 +628,7 @@ describe('OIDC Auth Spec Tests', function () {
637628 // - Assert there were `SaslStart` commands executed.
638629 // - Close the client.
639630 beforeEach ( async function ( ) {
640- utilClient = new MongoClient ( uriSingle , {
641- authMechanismProperties : {
642- OIDC_CALLBACK : createCallback ( )
643- } ,
644- retryReads : false
645- } ) ;
646-
631+ utilClient = getClient ( { } , callbackSpy ) ;
647632 client = getClient ( { monitorCommands : true } , callbackSpy ) ;
648633 client . on ( 'commandStarted' , event => {
649634 if ( event . commandName === 'saslStart' ) {
@@ -721,12 +706,7 @@ describe('OIDC Auth Spec Tests', function () {
721706 // Close the session and the client.
722707 beforeEach ( async function ( ) {
723708 client = getClient ( { } , callbackSpy ) ;
724- utilClient = new MongoClient ( uriSingle , {
725- authMechanismProperties : {
726- OIDC_CALLBACK : createCallback ( )
727- } ,
728- retryReads : false
729- } ) ;
709+ utilClient = getClient ( { } , callbackSpy ) ;
730710 collection = client . db ( 'test' ) . collection ( 'test' ) ;
731711 await utilClient
732712 . db ( )
0 commit comments