Skip to content

Commit 1a1f0ed

Browse files
fix: add optional test 6.2.37
1 parent a7e7792 commit 1a1f0ed

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
properties: {
12+
metrics: {
13+
elements: {
14+
additionalProperties: true,
15+
properties: {
16+
content: {
17+
additionalProperties: true,
18+
properties: {
19+
ssvc_v1: {
20+
additionalProperties: true,
21+
properties: {
22+
role: {
23+
type: 'string',
24+
},
25+
},
26+
},
27+
},
28+
},
29+
},
30+
},
31+
},
32+
},
33+
},
34+
},
35+
},
36+
})
37+
38+
const validate = ajv.compile(inputSchema)
39+
40+
/**
41+
* This implements the optional test 6.2.37 of the CSAF 2.1 standard.
42+
*
43+
* @param {any} doc
44+
*/
45+
export function optionalTest_6_2_37(doc) {
46+
/** @type {Array<{ message: string; instancePath: string }>} */
47+
const warnings = []
48+
const context = { warnings }
49+
50+
if (!validate(doc)) {
51+
return context
52+
}
53+
54+
/*
55+
* Please note that this list can change
56+
* */
57+
const registeredSsvcRoles = ['Supplier', 'Deployer', 'Coordinator']
58+
59+
doc.vulnerabilities?.forEach((vulnerability, vulnerabilityIndex) => {
60+
vulnerability.metrics.forEach((metric, metricIndex) => {
61+
const role = metric.content.ssvc_v1.role
62+
if (!registeredSsvcRoles.includes(role)) {
63+
context.warnings.push({
64+
message: `The used role "${role}" is not a registered role`,
65+
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/role`,
66+
})
67+
}
68+
})
69+
})
70+
71+
return context
72+
}

tests/csaf_2_1/oasis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ const excluded = [
6262
'6.2.34',
6363
'6.2.35',
6464
'6.2.36',
65-
'6.2.37',
6665
'6.2.38',
6766
'6.2.39.1',
6867
'6.2.39.2',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import assert from 'node:assert'
2+
import { optionalTest_6_2_37 } from '../../csaf_2_1/optionalTests.js'
3+
4+
describe('optionalTest_6_2_37', function () {
5+
it('only runs on relevant documents', function () {
6+
assert.equal(
7+
optionalTest_6_2_37({ vulnerabilities: 'mydoc' }).warnings.length,
8+
0
9+
)
10+
})
11+
})

0 commit comments

Comments
 (0)