Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dc70359

Browse files
committed
chore: add test for token refresh
1 parent 5745d7b commit dc70359

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

‎tests/integration/common/connectionManager.oidc.test.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import {
77
getServerVersion,
88
MongoDBIntegrationTestCase,
99
} from "../tools/mongodb/mongodbHelpers.js";
10-
import { defaultTestConfig, responseAsText } from "../helpers.js";
10+
import { defaultTestConfig, responseAsText,timeout } from "../helpers.js";
1111
import {
1212
ConnectionManager,
1313
ConnectionStateConnected,
1414
ConnectionStateConnecting,
1515
} from "../../../src/common/connectionManager.js";
1616
import { setupDriverConfig, UserConfig } from "../../../src/common/config.js";
17-
import fs from "fs";
1817
import path from "path";
1918
import type { OIDCMockProviderConfig } from "@mongodb-js/oidc-mock-provider";
2019
import { OIDCMockProvider } from "@mongodb-js/oidc-mock-provider";
2120

2221
const DEFAULT_TIMEOUT = 10000;
2322

24-
describe("ConnectionManager OIDC Tests", async () => {
23+
// OIDC is only supported on Linux servers
24+
describe.skipIf(process.platform !== "linux")("ConnectionManager OIDC Tests", async () => {
2525
function setParameter(param: string): ["--setParameter", string] {
2626
return ["--setParameter", param];
2727
}
@@ -55,7 +55,7 @@ describe("ConnectionManager OIDC Tests", async () => {
5555
getTokenPayload = ((metadata) => {
5656
tokenFetches++;
5757
return {
58-
expires_in: 3600,
58+
expires_in: 1,
5959
payload: {
6060
// Define the user information stored inside the access tokens
6161
groups: [`${metadata.client_id}-group`],
@@ -100,6 +100,8 @@ describe("ConnectionManager OIDC Tests", async () => {
100100
...defaultTestConfig,
101101
oidcRedirectURi: "http://localhost:0/",
102102
authenticationMechanism: "MONGODB-OIDC",
103+
maxIdleTimeMS: "1",
104+
minPoolSize: "0",
103105
username: "testuser",
104106
browser: fetchBrowserFixture,
105107
...args?.additionalConfig,
@@ -111,7 +113,6 @@ describe("ConnectionManager OIDC Tests", async () => {
111113
function oidcIt(name: string, cb: Parameters<OidcIt>[1]): void {
112114
/* eslint-disable @vitest/expect-expect */
113115
it(name, { timeout: DEFAULT_TIMEOUT }, async (context) => {
114-
context.skip(process.platform !== "linux", "OIDC is only supported on Linux");
115116
context.skip(
116117
await isCommunityServer(integration),
117118
"OIDC is not supported in MongoDB Community"
@@ -193,6 +194,18 @@ describe("ConnectionManager OIDC Tests", async () => {
193194
const databases = listDbResult.databases as unknown[];
194195
expect(databases.length).toBeGreaterThan(0);
195196
});
197+
198+
it("can refresh a token once expired", async ({ signal }, integration) => {
199+
const state = await ConnectionManager.waitUntil<ConnectionStateConnected>(
200+
"connected",
201+
integration.mcpServer().session.connectionManager,
202+
signal
203+
);
204+
205+
await timeout(2000);
206+
await state.serviceProvider.listDatabases("admin");
207+
expect(tokenFetches).toBeGreaterThan(1);
208+
});
196209
});
197210
}
198211

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /