Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 88 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/atlas-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@mongodb-js/compass-user-data": "^0.11.2",
"@mongodb-js/compass-utils": "^0.9.23",
"@mongodb-js/connection-info": "^0.24.0",
"@mongodb-js/devtools-connect": "^3.9.7",
"@mongodb-js/devtools-connect": "^3.12.0",
"@mongodb-js/devtools-proxy-support": "^0.5.5",
"@mongodb-js/oidc-plugin": "^2.0.4",
"compass-preferences-model": "^2.66.3",
Expand Down
6 changes: 5 additions & 1 deletion packages/compass-e2e-tests/helpers/compass-web-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ export const getAtlasCloudSandboxDefaultConnections = (
str.password = dbPassword;
return {
id: name,
connectionOptions: { connectionString: String(str) },
connectionOptions: {
connectionString: String(str),
// System CA certificates are not available in the browser environment
useSystemCA: false,
},
favorite: { name },
};
});
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export function createAgent(): void {
// The original can return 'undefined' as well
}
export function isExistingAgentInstance(): boolean {
return false;
}
export function useOrCreateAgent(): void {
// The original can return 'undefined' as well
}
Expand All @@ -10,14 +13,17 @@ export function createSocks5Tunnel(): void {
export function hookLogger(): void {
// no-op
}
export function createFetch(): never {
throw new Error('node-fetch like-API not available in compass-web');
export function createFetch(): typeof fetch {
return async () =>
Promise.reject(new Error('node-fetch not available in compass web'));
}
export function systemCA(): never {
throw new Error('system CA access not available in compass-web');
export async function systemCA() {
await Promise.reject(
new Error('system CA access not available in compass-web')
);
}
export function resetSystemCACache(): never {
throw new Error('system CA access not available in compass-web');
throw new Error('reset system CA access not available in compass-web');
}

// Explicitly web-compatible
Expand Down
10 changes: 10 additions & 0 deletions packages/compass-web/polyfills/@mongodb-js/oidc-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function hookLoggerToMongoLogWriter() {}
export function createMongoDBOIDCPlugin({ logger }: any) {
return {
mongoClientOptions: {},
logger,
/* eslint-disable @typescript-eslint/require-await */
serialize: async () => '',
destroy: () => {},
};
}
8 changes: 5 additions & 3 deletions packages/compass-web/polyfills/net/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ class Socket extends Duplex {
lookup?: ConnectionOptions['lookup'];
tls?: boolean;
}) {
// WS does not support callback lookup
if ((lookup?.length ?? 0) > 0) lookup = undefined;
Comment on lines +31 to +32
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a little inconvenient that this synchronous for CompassWeb and async everywhere else even if it is returning a dummy value. Should we refactor to return the cluster info in a callback?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are deliberatly not defining this function in a way that would mess up with the original interface as in theory it should be still passed down and be callable by the internals that we don't control and behave in a way that is matching the net interface

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That totally makes sense. Should it throw then if it's given the interface it doesn't support? or more accurately invoke the given callback with an error? any callers will probably hang if we don't do something with it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we should probably make the implementation in the connection storage for web fully matching the interface and call a callback with an error


const { wsURL, ...atlasOptions } =
lookup?.() ?? ({} as { wsURL?: string; clusterName?: string });

this._ws = new WebSocket(wsURL ?? '/ws-proxy');
this._ws.binaryType = 'arraybuffer';
this._ws.addEventListener(
Expand Down Expand Up @@ -157,8 +161,6 @@ export { isIPv4, isIPv6 } from 'is-ip';
export const isIP = (input: string) => ipVersion(input) ?? 0;
export const createConnection = (options: { host: string; port: number }) => {
const socket = new Socket();
setTimeout(() => {
socket.connect(options);
});
socket.connect(options);
Comment on lines -160 to +164
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was making an exception uncatchable by the try/catch wrapping connect(). The exception was momentary while I was debugging stuff so not a code path used in practice, but curious to know why we put this in a setTimeout?

return socket;
};
7 changes: 7 additions & 0 deletions packages/compass-web/polyfills/os-dns-native/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { resolveSrv, resolveTxt } from '../dns';

export const wasNativelyLookedUp = () => false;
export const withNodeFallback = {
resolveSrv,
resolveTxt,
};
24 changes: 22 additions & 2 deletions packages/compass-web/sandbox/sandbox-connection-storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,31 @@ class SandboxConnectionStorage implements ConnectionStorage {
return [info.id, info];
})
);

// Ensure useSystemCA is set to false for all connections since system CA
// certificates are not available in the browser environment
private normalizeConnectionInfo(info: ConnectionInfo): ConnectionInfo {
return {
...info,
connectionOptions: {
...info.connectionOptions,
useSystemCA: false,
},
};
}

loadAll(): Promise<ConnectionInfo[]> {
return Promise.resolve(Array.from(this._connections.values()));
return Promise.resolve(
Array.from(this._connections.values()).map((info) =>
this.normalizeConnectionInfo(info)
)
);
}
load({ id }: { id: string }): Promise<ConnectionInfo | undefined> {
return Promise.resolve(this._connections.get(id));
const info = this._connections.get(id);
return Promise.resolve(
info ? this.normalizeConnectionInfo(info) : undefined
);
}
save({ connectionInfo }: { connectionInfo: ConnectionInfo }): Promise<void> {
this._connections.set(connectionInfo.id, connectionInfo);
Expand Down
1 change: 1 addition & 0 deletions packages/compass-web/src/connection-storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class AtlasCloudConnectionStorage
...connectionInfo,
connectionOptions: {
...connectionInfo.connectionOptions,
useSystemCA: false,
lookup: () => {
return {
wsURL: this.atlasService.driverProxyEndpoint(
Expand Down
10 changes: 2 additions & 8 deletions packages/compass-web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = (env, args) => {
'@mongodb-js/devtools-proxy-support': localPolyfill(
'@mongodb-js/devtools-proxy-support'
),
'@mongodb-js/oidc-plugin': localPolyfill('@mongodb-js/oidc-plugin'),

...(config.mode === 'production'
? {
Expand All @@ -56,14 +57,6 @@ module.exports = (env, args) => {
}
: {}),

// Replace 'devtools-connect' with a package that just directly connects
// using the driver (= web-compatible driver) logic, because devtools-connect
// contains a lot of logic that makes sense in a desktop application/CLI but
// not in a web environment (DNS resolution, OIDC, CSFLE/QE, etc.)
'@mongodb-js/devtools-connect': localPolyfill(
'@mongodb-js/devtools-connect'
),

// TODO(COMPASS-7407): compass-logging
// hard to disable the whole thing while there are direct dependencies
// on log-writer
Expand Down Expand Up @@ -124,6 +117,7 @@ module.exports = (env, args) => {
os: require.resolve('os-browserify/browser'),
crypto: require.resolve('crypto-browserify'),
dns: localPolyfill('dns'),
'os-dns-native': localPolyfill('os-dns-native'),
// Built-in Node.js modules imported by the driver directly and used in
// ways that requires us to provide a no-op polyfill
zlib: localPolyfill('zlib'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ describe('ConnectionStorage', function () {
oidc: {},
fleOptions: { storeCredentials: false },
lookup: () => ({} as any),
useSystemCA: true,
};
await connectionStorage.save({
connectionInfo: {
Expand Down
Loading
Loading