Skip to content

Commit

Permalink
fix: fix execArgv not work in cov (#254)
Browse files Browse the repository at this point in the history
<!--
Thank you for your pull request. Please review below requirements.
Bug fixes and new features should include tests and possibly benchmarks.
Contributors guide:
https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md

感谢您贡献代码。请确认下列 checklist 的完成情况。
Bug 修复和新功能必须包含测试,必要时请附上性能测试。
Contributors guide:
https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
-->

##### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to
[x]. -->

- [ ] `npm test` passes
- [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [ ] commit message follows commit guidelines

##### Affected core subsystem(s)
<!-- Provide affected core subsystem(s). -->


##### Description of change
<!-- Provide a description of the change below this comment. -->
  • Loading branch information
killagu committed Feb 20, 2024
1 parent 25fb32c commit a31f9b4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
12 changes: 9 additions & 3 deletions lib/cmd/cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/egg-revert/node_modules/aliyun-egg/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/egg-revert/node_modules/aliyun-egg/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/fixtures/egg-revert/test/index.test.js
Original file line number Diff line number Diff line change
@@ -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'));
});
});
14 changes: 14 additions & 0 deletions test/lib/cmd/cov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
});
});
2 changes: 1 addition & 1 deletion test/lib/cmd/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a31f9b4

Please sign in to comment.