Skip to content

Commit 27c29b2

Browse files
committed
feat(CSAF2.1): add mandatory Test 6.1.6
1 parent e0bc7c3 commit 27c29b2

File tree

5 files changed

+95
-3
lines changed

5 files changed

+95
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ The following tests are not yet implemented and therefore missing:
311311
312312
**Mandatory Tests**
313313
314-
- Mandatory Test 6.1.6
315314
- Mandatory Test 6.1.14
316315
- Mandatory Test 6.1.16
317316
- Mandatory Test 6.1.26
@@ -394,6 +393,7 @@ export const mandatoryTest_6_1_2: DocumentTest
394393
export const mandatoryTest_6_1_3: DocumentTest
395394
export const mandatoryTest_6_1_4: DocumentTest
396395
export const mandatoryTest_6_1_5: DocumentTest
396+
export const mandatoryTest_6_1_6: DocumentTest
397397
export const mandatoryTest_6_1_7: DocumentTest
398398
export const mandatoryTest_6_1_8: DocumentTest
399399
export const mandatoryTest_6_1_9: DocumentTest

csaf_2_1/mandatoryTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export {
33
mandatoryTest_6_1_3,
44
mandatoryTest_6_1_4,
55
mandatoryTest_6_1_5,
6-
mandatoryTest_6_1_6,
76
mandatoryTest_6_1_12,
87
mandatoryTest_6_1_15,
98
mandatoryTest_6_1_17,
@@ -35,6 +34,7 @@ export {
3534
mandatoryTest_6_1_33,
3635
} from '../mandatoryTests.js'
3736
export { mandatoryTest_6_1_1 } from './mandatoryTests/mandatoryTest_6_1_1.js'
37+
export { mandatoryTest_6_1_6 } from './mandatoryTests/mandatoryTest_6_1_6.js'
3838
export { mandatoryTest_6_1_7 } from './mandatoryTests/mandatoryTest_6_1_7.js'
3939
export { mandatoryTest_6_1_8 } from './mandatoryTests/mandatoryTest_6_1_8.js'
4040
export { mandatoryTest_6_1_9 } from './mandatoryTests/mandatoryTest_6_1_9.js'
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* @param {any} doc
3+
*/
4+
export function mandatoryTest_6_1_6(doc) {
5+
/** @type {Array<{ message: string; instancePath: string }>} */
6+
const errors = []
7+
let isValid = true
8+
9+
if (Array.isArray(doc.vulnerabilities)) {
10+
/** @type {Array<any>} */
11+
const vulnerabilities = doc.vulnerabilities
12+
vulnerabilities.forEach((vulnerability, vulnerabilityIndex) => {
13+
const productStatus = vulnerability.product_status
14+
if (!productStatus) return
15+
const groups = [
16+
new Set(
17+
[]
18+
.concat(
19+
Array.isArray(productStatus.first_affected)
20+
? productStatus.first_affected
21+
: []
22+
)
23+
.concat(
24+
Array.isArray(productStatus.known_affected)
25+
? productStatus.known_affected
26+
: []
27+
)
28+
.concat(
29+
Array.isArray(productStatus.last_affected)
30+
? productStatus.last_affected
31+
: []
32+
)
33+
),
34+
new Set(
35+
Array.isArray(productStatus.known_not_affected)
36+
? productStatus.known_not_affected
37+
: []
38+
),
39+
new Set(
40+
[]
41+
.concat(
42+
Array.isArray(productStatus.first_fixed)
43+
? productStatus.first_fixed
44+
: []
45+
)
46+
.concat(
47+
Array.isArray(productStatus.fixed) ? productStatus.fixed : []
48+
)
49+
),
50+
new Set(
51+
Array.isArray(productStatus.under_investigation)
52+
? productStatus.under_investigation
53+
: []
54+
),
55+
new Set(
56+
Array.isArray(productStatus.unknown) ? productStatus.unknown : []
57+
),
58+
]
59+
60+
groups.forEach((group, index) => {
61+
const remainingGroups = groups.slice(index + 1)
62+
group.forEach((productID) => {
63+
if (remainingGroups.some((g) => g.has(productID))) {
64+
isValid = false
65+
errors.push({
66+
instancePath: `/vulnerabilities/${vulnerabilityIndex}/product_status`,
67+
message: `product id "${productID}" is mentioned in contradicting product status groups`,
68+
})
69+
}
70+
})
71+
})
72+
})
73+
}
74+
75+
return { isValid, errors }
76+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import assert from 'node:assert/strict'
2+
import { mandatoryTest_6_1_6 } from '../../csaf_2_1/mandatoryTests/mandatoryTest_6_1_6.js'
3+
4+
describe('mandatoryTest_6_1_6', function () {
5+
it('skip the check if there is no product status', function () {
6+
assert.equal(
7+
mandatoryTest_6_1_6({
8+
vulnerabilities: [
9+
{
10+
metrics: [],
11+
},
12+
],
13+
}).isValid,
14+
true
15+
)
16+
})
17+
})

tests/csaf_2_1/oasis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as mandatory from '../../csaf_2_1/mandatoryTests.js'
1010
Once all tests are implemented for CSAF 2.1 this should be deleted.
1111
*/
1212
const excluded = [
13-
'6.1.6',
1413
'6.1.14',
1514
'6.1.16',
1615
'6.1.26',

0 commit comments

Comments
 (0)