From 76a38f1ee24bd6af6ac92999972305ab8da65958 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 12 Dec 2023 15:44:35 +0100 Subject: [PATCH] fix(connection-form): include OIDC in `$external` auth mechanism list COMPASS-7512 (#5217) --- .../tests/connection-form.test.ts | 2 +- .../authentication-oidc.spec.tsx | 14 +++++++------- .../src/utils/authentication-handler.spec.ts | 1 + .../src/utils/authentication-handler.ts | 10 +++++++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/compass-e2e-tests/tests/connection-form.test.ts b/packages/compass-e2e-tests/tests/connection-form.test.ts index 6768722bcab..729a3c0690f 100644 --- a/packages/compass-e2e-tests/tests/connection-form.test.ts +++ b/packages/compass-e2e-tests/tests/connection-form.test.ts @@ -665,7 +665,7 @@ describe('Connection form', function () { await browser.setConnectFormState(expectedState); expect(await browser.getConnectFormConnectionString(true)).to.equal( - connectionString + `${connectionString}&authSource=%24external` ); }); diff --git a/packages/connection-form/src/components/advanced-options-tabs/authentication-tab/authentication-oidc.spec.tsx b/packages/connection-form/src/components/advanced-options-tabs/authentication-tab/authentication-oidc.spec.tsx index b8c93f646e2..5117c361731 100644 --- a/packages/connection-form/src/components/advanced-options-tabs/authentication-tab/authentication-oidc.spec.tsx +++ b/packages/connection-form/src/components/advanced-options-tabs/authentication-tab/authentication-oidc.spec.tsx @@ -56,7 +56,7 @@ const openAuthOIDC = async () => { const openOptionsAccordion = () => fireEvent.click(screen.getByText('OIDC Options')); -describe('AuthenticationOIDC Connection Form', function () { +describe('Authentication OIDC Connection Form', function () { let expectToConnectWith; let connectSpy: sinon.SinonSpy; @@ -100,7 +100,7 @@ describe('AuthenticationOIDC Connection Form', function () { await expectToConnectWith({ connectionString: - 'mongodb://goodSandwich@localhost:27017/?authMechanism=MONGODB-OIDC', + 'mongodb://goodSandwich@localhost:27017/?authMechanism=MONGODB-OIDC&authSource=%24external', }); }); @@ -111,7 +111,7 @@ describe('AuthenticationOIDC Connection Form', function () { await expectToConnectWith({ connectionString: - 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC', + 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC&authSource=%24external', oidc: { redirectURI: 'goodSandwiches', }, @@ -122,7 +122,7 @@ describe('AuthenticationOIDC Connection Form', function () { fireEvent.click(screen.getByText('Consider Target Endpoint Trusted')); await expectToConnectWith({ connectionString: - 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC', + 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC&authSource=%24external', oidc: { enableUntrustedEndpoints: true, }, @@ -134,7 +134,7 @@ describe('AuthenticationOIDC Connection Form', function () { fireEvent.click(screen.getByText('Consider Target Endpoint Trusted')); await expectToConnectWith({ connectionString: - 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC', + 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC&authSource=%24external', oidc: {}, }); }); @@ -153,7 +153,7 @@ describe('AuthenticationOIDC Connection Form', function () { fireEvent.click(screen.getByText(deviceAuthFlowText)); await expectToConnectWith({ connectionString: - 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC', + 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC&authSource=%24external', oidc: { allowedFlows: ['auth-code', 'device-auth'], }, @@ -165,7 +165,7 @@ describe('AuthenticationOIDC Connection Form', function () { fireEvent.click(screen.getByText(deviceAuthFlowText)); await expectToConnectWith({ connectionString: - 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC', + 'mongodb://localhost:27017/?authMechanism=MONGODB-OIDC&authSource=%24external', oidc: { allowedFlows: ['auth-code'], }, diff --git a/packages/connection-form/src/utils/authentication-handler.spec.ts b/packages/connection-form/src/utils/authentication-handler.spec.ts index 313f4b5b34e..4d0383b1cbb 100644 --- a/packages/connection-form/src/utils/authentication-handler.spec.ts +++ b/packages/connection-form/src/utils/authentication-handler.spec.ts @@ -225,6 +225,7 @@ describe('Authentication Handler', function () { 'GSSAPI', 'PLAIN', 'MONGODB-X509', + 'MONGODB-OIDC', ]; for (const authMechanism of externalAuthMechanisms) { diff --git a/packages/connection-form/src/utils/authentication-handler.ts b/packages/connection-form/src/utils/authentication-handler.ts index f98c78af8b7..81ae580c018 100644 --- a/packages/connection-form/src/utils/authentication-handler.ts +++ b/packages/connection-form/src/utils/authentication-handler.ts @@ -66,9 +66,13 @@ export function handleUpdateAuthMechanism({ if (action.authMechanism) { updatedSearchParams.set('authMechanism', action.authMechanism); if ( - ['MONGODB-AWS', 'GSSAPI', 'PLAIN', 'MONGODB-X509'].includes( - action.authMechanism - ) + [ + 'MONGODB-AWS', + 'GSSAPI', + 'PLAIN', + 'MONGODB-X509', + 'MONGODB-OIDC', + ].includes(action.authMechanism) ) { updatedSearchParams.set('authSource', '$external'); }