diff --git a/.gitignore b/.gitignore index 9269fce1..787f51b5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ test/fixtures/ts/node_modules/aliyun-egg/ !test/fixtures/test-files-stack/node_modules/ !test/fixtures/example/node_modules/ !test/fixtures/example-ts-cluster/node_modules/ +!test/fixtures/egg-revert/node_modules/ !test/fixtures/example-ts-error-stack/node_modules/ !test/fixtures/egg-require/node_modules/ test/fixtures/example-ts-ets/typings/ diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index b1900ef7..067b378a 100644 --- a/lib/cmd/cov.js +++ b/lib/cmd/cov.js @@ -131,14 +131,20 @@ class CovCommand extends Command { } const testArgs = await this.formatTestArgs(context); if (!testArgs) return; - covArgs.push(...this.getTestCommandAndArgs()); + covArgs.push(...this.getTestCommandAndArgs(context)); covArgs = covArgs.concat(testArgs); return covArgs; } - getTestCommandAndArgs() { + getTestCommandAndArgs(context) { + const node = process.execPath; + const execArgv = context.execArgv; const mochaFile = process.env.MOCHA_FILE || require.resolve('mocha/bin/_mocha'); - return [ mochaFile ]; + return [ + node, + ...execArgv, + mochaFile, + ]; } } diff --git a/test/fixtures/egg-revert/node_modules/aliyun-egg/index.js b/test/fixtures/egg-revert/node_modules/aliyun-egg/index.js new file mode 100644 index 00000000..dc41c309 --- /dev/null +++ b/test/fixtures/egg-revert/node_modules/aliyun-egg/index.js @@ -0,0 +1,15 @@ +'use strict'; + +exports.startCluster = options => { + console.log('options: %j', options); + if (process.execArgv.length) { + console.log('process.execArgv:', process.execArgv); + } + console.log('NODE_ENV: %s', process.env.NODE_ENV); + + // make sure exit + setTimeout(function() { + console.log('exist by setTimeout'); + process.exit(0); + }, 3000); +}; diff --git a/test/fixtures/egg-revert/node_modules/aliyun-egg/package.json b/test/fixtures/egg-revert/node_modules/aliyun-egg/package.json new file mode 100644 index 00000000..4e36e661 --- /dev/null +++ b/test/fixtures/egg-revert/node_modules/aliyun-egg/package.json @@ -0,0 +1,6 @@ +{ + "name": "aliyun-egg", + "dependencies": { + "egg": "*" + } +} diff --git a/test/fixtures/egg-revert/test/index.test.js b/test/fixtures/egg-revert/test/index.test.js index fb4b3e54..f2d2407b 100644 --- a/test/fixtures/egg-revert/test/index.test.js +++ b/test/fixtures/egg-revert/test/index.test.js @@ -1,5 +1,8 @@ +const assert = require('assert'); + describe('test/index.test.js', () => { it('should test', () => { // test + assert(process.execArgv.includes('--security-revert=CVE-2023-46809')); }); }); diff --git a/test/lib/cmd/cov.test.js b/test/lib/cmd/cov.test.js index 708ea616..2464dc41 100644 --- a/test/lib/cmd/cov.test.js +++ b/test/lib/cmd/cov.test.js @@ -3,6 +3,7 @@ const path = require('path'); const assert = require('assert'); const coffee = require('coffee'); const mm = require('mm'); +const version = Number(process.version.substring(1, 3)); describe('test/lib/cmd/cov.test.js', () => { const eggBin = require.resolve('../../../bin/egg-bin.js'); @@ -206,4 +207,17 @@ describe('test/lib/cmd/cov.test.js', () => { .expect('code', 0) .end(); }); + + it('should support egg.revert', () => { + if (version < 18) return; + mm(process.env, 'NODE_ENV', 'development'); + return coffee.fork(eggBin, [ 'cov' ], { + cwd: path.join(__dirname, '../../fixtures/egg-revert'), + }) + .debug() + .expect('stdout', /SECURITY WARNING: Reverting CVE-2023-46809: Marvin attack on PKCS#1 padding/) + .expect('stdout', /1 passing/) + .expect('code', 0) + .end(); + }); }); diff --git a/test/lib/cmd/dev.test.js b/test/lib/cmd/dev.test.js index 08e9e749..de21a5d8 100644 --- a/test/lib/cmd/dev.test.js +++ b/test/lib/cmd/dev.test.js @@ -183,7 +183,7 @@ describe('test/lib/cmd/dev.test.js', () => { return coffee.fork(eggBin, [ 'dev' ], { cwd: path.join(__dirname, '../../fixtures/egg-revert'), }) - // .debug() + .debug() .expect('stdout', /SECURITY WARNING: Reverting CVE-2023-46809: Marvin attack on PKCS#1 padding/) .expect('code', 0) .end();