-
Notifications
You must be signed in to change notification settings - Fork 8
/
mandatoryTest_6_1_6.js
73 lines (70 loc) · 2.11 KB
/
mandatoryTest_6_1_6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @param {any} doc
*/
export default function mandatoryTest_6_1_6(doc) {
/** @type {Array<{ message: string; instancePath: string }>} */
const errors = []
let isValid = true
if (Array.isArray(doc.vulnerabilities)) {
/** @type {Array<any>} */
const vulnerabilities = doc.vulnerabilities
vulnerabilities.forEach((vulnerability, vulnerabilityIndex) => {
const productStatus = vulnerability.product_status
if (!productStatus) return
const groups = [
new Set(
[]
.concat(
Array.isArray(productStatus.first_affected)
? productStatus.first_affected
: []
)
.concat(
Array.isArray(productStatus.known_affected)
? productStatus.known_affected
: []
)
.concat(
Array.isArray(productStatus.last_affected)
? productStatus.last_affected
: []
)
),
new Set(
Array.isArray(productStatus.known_not_affected)
? productStatus.known_not_affected
: []
),
new Set(
[]
.concat(
Array.isArray(productStatus.first_fixed)
? productStatus.first_fixed
: []
)
.concat(
Array.isArray(productStatus.fixed) ? productStatus.fixed : []
)
),
new Set(
Array.isArray(productStatus.under_investigation)
? productStatus.under_investigation
: []
),
]
groups.forEach((group, index) => {
const remainingGroups = groups.slice(index + 1)
group.forEach((productID) => {
if (remainingGroups.some((g) => g.has(productID))) {
isValid = false
errors.push({
instancePath: `/vulnerabilities/${vulnerabilityIndex}/product_status`,
message: `product id "${productID}" is mentioned in contradicting product status groups`,
})
}
})
})
})
}
return { isValid, errors }
}