Skip to content

Commit 3b6aa71

Browse files
Merge remote-tracking branch 'origin/main' into beta-releases
2 parents 42b72ce + afee5c4 commit 3b6aa71

File tree

17 files changed

+342
-243
lines changed

17 files changed

+342
-243
lines changed

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **Mongodb Compass**.
2-
This document was automatically generated on Sun Sep 24 2023.
2+
This document was automatically generated on Mon Sep 25 2023.
33

44
## List of dependencies
55

package-lock.json

Lines changed: 86 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/atlas-service/src/main.spec.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ describe('AtlasServiceMain', function () {
124124
expect(
125125
mockOidcPlugin.mongoClientOptions.authMechanismProperties
126126
.REQUEST_TOKEN_CALLBACK
127-
).to.have.been.calledOnce;
127+
// two times because we need to explicitly request token first to show a
128+
// proper error message from oidc plugin in case of failed sign in
129+
).to.have.been.calledTwice;
128130
expect(userInfo).to.have.property('sub', '1234');
129131
});
130132

@@ -139,7 +141,42 @@ describe('AtlasServiceMain', function () {
139141
expect(
140142
mockOidcPlugin.mongoClientOptions.authMechanismProperties
141143
.REQUEST_TOKEN_CALLBACK
142-
).to.have.been.calledOnce;
144+
// two times because we need to explicitly request token first to show a
145+
// proper error message from oidc plugin in case of failed sign in
146+
).to.have.been.calledTwice;
147+
});
148+
149+
it('should fail with oidc-plugin error first if auth failed', async function () {
150+
AtlasService['fetch'] = sandbox.stub().resolves({
151+
ok: false,
152+
json: sandbox.stub().rejects(),
153+
status: 401,
154+
statusText: 'Unauthorized',
155+
});
156+
AtlasService['plugin'] = {
157+
mongoClientOptions: {
158+
authMechanismProperties: {
159+
REQUEST_TOKEN_CALLBACK: sandbox
160+
.stub()
161+
.rejects(
162+
new Error(
163+
'Failed to request token for some specific plugin reason'
164+
)
165+
),
166+
REFRESH_TOKEN_CALLBACK: sandbox.stub().rejects(),
167+
},
168+
},
169+
} as any;
170+
171+
try {
172+
await AtlasService.signIn();
173+
expect.fail('Expected AtlasService.signIn to throw');
174+
} catch (err) {
175+
expect(err).to.have.property(
176+
'message',
177+
'Failed to request token for some specific plugin reason'
178+
);
179+
}
143180
});
144181
});
145182

packages/atlas-service/src/main.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { SecretStore, SECRET_STORE_KEY } from './secret-store';
4242
import { AtlasUserConfigStore } from './user-config-store';
4343
import { OidcPluginLogger } from './oidc-plugin-logger';
4444
import { getActiveUser } from 'compass-preferences-model';
45+
import { spawn } from 'child_process';
4546

4647
const { log, track } = createLoggerAndTelemetry('COMPASS-ATLAS-SERVICE');
4748

@@ -172,8 +173,24 @@ export class AtlasService {
172173

173174
private static config: AtlasServiceConfig;
174175

175-
private static openExternal(...args: Parameters<typeof shell.openExternal>) {
176-
return shell?.openExternal(...args);
176+
private static openExternal(url: string) {
177+
const { browserCommandForOIDCAuth } = preferences.getPreferences();
178+
if (browserCommandForOIDCAuth) {
179+
// NB: While it's possible to pass `openBrowser.command` option directly
180+
// to oidc-plugin properties, it's not possible to do dynamically. To
181+
// avoid recreating oidc-plugin every time user changes
182+
// `browserCommandForOIDCAuth` preference (which will cause loosing
183+
// internal plugin auth state), we copy oidc-plugin `openBrowser.command`
184+
// option handling to our openExternal method
185+
const child = spawn(browserCommandForOIDCAuth, [url], {
186+
shell: true,
187+
stdio: 'ignore',
188+
detached: true,
189+
});
190+
child.unref();
191+
return child;
192+
}
193+
return shell.openExternal(url);
177194
}
178195

179196
private static getAllowedAuthFlows(): AuthFlowType[] {
@@ -335,6 +352,10 @@ export class AtlasService {
335352
log.info(mongoLogId(1_001_000_218), 'AtlasService', 'Starting sign in');
336353

337354
try {
355+
// We first request oauth token just so we can get a proper auth error
356+
// from oidc-plugin. If we only run getUserInfo, the only thing users
357+
// will see is "401 unauthorized" as the reason for sign in failure
358+
await this.requestOAuthToken({ signal });
338359
const userInfo = await this.getUserInfo({ signal });
339360
log.info(
340361
mongoLogId(1_001_000_219),

packages/compass-aggregations/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@mongodb-js/compass-user-data": "^0.1.2",
4747
"@mongodb-js/compass-utils": "^0.4.0",
4848
"@mongodb-js/explain-plan-helper": "^1.1.2",
49-
"@mongodb-js/mongodb-constants": "^0.7.1",
49+
"@mongodb-js/mongodb-constants": "^0.8.3",
5050
"@mongodb-js/mongodb-redux-common": "^2.0.11",
5151
"bson": "^6.0.0",
5252
"compass-preferences-model": "^2.14.0",
@@ -106,7 +106,7 @@
106106
"@mongodb-js/compass-user-data": "^0.1.2",
107107
"@mongodb-js/compass-utils": "^0.4.0",
108108
"@mongodb-js/explain-plan-helper": "^1.1.2",
109-
"@mongodb-js/mongodb-constants": "^0.7.1",
109+
"@mongodb-js/mongodb-constants": "^0.8.3",
110110
"@mongodb-js/mongodb-redux-common": "^2.0.11",
111111
"bson": "^6.0.0",
112112
"compass-preferences-model": "^2.14.0",

0 commit comments

Comments
 (0)