Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disconnect extension when server is closed VSCODE-536 #734

Merged
merged 43 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ab84537
chore: bump minor dependencies
alenakhineika May 23, 2024
c85e84c
chore: bump more deps
alenakhineika May 23, 2024
1b00911
chore: revert ts-loader
alenakhineika May 23, 2024
38e7614
fix: update package lock
alenakhineika May 23, 2024
572c583
chore: remove npm legacy-peer-deps
alenakhineika May 24, 2024
0f8f6ce
chore: bump vscode engine and fix useEffect cleanup
alenakhineika May 24, 2024
1c5db75
fix: try to revert data service
alenakhineika May 24, 2024
518a04a
fix: try to revert some other stuff
alenakhineika May 24, 2024
7b8392b
test: debug
alenakhineika May 24, 2024
c57060a
test: move re-auth to beforeEach
alenakhineika May 24, 2024
d2bc204
test: reset reAuthCalled
alenakhineika May 24, 2024
5968cef
test: more debug
alenakhineika May 24, 2024
68c60b0
test: moreee debug
alenakhineika May 24, 2024
9756140
test: wait longer
alenakhineika May 24, 2024
74db530
test: print data service
alenakhineika May 24, 2024
14a5c9e
test: print only options
alenakhineika May 24, 2024
9f42776
test: try to move to before each
alenakhineika May 24, 2024
b6f90a4
test: try all before each
alenakhineika May 24, 2024
f828e75
test: try to skip prev test
alenakhineika May 24, 2024
c560171
test: try without catch
alenakhineika May 24, 2024
9692079
chore: revert mongodb runner
alenakhineika May 24, 2024
07efddf
test: revert test
alenakhineika May 24, 2024
f159919
test: run one
alenakhineika May 24, 2024
5137611
test: try server 8
alenakhineika May 24, 2024
7926dc3
test: try rc4
alenakhineika May 24, 2024
8d61871
test: try x
alenakhineika May 24, 2024
fa711be
test: revert
alenakhineika May 24, 2024
757b69c
test: try latest
alenakhineika May 26, 2024
ebbef7d
test: 8.1
alenakhineika May 26, 2024
869ba89
test: latest-alpha
alenakhineika May 26, 2024
3c4d7fe
Bump packages and fix errors
alenakhineika Jun 4, 2024
0bb702c
build: package lock
alenakhineika Jun 4, 2024
f8d29e1
build: freeze mongodb and bson versions
alenakhineika Jun 4, 2024
e4bde5a
build: bump vscode engine
alenakhineika Jun 4, 2024
5e7298f
chore: bump data service
alenakhineika Jun 25, 2024
c862bce
Merge remote-tracking branch 'origin/main' into bump-minor-deps
alenakhineika Jun 25, 2024
05a8a69
build: update package lock
alenakhineika Jun 25, 2024
bdcfe59
build: update package lock again
alenakhineika Jun 25, 2024
b91a858
build: bump vscode engine
alenakhineika Jun 25, 2024
c9785c8
refactor: remove sleeps
alenakhineika Jun 25, 2024
b9dd201
refactor: return sleep
alenakhineika Jun 25, 2024
093e852
test: trigger ci
alenakhineika Jun 25, 2024
c7976cf
refactor: use waitFor
alenakhineika Jun 26, 2024
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
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

