Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,51 @@ describe('OIDC plugin (mock OIDC provider)', function () {
expect(allOutboundRequests).to.deep.equal(allInboundRequests);
});

// Regression test for https://jira.mongodb.org/browse/MONGOSH-2444
it('correctly keeps tracking after serialization and deserialization', async function () {
const tokenEndpointRequests: any[] = [];
let serializedState: string | undefined;

getTokenPayload = () => {
return { ...tokenPayload, expires_in: 5 };
};

const runPlugin = async () => {
const plugin = createMongoDBOIDCPlugin({
openBrowserTimeout: 60_000,
openBrowser: fetchBrowser,
allowedFlows: ['auth-code'],
redirectURI: 'http://localhost:0/callback',
serializedState,
throwOnIncompatibleSerializedState: true,
});

plugin.logger.on(
'mongodb-oidc-plugin:outbound-http-request-completed',
(ev) => {
if (
ev.status === 200 &&
new URL(ev.url).pathname.endsWith('/token')
)
tokenEndpointRequests.push(ev);
}
);

await requestToken(plugin, {
issuer: provider.issuer,
clientId: 'mockclientid',
requestScopes: [],
});
serializedState = await plugin.serialize();
};

expect(tokenEndpointRequests).to.have.lengthOf(0);
await runPlugin();
expect(tokenEndpointRequests).to.have.lengthOf(1);
await runPlugin();
expect(tokenEndpointRequests).to.have.lengthOf(2);
});

it('allows node-fetch as a custom HTTP fetch client', async function () {
const customFetch = sinon.stub().callsFake(fetch);
const plugin = createMongoDBOIDCPlugin({
Expand Down
4 changes: 4 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ export class MongoDBOIDCPluginImpl implements MongoDBOIDCPlugin {
redirect_uri: redirectURI,
}
);
config[customFetch] = this.fetch;
if (
validateSecureHTTPUrl(config.serverMetadata().issuer, 'issuer') ===
'http-allowed'
Expand Down Expand Up @@ -544,6 +545,9 @@ export class MongoDBOIDCPluginImpl implements MongoDBOIDCPlugin {
);
validateSecureHTTPUrl(config.serverMetadata().jwks_uri, 'jwks_uri');

// Should already have been set by the discovery call, but doesn't hurt to make sure
config[customFetch] = this.fetch;

state.config = config;
return {
scope: makeScope(config.serverMetadata()),
Expand Down
Loading