|
| 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 | +} |
0 commit comments