Skip to content

Commit 1172750

Browse files
committed
✨ add assertions, test runners, improve output
1 parent 10fab67 commit 1172750

File tree

4 files changed

+87
-20
lines changed

4 files changed

+87
-20
lines changed

security/site/cve-data.mjs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
1+
/**
2+
* map of all CVEs affecting jQuery
3+
* versions === affected versions per the CVE
4+
* exceptions === affected versions per the CVE that we cannot reproduce
5+
*/
16
const cveMap = new Map([
2-
['2011-4969', { versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2'] }],
3-
['2012-6708', { versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3'] }],
4-
['2015-9251', { versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3', '1.12.4', '2.2.4'] }],
5-
['2019-11358', { versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3', '1.12.4', '2.2.4'] }],
6-
['2020-7656', { versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3'] }],
7-
['2020-11022', { versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3', '1.12.4', '2.2.4'] }],
8-
['2020-11023', { versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3', '1.12.4', '2.2.4'] }],
9-
['2020-23064', { versions: ['2.2.4'] }],
7+
['2011-4969', {
8+
versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2'],
9+
exceptions: [],
10+
}],
11+
['2012-6708', {
12+
versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3'],
13+
exceptions: [],
14+
}],
15+
['2015-9251', {
16+
versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3', '1.12.4', '2.2.4'],
17+
exceptions: ['1.2.6', '1.3.2'],
18+
}],
19+
['2019-11358', {
20+
versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3', '1.12.4', '2.2.4'],
21+
exceptions: [],
22+
}],
23+
['2020-7656', {
24+
versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3'],
25+
exceptions: [],
26+
}],
27+
['2020-11022', {
28+
versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3', '1.12.4', '2.2.4'],
29+
exceptions: [],
30+
}],
31+
['2020-11023', {
32+
versions: ['1.2.6', '1.3.2', '1.4.4', '1.5.2', '1.6.4', '1.7.2', '1.8.3', '1.12.4', '2.2.4'],
33+
exceptions: [],
34+
}],
35+
['2020-23064', {
36+
versions: ['2.2.4'],
37+
exceptions: [],
38+
}],
1039
]);
1140

1241
const jQueryVersions = new Set(Array.from(cveMap, ([name, value]) => (value.versions)).flat());

security/test/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"private": true,
33
"scripts": {
4+
"//": "use node test runner",
5+
"node": "npm test node",
6+
"//": "use tap test runner",
7+
"tap": "npm test tap",
8+
"//": "run directly; raw tap output",
49
"test": "./test.sh"
510
},
611
"dependencies": {

security/test/test.mjs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ import { cveMap, getPatchedVersion, jQueryVersions } from '../site/cve-data.mjs'
55
import t from 'tap'
66
import chalk from 'chalk';
77

8-
function banner(txt) {
9-
console.log(chalk.magenta(`
8+
// these are fully patched
9+
const patchedVersions = [
10+
'1.2.7-sec',
11+
'1.6.5-sec'
12+
];
13+
14+
function banner(txt, {borderColor = 'magenta', textColor = 'cyan'} = {borderColor: 'magenta', textColor: 'cyan'}) {
15+
console.log(chalk[borderColor](`
1016
--------------------------------------------------------------------------------
11-
${chalk.cyan(txt)}
17+
${chalk[textColor](txt)}
1218
--------------------------------------------------------------------------------
1319
`))
1420
}
1521

16-
banner('running jQuery security tests...');
17-
1822
const platform = os.platform();
19-
console.log(chalk.white(` platform detected: ${platform}`));
23+
banner(`platform detected: ${platform}`, { borderColor:'white', textColor: 'white' });
24+
banner('running jQuery security tests...');
2025

2126
const baseURL = 'http://127.0.0.1:3333/index.html';
2227
const timeout = 5 * 1000;
@@ -34,11 +39,11 @@ else {
3439
cmd += `--headless=old --virtual-time-budget=${timeout} --run-all-compositor-stages-before-draw --dump-dom `;
3540

3641
for (const v of jQueryVersions) {
37-
await t.test(v, async => testJQuery(v));
38-
await t.test(getPatchedVersion(v), async => testJQuery(v, true));
42+
await t.test(`validate jQuery v${v}`, async t => testJQuery(v, false, t));
43+
await t.test(`validate jQuery v${getPatchedVersion(v)}`, async t => testJQuery(v, true, t));
3944
}
4045

41-
async function testJQuery(version, patched) {
46+
async function testJQuery(version, patched, t) {
4247

4348
const effectiveVersion = patched ? getPatchedVersion(version) : version;
4449

@@ -56,17 +61,37 @@ async function testJQuery(version, patched) {
5661
if(cve[1].versions.includes(version)) {
5762
const cveName = `CVE-${cve[0]}`
5863
const status = d.querySelector(`#${cveName} .cve__footer-status`).textContent;
64+
const notReproducible = status.startsWith(`Can't`);
5965

60-
if(status.startsWith(`Can't`)) {
66+
if(notReproducible) {
6167
console.log(chalk.green(`${cveName.padEnd(14)} - ${status}`));
6268
}
6369
else {
6470
console.log(chalk.red(status
6571
.replace('CVE', `${cveName.padEnd(14)} - `)
6672
));
6773
}
74+
75+
if(patched && patchedVersions.includes(effectiveVersion)) {
76+
t.ok(notReproducible, `${cveName} should be patched in v${effectiveVersion}`);
77+
}
78+
else {
79+
if(cve[1].exceptions.includes(version)) {
80+
t.ok(notReproducible, `${cveName} is supposed be reproducible in v${effectiveVersion} according to the CVE but it can't be reproduced`);
81+
}
82+
else {
83+
t.notOk(notReproducible, `${cveName} should be reproducible in v${effectiveVersion}`);
84+
}
85+
}
6886
}
6987
}
7088
}
7189

72-
banner('...done');
90+
banner(`...done`);
91+
92+
if(t.counts.fail) {
93+
banner('FAIL 💔', { borderColor: 'red', textColor: 'red'});
94+
}
95+
else {
96+
banner('PASS 💚', { borderColor: 'green', textColor: 'green'});
97+
}

security/test/test.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#!/bin/sh
22

33
node ../server/index.cjs & SERVER_PID=$! ;
4-
tap run --allow-empty-coverage;
4+
5+
if [ "$1" = "node" ] ; then
6+
node --test ;
7+
elif [ "$1" = "tap" ] ; then
8+
tap run --allow-empty-coverage;
9+
else
10+
node test.mjs;
11+
fi
12+
513
TEST_EXIT=$? ;
614
kill $SERVER_PID ;
715
exit $TEST_EXIT ;

0 commit comments

Comments
 (0)