@@ -1460,6 +1460,51 @@ describe('OIDC plugin (mock OIDC provider)', function () {
1460
1460
expect ( allOutboundRequests ) . to . deep . equal ( allInboundRequests ) ;
1461
1461
} ) ;
1462
1462
1463
+ // Regression test for https://jira.mongodb.org/browse/MONGOSH-2444
1464
+ it ( 'correctly keeps tracking after serialization and deserialization' , async function ( ) {
1465
+ const tokenEndpointRequests : any [ ] = [ ] ;
1466
+ let serializedState : string | undefined ;
1467
+
1468
+ getTokenPayload = ( ) => {
1469
+ return { ...tokenPayload , expires_in : 5 } ;
1470
+ } ;
1471
+
1472
+ const runPlugin = async ( ) => {
1473
+ const plugin = createMongoDBOIDCPlugin ( {
1474
+ openBrowserTimeout : 60_000 ,
1475
+ openBrowser : fetchBrowser ,
1476
+ allowedFlows : [ 'auth-code' ] ,
1477
+ redirectURI : 'http://localhost:0/callback' ,
1478
+ serializedState,
1479
+ throwOnIncompatibleSerializedState : true ,
1480
+ } ) ;
1481
+
1482
+ plugin . logger . on (
1483
+ 'mongodb-oidc-plugin:outbound-http-request-completed' ,
1484
+ ( ev ) => {
1485
+ if (
1486
+ ev . status === 200 &&
1487
+ new URL ( ev . url ) . pathname . endsWith ( '/token' )
1488
+ )
1489
+ tokenEndpointRequests . push ( ev ) ;
1490
+ }
1491
+ ) ;
1492
+
1493
+ await requestToken ( plugin , {
1494
+ issuer : provider . issuer ,
1495
+ clientId : 'mockclientid' ,
1496
+ requestScopes : [ ] ,
1497
+ } ) ;
1498
+ serializedState = await plugin . serialize ( ) ;
1499
+ } ;
1500
+
1501
+ expect ( tokenEndpointRequests ) . to . have . lengthOf ( 0 ) ;
1502
+ await runPlugin ( ) ;
1503
+ expect ( tokenEndpointRequests ) . to . have . lengthOf ( 1 ) ;
1504
+ await runPlugin ( ) ;
1505
+ expect ( tokenEndpointRequests ) . to . have . lengthOf ( 2 ) ;
1506
+ } ) ;
1507
+
1463
1508
it ( 'allows node-fetch as a custom HTTP fetch client' , async function ( ) {
1464
1509
const customFetch = sinon . stub ( ) . callsFake ( fetch ) ;
1465
1510
const plugin = createMongoDBOIDCPlugin ( {
0 commit comments