Skip to content

Commit 0485c2c

Browse files
well this all works I guess
1 parent e8a3866 commit 0485c2c

File tree

5 files changed

+111
-43
lines changed

5 files changed

+111
-43
lines changed

configs/webpack-config-compass/src/webpack-plugin-start-electron.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ export class WebpackPluginStartElectron {
166166
this.logger.info(
167167
'- Ctrl+A to restart the main process with extra arguments'
168168
);
169+
this.logger.info('appPath: ', this.appPath);
170+
this.logger.info('extraArgs: ', extraArgs);
171+
this.logger.info('env:', process.env);
169172
this.electronProcess = spawn(
170173
// XXX: in non-electron environment this import returns path to the binary
171174
electronBinaryPath as unknown as string,

packages/compass-e2e-tests/helpers/compass.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ async function startCompassElectron(
591591
name: string,
592592
opts: StartCompassOptions = {}
593593
): Promise<Compass> {
594+
console.log('start compass electron...');
594595
runCounter++;
595596
const { testPackagedApp, binary } = await getCompassExecutionParameters();
596597

@@ -617,6 +618,8 @@ async function startCompassElectron(
617618
'--log-level=0'
618619
);
619620

621+
chromeArgs.push('--host-rules=MAP * 127.0.0.1');
622+
620623
if (opts.extraSpawnArgs) {
621624
chromeArgs.push(...opts.extraSpawnArgs);
622625
}
@@ -638,7 +641,8 @@ async function startCompassElectron(
638641
// For webdriverio env we are changing appName so that keychain records do not
639642
// overlap with anything else. But leave it alone when testing auto-update.
640643
if (!process.env.HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE) {
641-
process.env.HADRON_PRODUCT_NAME_OVERRIDE = 'MongoDB Compass WebdriverIO';
644+
process.env.HADRON_PRODUCT_NAME_OVERRIDE =
645+
'MongoDB Compassssssss WebdriverIO';
642646
}
643647

644648
// Guide cues might affect too many tests in a way where the auto showing of the cue prevents
@@ -922,7 +926,11 @@ export async function rebuildNativeModules(
922926
export async function compileCompassAssets(
923927
compassPath = COMPASS_DESKTOP_PATH
924928
): Promise<void> {
925-
await promisify(execFile)('npm', ['run', 'compile'], { cwd: compassPath });
929+
console.log('path nonsense: ', compassPath);
930+
await promisify(execFile)('npm', ['run', 'compile'], {
931+
maxBuffer: 256 * 1024 * 1024,
932+
cwd: compassPath,
933+
});
926934
}
927935

928936
async function getCompassBuildMetadata(): Promise<BinPathOptions> {
@@ -1035,6 +1043,7 @@ export async function init(
10351043
opts: StartCompassOptions = {}
10361044
): Promise<Compass> {
10371045
name = pathName(name ?? formattedDate());
1046+
console.log('process pid inside init: ', name, process.pid);
10381047

10391048
// Unfortunately mocha's type is that this.test inside a test or hook is
10401049
// optional even though it always exists. So we have a lot of

packages/compass-e2e-tests/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function main() {
5454
const e2eTestGroup = context.testGroup;
5555
const e2eTestFilter = context.testFilter;
5656

57-
const tests = (
57+
let tests = (
5858
await glob(`tests/**/${e2eTestFilter}.{test,spec}.ts`, {
5959
cwd: __dirname,
6060
})
@@ -67,6 +67,7 @@ async function main() {
6767
return index >= minGroupIndex && index <= maxGroupIndex;
6868
})
6969
.sort((a, b) => {
70+
// this comment is wrong
7071
// The only test file that's interested in the first-run experience (at the
7172
// time of writing) is time-to-first-query.ts and that happens to be
7273
// alphabetically right at the end. Which is fine, but the first test to run
@@ -82,18 +83,25 @@ async function main() {
8283
}
8384
});
8485

86+
tests = tests.filter((test) => test === 'tests/no-network-traffic.test.ts');
87+
88+
console.log('test files: ', tests);
8589
debug('Test files:', tests);
8690

8791
if (tests.length === 0) {
8892
throw new Error('No tests to run');
8993
}
9094

95+
console.log('before mocha 1');
96+
9197
const mocha = new Mocha({
9298
timeout: context.mochaTimeout,
9399
bail: context.mochaBail,
94100
reporter: require.resolve('@mongodb-js/mocha-config-compass/reporter'),
95101
});
96102

103+
console.log('after mocha 1');
104+
97105
// @ts-expect-error mocha types are incorrect, global setup this is bound to
98106
// runner, not context
99107
mocha.globalSetup(mochaGlobalSetup);
@@ -111,9 +119,11 @@ async function main() {
111119
mocha.addFile(path.join(__dirname, testPath));
112120
});
113121

122+
console.log('Running e2e ...');
114123
debug('Running E2E tests');
115124
runnerPromise = new Promise((resolve) => {
116125
mocha.run((failures: number) => {
126+
console.log('on finish??');
117127
debug('Finished running e2e tests', { failures });
118128
process.exitCode = failures ? 1 : 0;
119129
// Since the webdriverio update something is messing with the terminal's
@@ -161,4 +171,6 @@ async function run() {
161171
await main();
162172
}
163173

174+
console.log('running???????');
175+
164176
void run();

packages/compass-e2e-tests/tests/no-network-traffic.test.ts

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { promises as fs } from 'fs';
88
import path from 'path';
99
import os from 'os';
1010

11+
import http from 'http';
12+
import https from 'https';
13+
1114
/**
1215
* @securityTest Enhanced Network Isolation Tests
1316
*
@@ -22,11 +25,12 @@ describe('networkTraffic: false / Isolated Edition', function () {
2225
let i = 0;
2326

2427
before(function () {
28+
console.log('an early before in our test of choice');
2529
skipForWeb(this, 'cli params not available in compass-web');
2630

2731
if (process.platform !== 'linux') {
2832
// No strace on other platforms
29-
return this.skip();
33+
// return this.skip();
3034
}
3135
});
3236

@@ -56,78 +60,81 @@ describe('networkTraffic: false / Isolated Edition', function () {
5660
const wrapperFile = path.join(tmpdir, 'wrap.sh');
5761
await fs.writeFile(
5862
wrapperFile,
59-
`#!/bin/bash\nulimit -c 0; exec strace -f -e connect -qqq -o '${outfile}' '${binary}' "$@"\n`
63+
`#!/bin/bash\nulimit -c 0; '${binary}' "$@"\n`
6064
);
6165
await fs.chmod(wrapperFile, 0o755);
6266
return wrapperFile;
6367
}
6468

69+
console.log('process pid inside no network test: ', process.pid);
6570
const compass = await init(this.test?.fullTitle(), {
6671
extraSpawnArgs: ['--no-network-traffic'],
6772
wrapBinary,
6873
// TODO(COMPASS-8166): firstRun: true seems to result in network traffic.
6974
// Probably the welcome modal.
70-
firstRun: false,
75+
firstRun: true,
7176
});
7277
const browser = compass.browser;
7378

79+
console.log('set up default connections...');
7480
await browser.setupDefaultConnections();
7581

7682
{
7783
// TODO: Remove this once we are including https://github.com/mongodb-js/mongosh/pull/1349
7884
const exitOnDisconnectFile = path.join(tmpdir, 'exitOnDisconnect.js');
7985
await fs.writeFile(
8086
exitOnDisconnectFile,
81-
'process.once("disconnect", () => process.exit())'
87+
'process.once("disconnect", () => {})'
8288
);
89+
console.log('browser.execute...');
8390
await browser.execute((exitOnDisconnectFile) => {
8491
process.env.NODE_OPTIONS ??= '';
8592
process.env.NODE_OPTIONS += ` --require "${exitOnDisconnectFile}"`;
8693
}, exitOnDisconnectFile);
8794
}
8895

8996
try {
97+
console.log('connect to defaults...');
9098
await browser.connectToDefaults();
9199
} finally {
92100
await cleanup(compass);
93101
}
94102

95-
const straceLog = await fs.readFile(outfile, 'utf8');
96-
const connectCalls = straceLog.matchAll(/\bconnect\s*\((?<args>.*)\) =/g);
97-
const connectTargets = new Set<string>();
98-
for (const { groups } of connectCalls) {
99-
const args = groups!.args;
100-
// Possible format for the address argument in 'args':
101-
// sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"
102-
// sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")
103-
// sa_family=AF_INET6, sin6_port=htons(80), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "2606:2800:220:1:248:1893:25c8:1946", &sin6_addr), sin6_scope_id=0
104-
if (!args.includes('AF_INET')) continue;
105-
const match = args.match(
106-
/sa_family=AF_INET6?.*sin6?_port=htons\((?<port>\d+)\).*inet_(addr\("(?<ipv4>[^"]+)"\)|pton\(AF_INET6,\s*"(?<ipv6>[^"]+)")/
107-
)?.groups;
108-
if (!match) {
109-
throw new Error(`Unknown traced connect() target: ${args}`);
110-
}
111-
connectTargets.add(
112-
match.ipv4
113-
? `${match.ipv4}:${match.port}`
114-
: `[${match.ipv6}]:${match.port}`
115-
);
116-
}
103+
// const straceLog = await fs.readFile(outfile, 'utf8');
104+
// const connectCalls = straceLog.matchAll(/\bconnect\s*\((?<args>.*)\) =/g);
105+
// const connectTargets = new Set<string>();
106+
// for (const { groups } of connectCalls) {
107+
// const args = groups!.args;
108+
// // Possible format for the address argument in 'args':
109+
// // sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"
110+
// // sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")
111+
// // sa_family=AF_INET6, sin6_port=htons(80), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "2606:2800:220:1:248:1893:25c8:1946", &sin6_addr), sin6_scope_id=0
112+
// if (!args.includes('AF_INET')) continue;
113+
// const match = args.match(
114+
// /sa_family=AF_INET6?.*sin6?_port=htons\((?<port>\d+)\).*inet_(addr\("(?<ipv4>[^"]+)"\)|pton\(AF_INET6,\s*"(?<ipv6>[^"]+)")/
115+
// )?.groups;
116+
// if (!match) {
117+
// throw new Error(`Unknown traced connect() target: ${args}`);
118+
// }
119+
// connectTargets.add(
120+
// match.ipv4
121+
// ? `${match.ipv4}:${match.port}`
122+
// : `[${match.ipv6}]:${match.port}`
123+
// );
124+
// }
117125

118-
if (
119-
[...connectTargets].some(
120-
(target) => !/^127.0.0.1:|^\[::1\]:/.test(target)
121-
)
122-
) {
123-
throw new Error(`Connected to unexpected host! ${[...connectTargets]}`);
124-
}
125-
if (![...connectTargets].some((target) => /:27091$/.test(target))) {
126-
throw new Error(
127-
`Missed connection to database server in connect trace! ${[
128-
...connectTargets,
129-
]}`
130-
);
131-
}
126+
// const unexpectedHosts = [...connectTargets].filter(
127+
// (target) => !/^127.0.0.1:|^\[::1\]:/.test(target)
128+
// );
129+
// if (unexpectedHosts.length > 0) {
130+
// throw new Error(`Connected to unexpected host! ${[...unexpectedHosts]}`);
131+
// }
132+
// if (![...connectTargets].some((target) => /:27091$/.test(target))) {
133+
// throw new Error(
134+
// `Missed connection to database server in connect trace! ${[
135+
// ...connectTargets,
136+
// ]}`
137+
// );
138+
// }
132139
});
133140
});

packages/compass/src/main/application.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { CompassTelemetry } from './telemetry';
1111
import { CompassWindowManager } from './window-manager';
1212
import { CompassMenu } from './menu';
1313
import { setupCSFLELibrary } from './setup-csfle-library';
14+
15+
import http from 'http';
16+
import https from 'https';
1417
import type {
1518
ParsedGlobalPreferencesResult,
1619
PreferencesAccess,
@@ -129,6 +132,40 @@ class CompassApplication {
129132
// Accessing isEncryptionAvailable is not allowed when app is not ready on Windows
130133
// https://github.com/electron/electron/issues/33640
131134
await app.whenReady();
135+
136+
// Intercept HTTP requests
137+
const originalHttpRequest = http.request;
138+
http.request = function (...args: any[]) {
139+
console.log('HTTP Request:', args);
140+
log.error(
141+
mongoLogId(1_001_818_275),
142+
'DJECHLIN',
143+
'DJECHLIN HTTP REQUEST HAPPENED OH NO',
144+
{ message: args }
145+
);
146+
return originalHttpRequest.apply(this, args as any);
147+
};
148+
149+
// Intercept HTTPS requests
150+
const originalHttpsRequest = https.request;
151+
https.request = function (...args: any[]) {
152+
console.log('HTTPS Request:', args);
153+
log.error(
154+
mongoLogId(1_001_818_276),
155+
'DJECHLIN',
156+
'DJECHLIN HTTPS SSSSSSSSSS REQUEST HAPPENED OH NO',
157+
{ message: args }
158+
);
159+
return originalHttpsRequest.apply(this, args as any);
160+
};
161+
162+
// If you want to intercept at an even lower level:
163+
const originalClientRequest = http.ClientRequest;
164+
http.ClientRequest = function () {
165+
console.log('Client Request:', arguments);
166+
return new originalClientRequest(arguments as any);
167+
} as any;
168+
132169
log.info(
133170
mongoLogId(1_001_000_307),
134171
'Application',

0 commit comments

Comments
 (0)