@@ -8,6 +8,9 @@ import { promises as fs } from 'fs';
88import path from 'path' ;
99import 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 ( / \b c o n n e c t \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- / s a _ f a m i l y = A F _ I N E T 6 ? .* s i n 6 ? _ p o r t = h t o n s \( (?< port > \d + ) \) .* i n e t _ ( a d d r \( " (?< ipv4 > [ ^ " ] + ) " \) | p t o n \( A F _ I N E T 6 , \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 ) => ! / ^ 1 2 7 .0 .0 .1 : | ^ \[ : : 1 \] : / . test ( target )
121- )
122- ) {
123- throw new Error ( `Connected to unexpected host! ${ [ ...connectTargets ] } ` ) ;
124- }
125- if ( ! [ ...connectTargets ] . some ( ( target ) => / : 2 7 0 9 1 $ / . 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} ) ;
0 commit comments