From 555033632ed9cae8bcc856bbb900b03bde8c3cfa Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Fri, 9 May 2025 16:46:35 -0400 Subject: [PATCH 1/5] chore(webpack): add saslprep alias to avoid including the dep in the web bundle --- .../compass-web/polyfills/@mongodb-js/saslprep/index.ts | 1 + packages/compass-web/webpack.config.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts 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..ff8b4c56321 --- /dev/null +++ b/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts @@ -0,0 +1 @@ +export default {}; 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: [ From 52c74089675782cec13953ba4c44807c75c487df Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Fri, 9 May 2025 16:48:43 -0400 Subject: [PATCH 2/5] fixup: provide saslprep function in no-op polyfill --- .../compass-web/polyfills/@mongodb-js/saslprep/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts b/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts index ff8b4c56321..27a1bf39e82 100644 --- a/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts +++ b/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts @@ -1 +1,7 @@ -export default {}; +export function saslprep(): void { + // no-op +} + +export default { + saslprep, +}; From 921b26e718cdf6aec7a1b017a0e1b6db31548bf8 Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Thu, 15 May 2025 11:26:45 -0400 Subject: [PATCH 3/5] fixup: explicit throw, skip test for web, will need to skip more --- .../tests/connection.test.ts | 19 +++++++++---------- .../polyfills/@mongodb-js/saslprep/index.ts | 6 +----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/compass-e2e-tests/tests/connection.test.ts b/packages/compass-e2e-tests/tests/connection.test.ts index 542ab573466..b8c94cccaa0 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,15 +341,13 @@ 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 () { diff --git a/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts b/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts index 27a1bf39e82..241be4a647f 100644 --- a/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts +++ b/packages/compass-web/polyfills/@mongodb-js/saslprep/index.ts @@ -1,7 +1,3 @@ export function saslprep(): void { - // no-op + throw new Error('saslprep is not supported in this environment'); } - -export default { - saslprep, -}; From ec7428e591f7adbc42fe2f51b5f7f9c60fdbbf2a Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Thu, 15 May 2025 14:06:25 -0400 Subject: [PATCH 4/5] fixup: skip the other connection string scram based tests --- .../tests/connection.test.ts | 170 +++++++++--------- 1 file changed, 80 insertions(+), 90 deletions(-) diff --git a/packages/compass-e2e-tests/tests/connection.test.ts b/packages/compass-e2e-tests/tests/connection.test.ts index b8c94cccaa0..2f62abb42a4 100644 --- a/packages/compass-e2e-tests/tests/connection.test.ts +++ b/packages/compass-e2e-tests/tests/connection.test.ts @@ -351,7 +351,8 @@ describe('Connection string', function () { }); 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(); } @@ -370,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(); } @@ -394,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(); } @@ -418,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(); } @@ -442,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(); } @@ -465,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(); } @@ -487,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, @@ -506,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(); } @@ -517,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, @@ -554,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(); } @@ -565,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( @@ -591,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(); } @@ -602,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'); From 7f55363afcf874db8d4d9796f54c99c796c86e01 Mon Sep 17 00:00:00 2001 From: Rhys Howell Date: Mon, 19 May 2025 13:33:26 -0400 Subject: [PATCH 5/5] fixup: revert test changes, only polyfill saslprep when on production webpack build --- .../tests/connection.test.ts | 189 +++++++++--------- packages/compass-web/webpack.config.js | 13 +- 2 files changed, 109 insertions(+), 93 deletions(-) diff --git a/packages/compass-e2e-tests/tests/connection.test.ts b/packages/compass-e2e-tests/tests/connection.test.ts index 2f62abb42a4..542ab573466 100644 --- a/packages/compass-e2e-tests/tests/connection.test.ts +++ b/packages/compass-e2e-tests/tests/connection.test.ts @@ -329,8 +329,7 @@ describe('Connection string', function () { }); it('can connect to an Atlas replicaset without srv', async function () { - if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -341,18 +340,19 @@ describe('Connection string', function () { const connectionString = await resolveMongodbSrv(withSRV); await browser.connectWithConnectionString(connectionString); - const result = await browser.shellEval( - connectionNameFromString(connectionString), - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + 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); + } }); it('can connect to an Atlas cluster with a direct connection', async function () { - if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -371,18 +371,19 @@ describe('Connection string', function () { const connectionString = parsedString.toString(); await browser.connectWithConnectionString(connectionString); - const result = await browser.shellEval( - connectionNameFromString(connectionString), - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + 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); + } }); it('can connect to Atlas Serverless', async function () { - if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -394,18 +395,19 @@ describe('Connection string', function () { await browser.connectWithConnectionString(connectionString); - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + if (!TEST_COMPASS_WEB) { + 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() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -417,18 +419,19 @@ describe('Connection string', function () { await browser.connectWithConnectionString(connectionString); - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + if (!TEST_COMPASS_WEB) { + 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() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -440,18 +443,19 @@ describe('Connection string', function () { await browser.connectWithConnectionString(connectionString); - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + if (!TEST_COMPASS_WEB) { + 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() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -462,18 +466,19 @@ describe('Connection string', function () { const connectionName = connectionNameFromString(connectionString); await browser.connectWithConnectionString(connectionString); - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + if (!TEST_COMPASS_WEB) { + 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() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -483,13 +488,15 @@ describe('Connection string', function () { await browser.connectWithConnectionString(connectionString); - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + if (!TEST_COMPASS_WEB) { + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); + } await assertCanReadData( browser, @@ -500,8 +507,7 @@ describe('Connection string', function () { }); it('can connect with readAnyDatabase builtin role', async function () { - if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -512,13 +518,15 @@ describe('Connection string', function () { const connectionName = connectionNameFromString(connectionString); - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + if (!TEST_COMPASS_WEB) { + const result = await browser.shellEval( + connectionName, + 'db.runCommand({ connectionStatus: 1 })', + true + ); + assertNotError(result); + expect(result).to.have.property('ok', 1); + } await assertCanReadData( browser, @@ -547,8 +555,7 @@ describe('Connection string', function () { }); it('can connect with custom role', async function () { - if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { - // Skip this on web because it doesn't support saslprep. + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -559,13 +566,15 @@ describe('Connection string', function () { const connectionName = connectionNameFromString(connectionString); - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + if (!TEST_COMPASS_WEB) { + 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( @@ -583,7 +592,7 @@ describe('Connection string', function () { }); it('can connect with read one collection specific permission', async function () { - if (!hasAtlasEnvironmentVariables() || TEST_COMPASS_WEB) { + if (!hasAtlasEnvironmentVariables()) { return this.skip(); } @@ -594,13 +603,15 @@ describe('Connection string', function () { const connectionName = connectionNameFromString(connectionString); - const result = await browser.shellEval( - connectionName, - 'db.runCommand({ connectionStatus: 1 })', - true - ); - assertNotError(result); - expect(result).to.have.property('ok', 1); + if (!TEST_COMPASS_WEB) { + 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/webpack.config.js b/packages/compass-web/webpack.config.js index 080272c2542..8e04551c39e 100644 --- a/packages/compass-web/webpack.config.js +++ b/packages/compass-web/webpack.config.js @@ -45,10 +45,15 @@ 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'), + ...(config.mode === 'production' + ? { + // We don't need saslprep in the product web bundle, as we don't use scram auth there. + // We use a local polyfill for the driver to avoid having it in the bundle + // as it is a decent size. We do use scram auth in tests and local + // development, so we want it there. + '@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