Skip to content
Merged
8 changes: 8 additions & 0 deletions .github/workflows/actions/test-and-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ runs:
if: ${{ runner.os != 'Windows' }}
shell: bash

- name: Set BROWSER_AUTH_COMMAND
run: |
BROWSER_AUTH_COMMAND=$(echo "$(which node) $(pwd)/src/test/fixture/curl.js")
echo "BROWSER_AUTH_COMMAND=$BROWSER_AUTH_COMMAND" >> $GITHUB_ENV
shell: bash

- name: Run Tests
env:
BROWSER_AUTH_COMMAND: ${{ env.BROWSER_AUTH_COMMAND }}
run: |
npm run test
shell: bash
Expand Down
110 changes: 104 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,11 @@
"type": "boolean",
"default": false,
"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."
},
"mdb.browserCommandForOIDCAuth": {
"type": "string",
"default": "",
"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."
}
}
}
Expand Down Expand Up @@ -1079,6 +1084,7 @@
},
"devDependencies": {
"@babel/preset-typescript": "^7.22.5",
"@mongodb-js/oidc-mock-provider": "^0.6.9",
"@mongodb-js/oidc-plugin": "^0.3.0",
"@mongodb-js/prettier-config-compass": "^1.0.0",
"@mongodb-js/sbom-tools": "^0.5.4",
Expand Down Expand Up @@ -1132,6 +1138,7 @@
"mocha-multi": "^1.1.7",
"mongodb-client-encryption": "^6.0.0",
"mongodb-runner": "^5.4.5",
"node-fetch": "^2.7.0",
"node-loader": "^0.6.0",
"npm-run-all": "^4.1.5",
"ora": "^5.4.1",
Expand Down
30 changes: 18 additions & 12 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,22 +336,27 @@ export default class ConnectionController {
browserCommandForOIDCAuth: undefined, // We overwrite this below.
},
});
const browserAuthCommand = vscode.workspace
.getConfiguration('mdb')
.get('browserCommandForOIDCAuth');
dataService = await connectionAttempt.connect({
...connectionOptions,
oidc: {
...cloneDeep(connectionOptions.oidc),
openBrowser: async ({ signal, url }) => {
try {
await openLink(url);
} catch (err) {
if (signal.aborted) return;
// If opening the link fails we default to regular link opening.
await vscode.commands.executeCommand(
'vscode.open',
vscode.Uri.parse(url)
);
}
},
openBrowser: browserAuthCommand
? { command: browserAuthCommand }
: async ({ signal, url }) => {
try {
await openLink(url);
} catch (err) {
if (signal.aborted) return;
// If opening the link fails we default to regular link opening.
await vscode.commands.executeCommand(
'vscode.open',
vscode.Uri.parse(url)
);
}
},
},
});

Expand Down Expand Up @@ -425,6 +430,7 @@ export default class ConnectionController {
);

if (removeConfirmationResponse !== 'Confirm') {
await this.disconnect();
throw new Error('Reauthentication declined by user');
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/fixture/curl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node
/* eslint-disable */
'use strict';
const fetch = require('node-fetch');

// fetch() an URL and ignore the response body
(async function () {
(await fetch(process.argv[2])).body?.resume();
})().catch((err) => {
process.nextTick(() => {
throw err;
});
});
Loading