Skip to content

Commit 4ac5a17

Browse files
authored
fix: keep using customFetch implementation for new Configuration instance MONGOSH-2444 (#228)
1 parent 8fbf605 commit 4ac5a17

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/plugin.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,51 @@ describe('OIDC plugin (mock OIDC provider)', function () {
14601460
expect(allOutboundRequests).to.deep.equal(allInboundRequests);
14611461
});
14621462

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+
14631508
it('allows node-fetch as a custom HTTP fetch client', async function () {
14641509
const customFetch = sinon.stub().callsFake(fetch);
14651510
const plugin = createMongoDBOIDCPlugin({

src/plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ export class MongoDBOIDCPluginImpl implements MongoDBOIDCPlugin {
487487
redirect_uri: redirectURI,
488488
}
489489
);
490+
config[customFetch] = this.fetch;
490491
if (
491492
validateSecureHTTPUrl(config.serverMetadata().issuer, 'issuer') ===
492493
'http-allowed'
@@ -544,6 +545,9 @@ export class MongoDBOIDCPluginImpl implements MongoDBOIDCPlugin {
544545
);
545546
validateSecureHTTPUrl(config.serverMetadata().jwks_uri, 'jwks_uri');
546547

548+
// Should already have been set by the discovery call, but doesn't hurt to make sure
549+
config[customFetch] = this.fetch;
550+
547551
state.config = config;
548552
return {
549553
scope: makeScope(config.serverMetadata()),

0 commit comments

Comments
 (0)