Skip to content

Commit dac133e

Browse files
Merge pull request #276 from secvisogram/feat/199-Informative-Tests_CSAF2_1_6.3.4
Feat/199 informative tests csaf 2.1 6.3.4
2 parents efee6b1 + ad0a05c commit dac133e

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

csaf_2_1/informativeTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export {
22
informativeTest_6_3_2,
33
informativeTest_6_3_3,
4-
informativeTest_6_3_4,
54
informativeTest_6_3_5,
65
informativeTest_6_3_6,
76
informativeTest_6_3_7,
@@ -11,3 +10,4 @@ export {
1110
informativeTest_6_3_11,
1211
} from '../informativeTests.js'
1312
export { informativeTest_6_3_1 } from './informativeTests/informativeTest_6_3_1.js'
13+
export { informativeTest_6_3_4 } from './informativeTests/informativeTest_6_3_4.js'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Ajv from 'ajv/dist/jtd.js'
2+
3+
const ajv = new Ajv()
4+
5+
const inputSchema = /** @type {const} */ ({
6+
additionalProperties: true,
7+
properties: {
8+
vulnerabilities: {
9+
elements: {
10+
additionalProperties: true,
11+
optionalProperties: {
12+
cwes: {
13+
elements: {
14+
additionalProperties: true,
15+
properties: {},
16+
},
17+
},
18+
},
19+
},
20+
},
21+
},
22+
})
23+
24+
const validateInput = ajv.compile(inputSchema)
25+
26+
/**
27+
* It MUST be tested that at least one CWE is given.
28+
* @param {unknown} doc
29+
* @returns
30+
*/
31+
export function informativeTest_6_3_4(doc) {
32+
const ctx = {
33+
infos: /** @type {Array<{ message: string; instancePath: string }>} */ ([]),
34+
}
35+
36+
if (!validateInput(doc)) {
37+
return ctx
38+
}
39+
40+
doc.vulnerabilities.forEach((vulnerability, vulnerabilityIndex) => {
41+
if (!vulnerability?.cwes?.length) {
42+
ctx.infos.push({
43+
instancePath: `/vulnerabilities/${vulnerabilityIndex}`,
44+
message: 'missing cwe',
45+
})
46+
}
47+
})
48+
49+
return ctx
50+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import assert from 'node:assert'
2+
import { informativeTest_6_3_4 } from '../../csaf_2_1/informativeTests.js'
3+
4+
describe('informativeTest_6_3_4', function () {
5+
it('only runs on relevant documents', function () {
6+
assert.equal(informativeTest_6_3_4({ document: 'mydoc' }).infos.length, 0)
7+
})
8+
})

tests/csaf_2_1/oasis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const excluded = [
5858
'6.2.39.2',
5959
'6.2.40',
6060
'6.3.2',
61-
'6.3.4',
6261
'6.3.14',
6362
'6.3.15',
6463
'6.3.12',

0 commit comments

Comments
 (0)