diff --git a/packages/compass-e2e-tests/tests/connection.test.ts b/packages/compass-e2e-tests/tests/connection.test.ts index 542ab573466..2f62abb42a4 100644 --- a/packages/compass-e2e-tests/tests/connection.test.ts +++ b/packages/compass-e2e-tests/tests/connection.test.ts @@ -329,7 +329,8 @@ describe('Connection string', function () { }); it('can connect to an Atlas replicaset without srv', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -340,19 +341,18 @@ describe('Connection string', function () { const connectionString = await resolveMongodbSrv(withSRV); await browser.connectWithConnectionString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionNameFromString(connectionString), - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionNameFromString(connectionString), + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); }); it('can connect to an Atlas cluster with a direct connection', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -371,19 +371,18 @@ describe('Connection string', function () { const connectionString = parsedString.toString(); await browser.connectWithConnectionString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionNameFromString(connectionString), - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionNameFromString(connectionString), + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); }); it('can connect to Atlas Serverless', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -395,19 +394,18 @@ describe('Connection string', function () { await browser.connectWithConnectionString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); }); it('can connect to Atlas Datalake', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -419,19 +417,18 @@ describe('Connection string', function () { await browser.connectWithConnectionString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); }); it('can connect to Atlas Analytics Node', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -443,19 +440,18 @@ describe('Connection string', function () { await browser.connectWithConnectionString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); }); it('can connect to Atlas Free Tier', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -466,19 +462,18 @@ describe('Connection string', function () { const connectionName = connectionNameFromString(connectionString); await browser.connectWithConnectionString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); }); it('can connect with readWriteAnyDatabase builtin role', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -488,15 +483,13 @@ describe('Connection string', function () { await browser.connectWithConnectionString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); await assertCanReadData( browser, @@ -507,7 +500,8 @@ describe('Connection string', function () { }); it('can connect with readAnyDatabase builtin role', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -518,15 +512,13 @@ describe('Connection string', function () { const connectionName = connectionNameFromString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); await assertCanReadData( browser, @@ -555,7 +547,8 @@ describe('Connection string', function () { }); it('can connect with custom role', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + // Skip this on web because it doesn't support saslprep. return this.skip(); } @@ -566,15 +559,13 @@ describe('Connection string', function () { const connectionName = connectionNameFromString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); await assertCanReadData(browser, connectionName, 'test', 'users'); await assertCannotCreateDb( @@ -592,7 +583,7 @@ describe('Connection string', function () { }); it('can connect with read one collection specific permission', async function () { - if (!hasAtlasEnvironmentVariables()) { + if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { return this.skip(); } @@ -603,15 +594,13 @@ describe('Connection string', function () { const connectionName = connectionNameFromString(connectionString); - if (!TEST_COMPASS_WEB) { - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); - } + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); await assertCanReadData(browser, connectionName, 'test', 'users'); await assertCannotInsertData(browser, connectionName, 'test', 'users'); diff --git a/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts b/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts new file mode 100644 index 00000000000..241be4a647f --- /dev/null +++ b/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts @@ -0,0 +1,3 @@ +export function saslprep(): void { + throw new Error('saslprep is not supported in this environment'); +} diff --git a/packages/compass-web/webpack.config.js b/packages/compass-web/webpack.config.js index d0109cf0db8..080272c2542 100644 --- a/packages/compass-web/webpack.config.js +++ b/packages/compass-web/webpack.config.js @@ -45,6 +45,11 @@ module.exports = (env, args) => { '@mongodb-js/devtools-proxy-support' ), + // We don't need saslprep in the web, as we don't use scram auth. + // We use a local polyfill for the driver to avoid having it in the bundle + // as it is a decent size. + '@mongodb-js/saslprep': localPolyfill('@mongodb-js/saslprep'), + // Replace 'devtools-connect' with a package that just directly connects // using the driver (= web-compatible driver) logic, because devtools-connect // contains a lot of logic that makes sense in a desktop application/CLI but @@ -218,7 +223,7 @@ module.exports = (env, args) => { 'react-dom': 'commonjs2 react-dom', // TODO(CLOUDP-228421): move Socket implementation from mms codebase when - // active work on the connumicatino protocol is wrapped up + // active work on the communication protocol is wrapped up tls: 'commonjs2 tls', }, plugins: [