Skip to content

Commit 0973d8d

Browse files
committed
Merge branch 'main' into 1.29-releases
2 parents 67c1b8d + 3581237 commit 0973d8d

File tree

7 files changed

+109
-39
lines changed

7 files changed

+109
-39
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 **compass**.
2-
This document was automatically generated on Thu Nov 11 2021.
2+
This document was automatically generated on Fri Nov 12 2021.
33

44
## List of dependencies
55

package-lock.json

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-connect/src/stores/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,12 @@ const Store = Reflux.createStore({
983983
hostname,
984984
authMechanism,
985985
} = this.state.connectionModel;
986-
const { isAws, isAzure, isGcp } = await getCloudInfo(hostname);
986+
const { isAws, isAzure, isGcp } = await getCloudInfo(hostname)
987+
.catch((err) => {
988+
debug('getCloudInfo failed', err);
989+
return {};
990+
});
991+
987992
const isPublicCloud = isAws || isAzure || isGcp;
988993
const publicCloudName = isAws ? 'AWS' : isAzure ? 'Azure' : isGcp ? 'GCP' : '';
989994

@@ -1042,7 +1047,9 @@ const Store = Reflux.createStore({
10421047
// in another plugin.
10431048
this.StatusActions.showIndeterminateProgressBar();
10441049

1045-
void this._trackConnectionInfo();
1050+
void this._trackConnectionInfo().catch((err) => {
1051+
debug('_trackConnectionInfo failed', err);
1052+
});
10461053
},
10471054

10481055
/**

packages/compass-e2e-tests/helpers/commands/open-tour-modal.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,7 @@ module.exports = function (app) {
77
const { client } = app;
88

99
await client.execute(() => {
10-
const menu = require('electron').remote.Menu.getApplicationMenu();
11-
let subMenu;
12-
for (let i = 0; i < menu.getItemCount(); i++) {
13-
if (menu.getLabelAt(i) === '&Help') {
14-
subMenu = menu.items[i].submenu;
15-
break;
16-
}
17-
}
18-
if (!subMenu) {
19-
throw new Error('Could not find Help submenu');
20-
}
21-
for (let i = 0; i < subMenu.getItemCount(); i++) {
22-
if (subMenu.getLabelAt(i).endsWith('Overview')) {
23-
subMenu.items[i].click();
24-
return;
25-
}
26-
}
27-
throw new Error('Could not find overview item to click');
10+
require('electron').ipcRenderer.emit('window:show-compass-tour');
2811
});
2912

3013
const featureTourModalElement = await client.$(Selectors.FeatureTourModal);

packages/data-service/src/instance-detail-helper.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,65 @@ describe('instance-detail-helper', function () {
253253
expect(dbs).to.have.nested.property('foo.bar').deep.eq([]);
254254
});
255255

256+
context('with known resources', function () {
257+
it('ignores cluster privileges', function () {
258+
const dbs = extractPrivilegesByDatabaseAndCollection([
259+
{ resource: { db: 'foo', collection: 'bar' }, actions: [] },
260+
{ resource: { db: 'buz', collection: 'bla' }, actions: [] },
261+
{ resource: { cluster: true }, actions: [] },
262+
]);
263+
264+
expect(dbs).to.deep.eq({
265+
foo: {
266+
bar: [],
267+
},
268+
buz: {
269+
bla: [],
270+
},
271+
});
272+
});
273+
274+
it('ignores anyResource privileges', function () {
275+
const dbs = extractPrivilegesByDatabaseAndCollection([
276+
{ resource: { db: 'foo', collection: 'bar' }, actions: [] },
277+
{ resource: { db: 'buz', collection: 'bla' }, actions: [] },
278+
{ resource: { anyResource: true }, actions: [] },
279+
]);
280+
281+
expect(dbs).to.deep.eq({
282+
foo: {
283+
bar: [],
284+
},
285+
buz: {
286+
bla: [],
287+
},
288+
});
289+
});
290+
});
291+
292+
context('with unknown resources', function () {
293+
it("ignores everything that doesn't have database and collection in resource", function () {
294+
const dbs = extractPrivilegesByDatabaseAndCollection([
295+
{ resource: { db: 'foo', collection: 'bar' }, actions: [] },
296+
{ resource: { db: 'buz', collection: 'bla' }, actions: [] },
297+
{ resource: { this: true }, actions: [] },
298+
{ resource: { is: true }, actions: [] },
299+
{ resource: { not: true }, actions: [] },
300+
{ resource: { valid: true }, actions: [] },
301+
{ resource: { resource: true }, actions: [] },
302+
] as any);
303+
304+
expect(dbs).to.deep.eq({
305+
foo: {
306+
bar: [],
307+
},
308+
buz: {
309+
bla: [],
310+
},
311+
});
312+
});
313+
});
314+
256315
it('keeps records for all collections in a database', function () {
257316
const dbs = extractPrivilegesByDatabaseAndCollection([
258317
{ resource: { db: 'foo', collection: 'bar' }, actions: [] },

packages/data-service/src/instance-detail-helper.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,26 @@ export function extractPrivilegesByDatabaseAndCollection(
176176

177177
const result: DatabaseCollectionPrivileges = {};
178178

179-
for (const {
180-
resource: { db, collection },
181-
actions,
182-
} of filteredPrivileges) {
183-
if (result[db]) {
184-
Object.assign(result[db], { [collection]: actions });
185-
} else {
186-
result[db] = { [collection]: actions };
179+
for (const { resource, actions } of filteredPrivileges) {
180+
// Documented resources include roles for dbs/colls, cluster, or in rare cases
181+
// anyResource, additionally there seem to be undocumented ones like
182+
// system_buckets and who knows what else. To make sure we are only cover
183+
// cases that we can meaningfully handle here, roles for the
184+
// databases/collections, we are skipping all roles where these are
185+
// undefined
186+
//
187+
// See: https://docs.mongodb.com/manual/reference/resource-document/#std-label-resource-document
188+
if (
189+
typeof resource.db !== 'undefined' &&
190+
typeof resource.collection !== 'undefined'
191+
) {
192+
const { db, collection } = resource;
193+
194+
if (result[db]) {
195+
Object.assign(result[db], { [collection]: actions });
196+
} else {
197+
result[db] = { [collection]: actions };
198+
}
187199
}
188200
}
189201

@@ -216,14 +228,6 @@ function isNotAuthorized(err: AnyError) {
216228
return new RegExp('not (authorized|allowed)').test(msg);
217229
}
218230

219-
function isMongosLocalException(err: AnyError) {
220-
if (!err) {
221-
return false;
222-
}
223-
const msg = err.message || JSON.stringify(err);
224-
return new RegExp('database through mongos').test(msg);
225-
}
226-
227231
function ignoreNotAuthorized<T>(fallback: T): (err: AnyError) => Promise<T> {
228232
return (err: AnyError) => {
229233
if (isNotAuthorized(err)) {

packages/data-service/src/run-command.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ export type ConnectionStatus = {
1111
export type ConnectionStatusWithPrivileges = ConnectionStatus & {
1212
authInfo: {
1313
authenticatedUserPrivileges: {
14-
resource: { db: string; collection: string };
14+
resource:
15+
| { db?: never; collection?: never; cluster: true; anyResource?: never }
16+
| {
17+
db: string;
18+
collection: string;
19+
cluster?: never;
20+
anyResource?: never;
21+
}
22+
| {
23+
db?: never;
24+
collection?: never;
25+
cluster?: never;
26+
anyResource: true;
27+
};
1528
actions: string[];
1629
}[];
1730
};

0 commit comments

Comments
 (0)