From b54500fcc3eae729ab0e94247f2edae05f83f826 Mon Sep 17 00:00:00 2001 From: killagu Date: Tue, 20 Feb 2024 20:02:11 +0800 Subject: [PATCH 1/3] fix: fix execArgv not work in cov --- lib/cmd/cov.js | 12 +++++++++--- test/fixtures/egg-revert/test/index.test.js | 3 +++ test/lib/cmd/cov.test.js | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/cmd/cov.js b/lib/cmd/cov.js index b1900ef..067b378 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/test/index.test.js b/test/fixtures/egg-revert/test/index.test.js index fb4b3e5..f2d2407 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 708ea61..2464dc4 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(); + }); }); From 36056fe5af6677495f6c07d07953912f17e3e56f Mon Sep 17 00:00:00 2001 From: killagu Date: Tue, 20 Feb 2024 20:24:16 +0800 Subject: [PATCH 2/3] f --- test/lib/cmd/dev.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/cmd/dev.test.js b/test/lib/cmd/dev.test.js index 08e9e74..603128a 100644 --- a/test/lib/cmd/dev.test.js +++ b/test/lib/cmd/dev.test.js @@ -177,13 +177,13 @@ describe('test/lib/cmd/dev.test.js', () => { .end(); }); - it('should support egg.revert', () => { + it.only('should support egg.revert', () => { if (version < 18) return; mm(process.env, 'NODE_ENV', 'development'); 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(); From 7c9dbc9cd88ec350831a27b2658fb861372feed0 Mon Sep 17 00:00:00 2001 From: killagu Date: Tue, 20 Feb 2024 20:26:57 +0800 Subject: [PATCH 3/3] f --- .gitignore | 1 + .../egg-revert/node_modules/aliyun-egg/index.js | 15 +++++++++++++++ .../node_modules/aliyun-egg/package.json | 6 ++++++ test/lib/cmd/dev.test.js | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/egg-revert/node_modules/aliyun-egg/index.js create mode 100644 test/fixtures/egg-revert/node_modules/aliyun-egg/package.json diff --git a/.gitignore b/.gitignore index 9269fce..787f51b 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/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 0000000..dc41c30 --- /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 0000000..4e36e66 --- /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/lib/cmd/dev.test.js b/test/lib/cmd/dev.test.js index 603128a..de21a5d 100644 --- a/test/lib/cmd/dev.test.js +++ b/test/lib/cmd/dev.test.js @@ -177,7 +177,7 @@ describe('test/lib/cmd/dev.test.js', () => { .end(); }); - it.only('should support egg.revert', () => { + it('should support egg.revert', () => { if (version < 18) return; mm(process.env, 'NODE_ENV', 'development'); return coffee.fork(eggBin, [ 'dev' ], {