Skip to content

Commit 1eb876e

Browse files
chore: adds tests for oidc in vscode - VSCODE-414 (#652)
* chore: added integration tests for oidc in vscode * chore: removed mac specific changes * chore: fix github ci * chore: action fixup * chore: minor cleanup * chore: remove the timeout and instead wait for promise resolve * chore: review fixup * chore: changed expectations to use chai * chore: remove reliance on timeouts entirely
1 parent 74dd970 commit 1eb876e

File tree

6 files changed

+586
-18
lines changed

6 files changed

+586
-18
lines changed

.github/workflows/actions/test-and-build/action.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ runs:
6969
if: ${{ runner.os != 'Windows' }}
7070
shell: bash
7171

72+
- name: Set BROWSER_AUTH_COMMAND
73+
run: |
74+
BROWSER_AUTH_COMMAND=$(echo "$(which node) $(pwd)/src/test/fixture/curl.js")
75+
echo "BROWSER_AUTH_COMMAND=$BROWSER_AUTH_COMMAND" >> $GITHUB_ENV
76+
shell: bash
77+
7278
- name: Run Tests
79+
env:
80+
BROWSER_AUTH_COMMAND: ${{ env.BROWSER_AUTH_COMMAND }}
7381
run: |
7482
npm run test
7583
shell: bash

package-lock.json

+104-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,11 @@
10291029
"type": "boolean",
10301030
"default": false,
10311031
"description": "The default behavior is to generate a single ObjectId and insert it on all cursors. Set to true to generate a unique ObjectId per cursor instead."
1032+
},
1033+
"mdb.browserCommandForOIDCAuth": {
1034+
"type": "string",
1035+
"default": "",
1036+
"description": "Specify a shell command that is run to start the browser for authenticating with the OIDC identity provider for the server connection. Leave this empty for default browser."
10321037
}
10331038
}
10341039
}
@@ -1071,6 +1076,7 @@
10711076
},
10721077
"devDependencies": {
10731078
"@babel/preset-typescript": "^7.22.5",
1079+
"@mongodb-js/oidc-mock-provider": "^0.6.9",
10741080
"@mongodb-js/oidc-plugin": "^0.3.0",
10751081
"@mongodb-js/prettier-config-compass": "^1.0.0",
10761082
"@mongodb-js/sbom-tools": "^0.5.4",
@@ -1122,6 +1128,7 @@
11221128
"mocha-multi": "^1.1.7",
11231129
"mongodb-client-encryption": "^6.0.0",
11241130
"mongodb-runner": "^5.4.5",
1131+
"node-fetch": "^2.7.0",
11251132
"node-loader": "^0.6.0",
11261133
"npm-run-all": "^4.1.5",
11271134
"ora": "^5.4.1",

src/connectionController.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,27 @@ export default class ConnectionController {
313313
browserCommandForOIDCAuth: undefined, // We overwrite this below.
314314
},
315315
});
316+
const browserAuthCommand = vscode.workspace
317+
.getConfiguration('mdb')
318+
.get('browserCommandForOIDCAuth');
316319
dataService = await connectionAttempt.connect({
317320
...connectionOptions,
318321
oidc: {
319322
...cloneDeep(connectionOptions.oidc),
320-
openBrowser: async ({ signal, url }) => {
321-
try {
322-
await openLink(url);
323-
} catch (err) {
324-
if (signal.aborted) return;
325-
// If opening the link fails we default to regular link opening.
326-
await vscode.commands.executeCommand(
327-
'vscode.open',
328-
vscode.Uri.parse(url)
329-
);
330-
}
331-
},
323+
openBrowser: browserAuthCommand
324+
? { command: browserAuthCommand }
325+
: async ({ signal, url }) => {
326+
try {
327+
await openLink(url);
328+
} catch (err) {
329+
if (signal.aborted) return;
330+
// If opening the link fails we default to regular link opening.
331+
await vscode.commands.executeCommand(
332+
'vscode.open',
333+
vscode.Uri.parse(url)
334+
);
335+
}
336+
},
332337
},
333338
});
334339

@@ -402,6 +407,7 @@ export default class ConnectionController {
402407
);
403408

404409
if (removeConfirmationResponse !== 'Confirm') {
410+
await this.disconnect();
405411
throw new Error('Reauthentication declined by user');
406412
}
407413
}

src/test/fixture/curl.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable */
3+
'use strict';
4+
const fetch = require('node-fetch');
5+
6+
// fetch() an URL and ignore the response body
7+
(async function () {
8+
(await fetch(process.argv[2])).body?.resume();
9+
})().catch((err) => {
10+
process.nextTick(() => {
11+
throw err;
12+
});
13+
});

0 commit comments

Comments
 (0)