Skip to content

Commit 8401a73

Browse files
authored
feat: add proxy support MONGOSH-1827 (#2123)
This PR mostly just adds tests on top of the work done in devtools-shared.
1 parent 320f674 commit 8401a73

File tree

17 files changed

+1015
-528
lines changed

17 files changed

+1015
-528
lines changed

package-lock.json

Lines changed: 292 additions & 465 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/arg-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"mongodb-connection-string-url": "^3.0.1"
4141
},
4242
"devDependencies": {
43-
"@mongodb-js/devtools-connect": "^3.2.2",
43+
"@mongodb-js/devtools-connect": "^3.2.4",
4444
"@mongodb-js/eslint-config-mongosh": "^1.0.0",
4545
"@mongodb-js/prettier-config-devtools": "^1.0.1",
4646
"@mongodb-js/tsconfig-mongosh": "^1.0.0",

packages/cli-repl/.depcheckrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ ignores:
1717
- emphasize
1818
- ipv6-normalize
1919
- bindings
20+
- system-ca
2021
ignore-patterns:
21-
- .eslintrc.js
22+
- .eslintrc.js

packages/cli-repl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
}
6262
},
6363
"dependencies": {
64+
"@mongodb-js/devtools-proxy-support": "^0.3.4",
6465
"@mongosh/arg-parser": "0.0.0-dev.0",
6566
"@mongosh/autocomplete": "0.0.0-dev.0",
6667
"@mongosh/editor": "0.0.0-dev.0",
@@ -87,7 +88,6 @@
8788
"mongodb-log-writer": "^1.4.2",
8889
"numeral": "^2.0.6",
8990
"pretty-repl": "^4.0.1",
90-
"proxy-agent": "^6.4.0",
9191
"semver": "^7.5.4",
9292
"strip-ansi": "^6.0.0",
9393
"text-table": "^0.2.0",

packages/cli-repl/src/cli-repl.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,24 +1174,10 @@ export class CliRepl implements MongoshIOProvider {
11741174
)}\nWaiting...\n`
11751175
);
11761176
};
1177-
if (process.env.MONGOSH_EXPERIMENTAL_OIDC_PROXY_SUPPORT) {
1178-
const ProxyAgent = (await import('proxy-agent')).ProxyAgent;
1179-
const tlsCAFile =
1180-
driverOptions.tlsCAFile ??
1181-
new ConnectionString(driverUri)
1182-
.typedSearchParams<DevtoolsConnectOptions>()
1183-
.get('tlsCAFile');
1184-
const ca = tlsCAFile ? await fs.readFile(tlsCAFile) : undefined;
1185-
driverOptions.oidc.customHttpOptions = (_url, opts) => {
1186-
if (ca && !opts.ca) {
1187-
opts = { ...opts, ca };
1188-
}
1189-
return {
1190-
...opts,
1191-
agent: new ProxyAgent({ ...opts }),
1192-
};
1193-
};
1194-
}
1177+
driverOptions.proxy ??= {
1178+
useEnvironmentVariableProxies: true,
1179+
};
1180+
driverOptions.applyProxyToOIDC ??= true;
11951181

11961182
const [redirectURI, trustedEndpoints, browser] = await Promise.all([
11971183
this.getConfig('oidcRedirectURI'),

packages/cli-repl/src/run.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import net from 'net';
3131
import v8 from 'v8';
3232
import { TimingCategories } from '@mongosh/types';
3333
import './webpack-self-inspection';
34+
import { systemCA } from '@mongodb-js/devtools-proxy-support';
3435

3536
// TS does not yet have type definitions for v8.startupSnapshot
3637
if ((v8 as any)?.startupSnapshot?.isBuildingSnapshot?.()) {
@@ -41,6 +42,7 @@ if ((v8 as any)?.startupSnapshot?.isBuildingSnapshot?.()) {
4142
require('emphasize'); // Dependency of pretty-repl
4243
require('ipv6-normalize'); // Dependency of devtools-connect via os-dns-native
4344
require('bindings'); // Used by various native dependencies but not a native dep itself
45+
require('system-ca'); // Dependency of devtools-proxy-support
4446

4547
{
4648
const console = require('console');
@@ -195,6 +197,11 @@ async function main() {
195197
}
196198
}
197199

200+
markTime(TimingCategories.Main, 'scheduling system-ca loading');
201+
// asynchronously populate the system CA cache in devtools-proxy-support
202+
systemCA().catch(() => undefined);
203+
markTime(TimingCategories.Main, 'scheduled system-ca loading');
204+
198205
const connectionInfo = generateConnectionInfoFromCliArgs(options);
199206
connectionInfo.driverOptions = {
200207
...connectionInfo.driverOptions,

packages/e2e-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/chai-as-promised": "^7.1.3",
4040
"@types/node": "^14.14.6",
4141
"@types/rimraf": "^3.0.0",
42+
"bson": "^6.7.0",
4243
"chai-as-promised": "^7.1.1",
4344
"depcheck": "^1.4.3",
4445
"eslint": "^7.25.0",

packages/e2e-tests/test/e2e-oidc.spec.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import path from 'path';
1111
import { expect } from 'chai';
1212
import { createServer as createHTTPSServer } from 'https';
1313
import { getCertPath, useTmpdir } from './repl-helpers';
14+
import {
15+
baseOidcServerConfig,
16+
commonOidcServerArgs,
17+
skipOIDCTestsDueToPlatformOrServerVersion,
18+
} from './oidc-helpers';
1419

1520
/**
1621
* @securityTest OIDC Authentication End-to-End Tests
@@ -47,17 +52,10 @@ describe('OIDC auth e2e', function () {
4752
skipIfEnvServerVersion('< 7.0');
4853

4954
before(async function () {
50-
if (
51-
process.platform !== 'linux' ||
52-
!process.env.MONGOSH_SERVER_TEST_VERSION ||
53-
!process.env.MONGOSH_SERVER_TEST_VERSION.includes('-enterprise') ||
54-
+process.version.slice(1).split('.')[0] < 16
55-
) {
55+
if (skipOIDCTestsDueToPlatformOrServerVersion()) {
5656
// OIDC is only supported on Linux in the 7.0+ enterprise server,
5757
// and we can't skip based on the dynamically detected server version because
5858
// the OIDC config is something that needs to be available at server startup time.
59-
// Our mock OIDC provider does not work with Node.js 14, so we also need to skip
60-
// tests there.
6159
return this.skip();
6260
}
6361

@@ -87,19 +85,8 @@ describe('OIDC auth e2e', function () {
8785
]);
8886
const serverOidcConfig = {
8987
issuer: oidcMockProvider.issuer,
90-
clientId: 'testServer',
91-
requestScopes: ['mongodbGroups'],
92-
authorizationClaim: 'groups',
93-
audience: 'resource-server-audience-value',
94-
authNamePrefix: 'dev',
88+
...baseOidcServerConfig,
9589
};
96-
const commonOidcServerArgs = [
97-
'--setParameter',
98-
'authenticationMechanisms=SCRAM-SHA-256,MONGODB-OIDC',
99-
// enableTestCommands allows using http:// issuers such as http://localhost
100-
'--setParameter',
101-
'enableTestCommands=true',
102-
];
10390
testServer = new MongoRunnerSetup('e2e-oidc-test1', {
10491
args: [
10592
'--setParameter',

0 commit comments

Comments
 (0)