Skip to content

Commit

Permalink
feat: support configure egg.revert in package.json (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Feb 19, 2024
1 parent 42e9c9d commit 8409536
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -15,4 +15,4 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest'
version: '14, 16, 18'
version: '14, 16, 18, 20'
8 changes: 8 additions & 0 deletions lib/command.js
Expand Up @@ -114,6 +114,14 @@ class Command extends BaseCommand {
execArgvObj.require = execArgvObj.require.concat(eggInfo.require);
}

if (eggInfo.revert) {
context.execArgvObj['security-revert'] = context.execArgvObj['security-revert'] || [];
const reverts = Array.isArray(eggInfo.revert) ? eggInfo.revert : [ eggInfo.revert ];
for (const revert of reverts) {
context.execArgvObj['security-revert'].push(revert);
}
}

// load ts-node
if (argv.typescript) {
execArgvObj.require.push(argv.tscompiler);
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/egg-revert/package.json
@@ -0,0 +1,7 @@
{
"name": "demo-app",
"egg": {
"framework": "aliyun-egg",
"revert": "CVE-2023-46809"
}
}
5 changes: 5 additions & 0 deletions test/fixtures/egg-revert/test/index.test.js
@@ -0,0 +1,5 @@
describe('test/index.test.js', () => {
it('should test', () => {
// test
});
});
13 changes: 13 additions & 0 deletions test/lib/cmd/dev.test.js
Expand Up @@ -3,6 +3,7 @@ const coffee = require('coffee');
const net = require('net');
const mm = require('mm');
const detect = require('detect-port');
const version = Number(process.version.substring(1, 3));

describe('test/lib/cmd/dev.test.js', () => {
const eggBin = require.resolve('../../../bin/egg-bin.js');
Expand Down Expand Up @@ -175,4 +176,16 @@ describe('test/lib/cmd/dev.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, [ '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();
});
});
12 changes: 12 additions & 0 deletions test/lib/cmd/test.test.js
Expand Up @@ -4,6 +4,7 @@ const mm = require('mm');
const assert = require('assert');
const changed = require('jest-changed-files');
const Command = require('../../../lib/cmd/test');
const version = Number(process.version.substring(1, 3));

describe('test/lib/cmd/test.test.js', () => {
const eggBin = require.resolve('../../../bin/egg-bin.js');
Expand Down Expand Up @@ -300,4 +301,15 @@ describe('test/lib/cmd/test.test.js', () => {
.expect('code', 1)
.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();
});
});

0 comments on commit 8409536

Please sign in to comment.