Skip to content

Commit 9138b22

Browse files
committed
Merge branch 'main' into COMPASS-8441-global0=-writes-tests
2 parents 9e279bc + 2f2a8c6 commit 9138b22

File tree

86 files changed

+1724
-912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1724
-912
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 Thu Nov 07 2024.
2+
This document was automatically generated on Mon Nov 11 2024.
33

44
## List of dependencies
55

configs/webpack-config-compass/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"cli-progress": "^3.9.1",
7474
"core-js": "^3.17.3",
7575
"css-loader": "^4.3.0",
76-
"electron": "^32.2.2",
76+
"electron": "^32.2.3",
7777
"html-webpack-plugin": "^5.6.0",
7878
"less": "^3.13.1",
7979
"less-loader": "^10.0.1",

docs/tracking-plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Compass Tracking Plan
33

4-
Generated on Thu, Nov 7, 2024 at 11:58 PM
4+
Generated on Mon, Nov 11, 2024 at 10:33 AM
55

66
## Table of Contents
77

package-lock.json

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

packages/atlas-service/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"email": "[email protected]"
1414
},
1515
"homepage": "https://github.com/mongodb-js/compass",
16-
"version": "0.31.1",
16+
"version": "0.32.0",
1717
"repository": {
1818
"type": "git",
1919
"url": "https://github.com/mongodb-js/compass.git"
@@ -83,12 +83,11 @@
8383
"@mongodb-js/devtools-proxy-support": "^0.4.1",
8484
"@mongodb-js/oidc-plugin": "^1.1.1",
8585
"hadron-app-registry": "^9.2.7",
86-
"compass-preferences-model": "^2.29.3",
87-
"electron": "^32.2.2",
86+
"compass-preferences-model": "^2.30.0",
87+
"electron": "^32.2.3",
8888
"hadron-ipc": "^3.2.25",
8989
"lodash": "^4.17.21",
9090
"react": "^17.0.2",
91-
"react-redux": "^8.1.3",
9291
"redux": "^4.2.1",
9392
"redux-thunk": "^2.4.2"
9493
}

packages/atlas-service/src/atlas-auth-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AtlasUserInfo } from './util';
44
export type ArgsWithSignal<T = Record<string, unknown>> = T & {
55
signal?: AbortSignal;
66
};
7-
export type SignInPrompt = 'none' | 'ai-promo-modal';
7+
export type SignInPrompt = 'none';
88

99
type AtlasAuthServiceEvents = {
1010
'signed-in': [];

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,30 @@ describe('AtlasService', function () {
132132
);
133133
expect(getAuthHeadersFn.calledOnce).to.be.true;
134134
});
135+
136+
it('should set CSRF headers when available', async function () {
137+
const fetchStub = sandbox.stub().resolves({ status: 200, ok: true });
138+
global.fetch = fetchStub;
139+
document.head.append(
140+
(() => {
141+
const el = document.createElement('meta');
142+
el.setAttribute('name', 'csrf-token');
143+
el.setAttribute('content', 'token');
144+
return el;
145+
})()
146+
);
147+
document.head.append(
148+
(() => {
149+
const el = document.createElement('meta');
150+
el.setAttribute('name', 'CSRF-TIME');
151+
el.setAttribute('content', 'time');
152+
return el;
153+
})()
154+
);
155+
await atlasService.fetch('/foo/bar', { method: 'POST' });
156+
expect(fetchStub.firstCall.lastArg.headers).to.deep.eq({
157+
'X-CSRF-Time': 'time',
158+
'X-CSRF-Token': 'token',
159+
});
160+
});
135161
});

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ function normalizePath(path?: string) {
1919
return encodeURI(path);
2020
}
2121

22+
function getCSRFHeaders() {
23+
return {
24+
'X-CSRF-Token':
25+
document
26+
.querySelector('meta[name="csrf-token" i]')
27+
?.getAttribute('content') ?? '',
28+
'X-CSRF-Time':
29+
document
30+
.querySelector('meta[name="csrf-time" i]')
31+
?.getAttribute('content') ?? '',
32+
};
33+
}
34+
35+
function shouldAddCSRFHeaders(method = 'get') {
36+
return !/^(get|head|options|trace)$/.test(method.toLowerCase());
37+
}
38+
2239
export class AtlasService {
2340
private config: AtlasServiceConfig;
2441
constructor(
@@ -60,6 +77,7 @@ export class AtlasService {
6077
...init,
6178
headers: {
6279
...this.options?.defaultHeaders,
80+
...(shouldAddCSRFHeaders(init?.method) && getCSRFHeaders()),
6381
...init?.headers,
6482
},
6583
});

packages/atlas-service/src/compass-atlas-auth-service.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { ipcRenderer } from 'hadron-ipc';
22
import type { CompassAuthService as AtlasServiceMain } from './main';
3-
import {
4-
signInWithModalPrompt,
5-
signInWithoutPrompt,
6-
} from './store/atlas-signin-reducer';
3+
import { signInWithoutPrompt } from './store/atlas-signin-reducer';
74
import { getStore } from './store/atlas-signin-store';
85
import { AtlasAuthService } from './atlas-auth-service';
96
import type { ArgsWithSignal, SignInPrompt } from './atlas-auth-service';
@@ -46,8 +43,6 @@ export class CompassAtlasAuthService extends AtlasAuthService {
4643
switch (promptType) {
4744
case 'none':
4845
return getStore().dispatch(signInWithoutPrompt({ signal }));
49-
case 'ai-promo-modal':
50-
return getStore().dispatch(signInWithModalPrompt({ signal }));
5146
default:
5247
return this.ipc.signIn({ signal });
5348
}

packages/atlas-service/src/renderer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { registerHadronPlugin } from 'hadron-app-registry';
22
import { activatePlugin } from './store/atlas-signin-store';
33
import { atlasAuthServiceLocator } from './provider';
4-
import { AtlasSignIn } from './components';
54

65
export const AtlasAuthPlugin = registerHadronPlugin(
76
{
87
name: 'AtlasAuth',
9-
component: AtlasSignIn,
8+
component: () => null,
109
activate: activatePlugin,
1110
},
1211
{

0 commit comments

Comments
 (0)