1
- /* eslint-disable no-console */
1
+ /* eslint-disable no-console, @typescript-eslint/no-non-null-assertion, chai-friendly/no-unused-expressions */
2
2
import { spawn } from 'child_process' ;
3
3
import assert from 'assert' ;
4
4
import { once } from 'events' ;
5
5
import { redactURICredentials } from '@mongosh/history' ;
6
6
import fleSmokeTestScript from './smoke-tests-fle' ;
7
+ import { buildInfo } from './build-info' ;
7
8
8
9
/**
9
10
* Run smoke tests on an executable, e.g.
@@ -20,11 +21,23 @@ export async function runSmokeTests(smokeTestServer: string | undefined, executa
20
21
assert ( ! ! smokeTestServer , 'Make sure MONGOSH_SMOKE_TEST_SERVER is set in CI' ) ;
21
22
}
22
23
23
- for ( const { input, output, testArgs } of [ {
24
+ const skipFipsWithOpenSSL3 = process . env . MONGOSH_SMOKE_TEST_OS_SKIP_FIPS_WITH_OPENSSL3 && buildInfo ( ) . opensslVersion . startsWith ( '3.' ) ;
25
+ const expectFipsSupport = ! ! process . env . MONGOSH_SMOKE_TEST_OS_HAS_FIPS_SUPPORT && buildInfo ( ) . sharedOpenssl ;
26
+ console . log ( 'FIPS support required to pass?' , { skipFipsWithOpenSSL3, expectFipsSupport } ) ;
27
+
28
+ for ( const { input, output, testArgs, includeStderr } of [ {
24
29
input : 'print("He" + "llo" + " Wor" + "ld!")' ,
25
30
output : / H e l l o W o r l d ! / ,
31
+ includeStderr : false ,
26
32
testArgs : [ '--nodb' ] ,
27
- } ] . concat ( smokeTestServer ? [ {
33
+ } ] . concat ( skipFipsWithOpenSSL3 ? [ ] : [ {
34
+ input : 'crypto.createHash("md5").update("hello").digest("hex")' ,
35
+ output : expectFipsSupport ?
36
+ / d i s a b l e d f o r F I P S / i :
37
+ / d i s a b l e d f o r F I P S | C o u l d n o t e n a b l e F I P S m o d e / i,
38
+ includeStderr : true ,
39
+ testArgs : [ '--tlsFIPSMode' , '--nodb' ]
40
+ } ] ) . concat ( smokeTestServer ? [ {
28
41
input : `
29
42
const dbname = "testdb_simplesmoke" + new Date().getTime();
30
43
use(dbname);
@@ -34,13 +47,15 @@ export async function runSmokeTests(smokeTestServer: string | undefined, executa
34
47
}
35
48
db.dropDatabase();` ,
36
49
output : / T e s t s u c c e e d e d / ,
50
+ includeStderr : false ,
37
51
testArgs : [ smokeTestServer as string ]
38
52
} , {
39
53
input : fleSmokeTestScript ,
40
54
output : / T e s t s u c c e e d e d | T e s t s k i p p e d / ,
55
+ includeStderr : false ,
41
56
testArgs : [ smokeTestServer as string ]
42
57
} ] : [ ] ) ) {
43
- await runSmokeTest ( executable , [ ...args , ...testArgs ] , input , output ) ;
58
+ await runSmokeTest ( executable , [ ...args , ...testArgs ] , input , output , includeStderr ) ;
44
59
}
45
60
console . log ( 'all tests passed' ) ;
46
61
}
@@ -53,16 +68,18 @@ export async function runSmokeTests(smokeTestServer: string | undefined, executa
53
68
* @param input stdin contents of the executable
54
69
* @param output Expected contents of stdout
55
70
*/
56
- async function runSmokeTest ( executable : string , args : string [ ] , input : string , output : RegExp ) : Promise < void > {
71
+ async function runSmokeTest ( executable : string , args : string [ ] , input : string , output : RegExp , includeStderr ?: boolean ) : Promise < void > {
57
72
const proc = spawn ( executable , [ ...args ] , {
58
- stdio : [ 'pipe' , 'pipe' , 'inherit' ]
73
+ stdio : [ 'pipe' , 'pipe' , includeStderr ? 'pipe' : 'inherit' ]
59
74
} ) ;
60
75
let stdout = '' ;
61
- proc . stdout . setEncoding ( 'utf8' ) . on ( 'data' , ( chunk ) => { stdout += chunk ; } ) ;
62
- proc . stdin . end ( input ) ;
63
- await once ( proc . stdout , 'end' ) ;
76
+ let stderr = '' ;
77
+ proc . stdout ! . setEncoding ( 'utf8' ) . on ( 'data' , ( chunk ) => { stdout += chunk ; } ) ;
78
+ proc . stderr ?. setEncoding ( 'utf8' ) . on ( 'data' , ( chunk ) => { stderr += chunk ; } ) ;
79
+ proc . stdin ! . end ( input ) ;
80
+ await once ( proc . stdout ! , 'end' ) ;
64
81
try {
65
- assert . match ( stdout , output ) ;
82
+ assert . match ( includeStderr ? ` ${ stdout } \n ${ stderr } ` : stdout , output ) ;
66
83
console . error ( { status : 'success' , input, output, stdout, executable, args : args . map ( arg => redactURICredentials ( arg ) ) } ) ;
67
84
} catch ( err : any ) {
68
85
console . error ( { status : 'failure' , input, output, stdout, executable, args : args . map ( arg => redactURICredentials ( arg ) ) } ) ;
0 commit comments