Skip to content

Commit

Permalink
fix(connection-form): include OIDC in $external auth mechanism list C…
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax authored Dec 12, 2023
1 parent c06727f commit 76a38f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/tests/connection-form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ describe('Connection form', function () {

await browser.setConnectFormState(expectedState);
expect(await browser.getConnectFormConnectionString(true)).to.equal(
connectionString
`${connectionString}&authSource=%24external`
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
});
});

Expand All @@ -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',
},
Expand All @@ -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,
},
Expand All @@ -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: {},
});
});
Expand All @@ -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'],
},
Expand All @@ -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'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ describe('Authentication Handler', function () {
'GSSAPI',
'PLAIN',
'MONGODB-X509',
'MONGODB-OIDC',
];

for (const authMechanism of externalAuthMechanisms) {
Expand Down
10 changes: 7 additions & 3 deletions packages/connection-form/src/utils/authentication-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit 76a38f1

Please sign in to comment.