6,623 changes: 4,030 additions & 2,593 deletions package-lock.json

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@
"@mongodb-js/compass-components": "^1.21.2",
"@mongodb-js/connection-form": "^1.22.2",
"@mongodb-js/connection-info": "^0.1.2",
"@mongodb-js/mongodb-constants": "^0.8.9",
"@mongodb-js/mongodb-constants": "^0.10.1",
"@mongosh/browser-runtime-electron": "^2.1.1",
"@mongosh/i18n": "^2.1.1",
"@mongosh/service-provider-server": "^2.1.1",
Expand All @@ -1090,79 +1090,79 @@
"bson": "^6.2.0",
"bson-transpilers": "^2.2.0",
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"dotenv": "^16.4.5",
"lodash": "^4.17.21",
"micromatch": "^4.0.5",
"mongodb": "^6.3.0",
"micromatch": "^4.0.7",
"mongodb": "^6.6.2",
"mongodb-build-info": "^1.7.1",
"mongodb-cloud-info": "^2.1.0",
"mongodb-connection-string-url": "^3.0.0",
"mongodb-data-service": "^22.17.3",
"mongodb-log-writer": "^1.4.0",
"mongodb-query-parser": "^4.0.2",
"mongodb-connection-string-url": "^3.0.1",
"mongodb-data-service": "^22.19.2",
"mongodb-log-writer": "^1.4.2",
"mongodb-query-parser": "^4.1.1",
"mongodb-schema": "^12.1.1",
"numeral": "^2.0.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"resolve-mongodb-srv": "^1.1.3",
"resolve-mongodb-srv": "^1.1.5",
"ts-log": "^2.2.5",
"uuid": "^8.3.2",
"vscode-languageclient": "^8.1.0",
"vscode-languageserver": "^8.1.0",
"vscode-languageserver-textdocument": "^1.0.10"
"vscode-languageserver-textdocument": "^1.0.11"
},
"devDependencies": {
"@babel/preset-typescript": "^7.22.5",
"@mongodb-js/oidc-mock-provider": "^0.6.10",
"@mongodb-js/oidc-plugin": "^0.3.0",
"@mongodb-js/oidc-mock-provider": "^0.9.0",
"@mongodb-js/oidc-plugin": "^0.4.0",
"@mongodb-js/prettier-config-devtools": "^1.0.1",
"@mongodb-js/sbom-tools": "^0.5.4",
"@mongodb-js/signing-utils": "^0.3.1",
"@mongodb-js/sbom-tools": "^0.5.13",
"@mongodb-js/signing-utils": "^0.3.4",
"@mongosh/service-provider-core": "^2.0.2",
"@testing-library/react": "^12.1.5",
"@types/babel__core": "^7.20.1",
"@types/babel__traverse": "^7.20.1",
"@types/chai": "^4.3.5",
"@types/debug": "^4.1.8",
"@types/chai": "^4.3.16",
"@types/debug": "^4.1.12",
"@types/glob": "^7.2.0",
"@types/jest": "^26.0.24",
"@types/micromatch": "^4.0.2",
"@types/micromatch": "^4.0.7",
"@types/mkdirp": "^2.0.0",
"@types/mocha": "^8.2.3",
"@types/node": "^14.18.53",
"@types/react": "^17.0.62",
"@types/react-dom": "^17.0.20",
"@types/node": "^14.18.63",
"@types/react": "^17.0.80",
"@types/react-dom": "^17.0.25",
"@types/sinon": "^9.0.11",
"@types/uuid": "^8.3.4",
"@types/vscode": "^1.79.1",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"@vscode/test-electron": "^2.3.8",
"@vscode/vsce": "^2.19.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@vscode/test-electron": "^2.3.10",
"@vscode/vsce": "^2.26.1",
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
"autoprefixer": "^10.4.16",
"autoprefixer": "^10.4.19",
"buffer": "^6.0.3",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"chai": "^4.4.1",
"chai-as-promised": "^7.1.2",
"cross-env": "^7.0.3",
"crypto-browserify": "^3.12.0",
"depcheck": "^1.4.3",
"depcheck": "^1.4.7",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"enzyme": "^3.11.0",
"eslint": "^8.44.0",
"eslint": "^8.57.0",
"eslint-config-mongodb-js": "^5.0.3",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-mocha": "^10.4.3",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"glob": "^7.2.3",
"jest": "^26.6.3",
"jest-junit": "^12.3.0",
"jest-transform-stub": "^2.0.0",
"mkdirp": "^1.0.4",
"mocha": "^10.2.0",
"mocha-junit-reporter": "^2.2.0",
"mocha": "^10.4.0",
"mocha-junit-reporter": "^2.2.1",
"mocha-multi": "^1.1.7",
"mongodb-client-encryption": "^6.0.0",
"mongodb-runner": "^5.5.2",
"mongodb-runner": "^5.6.2",
"node-fetch": "^2.7.0",
"node-loader": "^0.6.0",
"npm-run-all": "^4.1.5",
Expand All @@ -1176,12 +1176,12 @@
"stream-browserify": "^3.0.0",
"ts-jest": "^26.5.6",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"typescript": "^4.9.5",
"webpack": "^5.88.1",
"webpack-bundle-analyzer": "^4.9.0",
"webpack": "^5.91.0",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.9.0",
"webpack-merge": "^5.10.0",
"xvfb-maybe": "^0.2.1"
},
"precommit": [
Expand Down
12 changes: 12 additions & 0 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
import * as vscode from 'vscode';
import { connect, createConnectionAttempt } from 'mongodb-data-service';
import type {
Expand Down Expand Up @@ -458,15 +459,25 @@ export default class ConnectionController {

// Used to re-authenticate with OIDC.
async _reauthenticationHandler() {
console.log('----------------------');
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
console.log('original _reauthenticationHandler called');
console.log('----------------------');
const removeConfirmationResponse =
await vscode.window.showInformationMessage(
'You need to re-authenticate to the database in order to continue.',
{ modal: true },
'Confirm'
);

console.log('removeConfirmationResponse----------------------');
console.log(removeConfirmationResponse);
console.log('----------------------');

if (removeConfirmationResponse !== 'Confirm') {
await this.disconnect();
console.log('----------------------');
console.log('disconnected');
console.log('----------------------');
throw new Error('Reauthentication declined by user');
}
}
Expand Down Expand Up @@ -591,6 +602,7 @@ export default class ConnectionController {
try {
// Disconnect from the active connection.
await this._activeDataService.disconnect();

void vscode.window.showInformationMessage('MongoDB disconnected.');
this._activeDataService = null;

Expand Down
4 changes: 2 additions & 2 deletions src/telemetry/connectionTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ type CloudInfo = {

async function getHostnameForConnection(
connectionStringData: ConnectionString
): Promise<string | null> {
): Promise<string | undefined> {
if (connectionStringData.isSRV) {
const uri = await resolveMongodbSrv(connectionStringData.toString()).catch(
() => null
);
if (!uri) {
return null;
return undefined;
}
connectionStringData = new ConnectionString(uri, {
looseValidation: true,
Expand Down
34 changes: 29 additions & 5 deletions src/test/suite/oidc.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
import os from 'os';
import path from 'path';
import chai, { expect } from 'chai';
Expand All @@ -24,6 +25,8 @@ import { ConnectionString } from 'mongodb-connection-string-url';
import launchMongoShell from '../../commands/launchMongoShell';
import { getFullRange } from './suggestTestHelpers';

import * as util from 'util';

chai.use(chaiAsPromised);

function hash(input: string): string {
Expand Down Expand Up @@ -120,7 +123,7 @@ suite('OIDC Tests', function () {

cluster = await MongoCluster.start({
...defaultClusterOptions,
version: '7.0.x',
version: 'latest-alpha',
downloadOptions: { enterprise: true },
args: [
'--setParameter',
Expand All @@ -130,6 +133,8 @@ suite('OIDC Tests', function () {
'enableTestCommands=true',
'--setParameter',
`oidcIdentityProviders=${JSON.stringify([serverOidcConfig])}`,
'--setParameter',
'JWKSMinimumQuiescePeriodSecs=0',
],
});

Expand Down Expand Up @@ -352,7 +357,8 @@ suite('OIDC Tests', function () {
expect(testConnectionController.isCurrentlyConnected()).to.be.true;
});

test('can decline re-authentication if wanted', async function () {
// eslint-disable-next-line mocha/no-exclusive-tests
test.only('can decline re-authentication if wanted', async function () {
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
showInformationMessageStub.resolves('Declined');
const originalReAuthHandler =
testConnectionController._reauthenticationHandler.bind(
Expand Down Expand Up @@ -380,11 +386,17 @@ suite('OIDC Tests', function () {
};
};

expect(
const isConnected =
await testConnectionController.addNewConnectionStringAndConnect(
connectionString
)
).to.be.true;
);

expect(isConnected).to.be.true;

console.log('isConnected----------------------');
console.log(`${util.inspect(isConnected)}`);
console.log('----------------------');

afterReauth = true;

// Trigger a command on data service for reauthentication
Expand All @@ -393,6 +405,9 @@ suite('OIDC Tests', function () {
.getActiveDataService()
?.count('x.y', {})
.catch((error) => {
console.log('error----------------------');
console.log(`${util.inspect(error)}`);
console.log('----------------------');
expect(error.message).to.equal('Reauthentication declined by user');
});
}
Expand All @@ -401,6 +416,15 @@ suite('OIDC Tests', function () {

// Because we declined the auth in showInformationMessage above
expect(tokenFetchCalls).to.equal(1);

console.log(
'testConnectionController.isCurrentlyConnected()----------------------'
);
console.log(
`${util.inspect(testConnectionController.isCurrentlyConnected())}`
);
console.log('----------------------');

expect(testConnectionController.isCurrentlyConnected()).to.be.false;
});

Expand Down
8 changes: 6 additions & 2 deletions src/views/webview-app/use-connection-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ export default function useConnectionForm() {
}
};
window.addEventListener('message', handleConnectResultResponse);
() => window.removeEventListener('message', handleConnectResultResponse);
return () => {
window.removeEventListener('message', handleConnectResultResponse);
Anemy marked this conversation as resolved.
Show resolved Hide resolved
};
}, [initialConnectionInfo]);

useEffect(() => {
Expand All @@ -165,7 +167,9 @@ export default function useConnectionForm() {
}
};
window.addEventListener('message', handleConnectResultResponse);
() => window.removeEventListener('message', handleConnectResultResponse);
return () => {
window.removeEventListener('message', handleConnectResultResponse);
};
}, []);

return {
Expand Down
9 changes: 9 additions & 0 deletions syntaxes/mongodbInjection.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,15 @@
}
}
},
{
"name": "meta.object.member.mongodb",
"match": "\\$toHashedIndexKey\\b",
"captures": {
"0": {
"name": "keyword.other.$toHashedIndexKey.mongodb"
}
}
},
{
"name": "meta.object.member.mongodb",
"match": "\\$toLower\\b",
Expand Down
Loading