Skip to content

Commit

Permalink
fix: fix execArgv not work in cov (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Mar 3, 2024
1 parent 2a95ebe commit 366f11b
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test/fixtures/ts/node_modules/aliyun-egg/
!test/fixtures/test-files-glob/**
!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-simple/node_modules/
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ export abstract class BaseCommand extends Command {
console.log('dry run: $ %o', `${process.execPath} ${modulePath} ${args.join(' ')}`);
return;
}
const forkExecArgv = [
...this.ctx.args.execArgv || [],
...options.execArgv || [],
];

options = {
stdio: 'inherit',
env: this.ctx.env,
cwd: this.base,
...options,
execArgv: forkExecArgv,
};
const proc = fork(modulePath, args, options);
debug('Run fork pid: %o, `%s %s %s`',
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ export class CovCommand extends TestCommand {
const coverageDir = path.join(this.base, 'coverage');
await fs.rm(coverageDir, { force: true, recursive: true });

await super.forkNode(c8File, [ ...c8Args, modulePath, ...args ]);
await super.forkNode(c8File, [ ...c8Args, process.execPath, ...this.ctx.args.execArgv || [], modulePath, ...args ]);
}
}
8 changes: 8 additions & 0 deletions src/middleware/global_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ export default class GlobalOptions implements ApplicationLifecycle {
await runscript(`node ${etsBin}`);
}

if (ctx.args.pkgEgg.revert) {
ctx.args.execArgv = ctx.args.execArgv || [];
const reverts = Array.isArray(ctx.args.pkgEgg.revert) ? ctx.args.pkgEgg.revert : [ ctx.args.pkgEgg.revert ];
for (const revert of reverts) {
ctx.args.execArgv.push(`--security-revert=${revert}`);
}
}

debug('set NODE_OPTIONS: %o', ctx.env.NODE_OPTIONS);
debug('ctx.args: %o', ctx.args);
debug('enter next');
Expand Down
17 changes: 17 additions & 0 deletions test/cmd/cov.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import assert from 'node:assert';
import path from 'node:path';
import fs from 'node:fs/promises';
import assertFile from 'assert-file';
import mm from 'mm';

import coffee from '../coffee';

const version = Number(process.version.substring(1, 3));

describe('test/cmd/cov.test.ts', () => {
const eggBin = path.join(__dirname, '../../src/bin/cli.ts');
const fixtures = path.join(__dirname, '../fixtures');
Expand Down Expand Up @@ -183,5 +187,18 @@ describe('test/cmd/cov.test.ts', () => {
.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();
});
});
});
15 changes: 15 additions & 0 deletions test/cmd/dev.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import path from 'node:path';
import net from 'node:net';
import detect from 'detect-port';
import mm from 'mm';
import coffee from '../coffee';

const version = Number(process.version.substring(1, 3));

describe('test/cmd/dev.test.ts', () => {
const eggBin = path.join(__dirname, '../../src/bin/cli.ts');
const fixtures = path.join(__dirname, '../fixtures');
Expand Down Expand Up @@ -186,4 +189,16 @@ describe('test/cmd/dev.test.ts', () => {
.end();
});
});

it('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()
.expect('stdout', /SECURITY WARNING: Reverting CVE-2023-46809: Marvin attack on PKCS#1 padding/)
.expect('code', 0)
.end();
});
});
13 changes: 13 additions & 0 deletions test/cmd/test.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import path from 'node:path';
import coffee from '../coffee';

const version = Number(process.version.substring(1, 3));

describe('test/cmd/test.test.ts', () => {
const eggBin = path.join(__dirname, '../../src/bin/cli.ts');
const fixtures = path.join(__dirname, '../fixtures');
Expand Down Expand Up @@ -304,5 +306,16 @@ describe('test/cmd/test.test.ts', () => {
.expect('code', 0)
.end();
});

it('should support egg.revert', () => {
if (version < 18) return;
return coffee.fork(eggBin, [ 'test' ], {
cwd: path.join(__dirname, '../fixtures/egg-revert'),
})
.debug()
.expect('stdout', /SECURITY WARNING: Reverting CVE-2023-46809: Marvin attack on PKCS#1 padding/)
.expect('code', 0)
.end();
});
});
});
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.

7 changes: 7 additions & 0 deletions test/fixtures/egg-revert/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "demo-app",
"egg": {
"framework": "aliyun-egg",
"revert": "CVE-2023-46809"
}
}
8 changes: 8 additions & 0 deletions test/fixtures/egg-revert/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const assert = require('assert');

describe('test/index.test.js', () => {
it('should test', () => {
// test
assert(process.execArgv.includes('--security-revert=CVE-2023-46809'));
});
});

0 comments on commit 366f11b

Please sign in to comment.