diff --git a/README.md b/README.md index 10b8200a..92b52172 100644 --- a/README.md +++ b/README.md @@ -350,6 +350,7 @@ The following tests are not yet implemented and therefore missing: - Recommended Test 6.2.50.3 - Recommended Test 6.2.51 - Recommended Test 6.2.52 +- Recommended Test 6.2.53 - Recommended Test 6.2.54.1 - Recommended Test 6.2.54.2 - Recommended Test 6.2.54.4 @@ -500,7 +501,6 @@ export const recommendedTest_6_2_41: DocumentTest export const recommendedTest_6_2_43: DocumentTest export const recommendedTest_6_2_47: DocumentTest export const recommendedTest_6_2_48: DocumentTest -export const recommendedTest_6_2_53: DocumentTest export const recommendedTest_6_2_54_3: DocumentTest ``` diff --git a/csaf_2_1/recommendedTests.js b/csaf_2_1/recommendedTests.js index cdd6cc14..7f91836b 100644 --- a/csaf_2_1/recommendedTests.js +++ b/csaf_2_1/recommendedTests.js @@ -42,5 +42,4 @@ export { recommendedTest_6_2_41 } from './recommendedTests/recommendedTest_6_2_4 export { recommendedTest_6_2_43 } from './recommendedTests/recommendedTest_6_2_43.js' export { recommendedTest_6_2_47 } from './recommendedTests/recommendedTest_6_2_47.js' export { recommendedTest_6_2_48 } from './recommendedTests/recommendedTest_6_2_48.js' -export { recommendedTest_6_2_53 } from './recommendedTests/recommendedTest_6_2_53.js' export { recommendedTest_6_2_54_3 } from './recommendedTests/recommendedTest_6_2_54_3.js' diff --git a/csaf_2_1/recommendedTests/recommendedTest_6_2_53.js b/csaf_2_1/recommendedTests/recommendedTest_6_2_53.js deleted file mode 100644 index 65d7fb8d..00000000 --- a/csaf_2_1/recommendedTests/recommendedTest_6_2_53.js +++ /dev/null @@ -1,91 +0,0 @@ -import { createRequire } from 'module' -import { Ajv } from 'ajv/dist/jtd.js' - -const ajv = new Ajv() -const require = createRequire(import.meta.url) -const registry = - /** @type {{ entries: Array<{ system_name: string; text_pattern: string }> }} */ ( - // @ts-ignore — registry.json lives in the excluded csaf/ subtree - require('../../csaf/registry/id/registry.json') - ) - -/** @type {Array<{ system_name: string; text_pattern: RegExp }>} */ -const registeredIdSystems = registry.entries.map( - (/** @type {{ system_name: string; text_pattern: string }} */ entry) => ({ - system_name: entry.system_name, - text_pattern: new RegExp(entry.text_pattern), - }) -) - -/* - This is the jtd schema that needs to match the input document so that the - test is activated. If this schema doesn't match it normally means that the input - document does not validate against the csaf json schema or optional fields that - the test checks are not present. - */ -const inputSchema = /** @type {const} */ ({ - additionalProperties: true, - - properties: { - vulnerabilities: { - elements: { - additionalProperties: true, - optionalProperties: { - ids: { - elements: { - additionalProperties: true, - optionalProperties: { - system_name: { type: 'string' }, - text: { type: 'string' }, - }, - }, - }, - }, - }, - }, - }, -}) - -const validate = ajv.compile(inputSchema) - -/** @typedef {import('ajv/dist/jtd.js').JTDDataType} InputSchema */ -/** @typedef {InputSchema['vulnerabilities'][number]} Vulnerability */ - -/** - * For each item in vulnerabilities[].ids[] that has a registered system_name, - * it is tested that the text matches the text_pattern from the RVISC registry. - * - * @param {unknown} doc - */ -export function recommendedTest_6_2_53(doc) { - /** @type {Array<{ message: string; instancePath: string }>} */ - const warnings = [] - const context = { warnings } - - if (!validate(doc)) { - return context - } - - /** @type {Array} */ - const vulnerabilities = doc.vulnerabilities - vulnerabilities.forEach((vulnerability, vulnIndex) => { - const ids = vulnerability.ids ?? [] - ids.forEach((id, idIndex) => { - if (id.system_name === undefined || id.text === undefined) return - - const registeredSystem = registeredIdSystems.find( - (entry) => entry.system_name === id.system_name - ) - if (!registeredSystem) return - - if (!registeredSystem.text_pattern.test(id.text)) { - warnings.push({ - instancePath: `/vulnerabilities/${vulnIndex}/ids/${idIndex}/text`, - message: `the text does not match the text_pattern of the registered ID system "${id.system_name}"`, - }) - } - }) - }) - - return context -} diff --git a/tests/csaf_2_1/oasis.js b/tests/csaf_2_1/oasis.js index 03f6ba20..1521905f 100644 --- a/tests/csaf_2_1/oasis.js +++ b/tests/csaf_2_1/oasis.js @@ -45,6 +45,7 @@ const excluded = [ '6.2.50.3', '6.2.51', '6.2.52', + '6.2.53', '6.2.54.1', '6.2.54.2', '6.2.54.4', diff --git a/tests/csaf_2_1/recommendedTest_6_2_53.js b/tests/csaf_2_1/recommendedTest_6_2_53.js deleted file mode 100644 index 9d767128..00000000 --- a/tests/csaf_2_1/recommendedTest_6_2_53.js +++ /dev/null @@ -1,46 +0,0 @@ -import assert from 'node:assert/strict' -import { recommendedTest_6_2_53 } from '../../csaf_2_1/recommendedTests/recommendedTest_6_2_53.js' - -describe('recommendedTest_6_2_53', function () { - it('only runs on relevant documents', function () { - assert.equal(recommendedTest_6_2_53({}).warnings.length, 0) - }) - // - it('does not warn when ids are absent', function () { - assert.equal( - recommendedTest_6_2_53({ vulnerabilities: [{}] }).warnings.length, - 0 - ) - }) - - it('does not warn when text is absent', function () { - assert.equal( - recommendedTest_6_2_53({ - vulnerabilities: [ - { - ids: [{ system_name: 'https://example.com' }], - }, - ], - }).warnings.length, - 0 - ) - }) - - it('does not warn when system_name is not in the registry', function () { - assert.equal( - recommendedTest_6_2_53({ - vulnerabilities: [ - { - ids: [ - { - system_name: 'https://unknown-system.example.com', - text: 'some-text', - }, - ], - }, - ], - }).warnings.length, - 0 - ) - }) -})