Skip to content

Feat/199 informative tests csaf2.1 6.3.15 #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions csaf_2_1/informativeTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export {
export { informativeTest_6_3_1 } from './informativeTests/informativeTest_6_3_1.js'
export { informativeTest_6_3_4 } from './informativeTests/informativeTest_6_3_4.js'
export { informativeTest_6_3_2 } from './informativeTests/informativeTest_6_3_2.js'
export { informativeTest_6_3_15 } from './informativeTests/informativeTest_6_3_15.js'
134 changes: 134 additions & 0 deletions csaf_2_1/informativeTests/informativeTest_6_3_15.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import Ajv from 'ajv/dist/jtd.js'

const ajv = new Ajv()

/**
* @typedef {object} Selection
* @property {string} [name]
* @property {string} [namespace]
* @property {string} [version]
*/

/**
* @typedef {object} Ssvc1
* @property {Array<Selection>} [selections]
*/

/**
* @typedef {object} MetricContent
* @property {Ssvc1} [ssvc_v1]
*/

/**
* @typedef {object} Metric
* @property {MetricContent} [content]
*/

const inputSchema = /** @type {const} */ ({
additionalProperties: true,
properties: {
document: {
additionalProperties: true,
properties: {
distribution: {
additionalProperties: true,
optionalProperties: {
tlp: {
additionalProperties: true,
optionalProperties: {
label: { type: 'string' },
},
},
},
},
},
},
vulnerabilities: {
elements: {
additionalProperties: true,
properties: {},
optionalProperties: {
metrics: {
elements: {
additionalProperties: true,
properties: {},
optionalProperties: {
content: {
additionalProperties: true,
properties: {},
optionalProperties: {
ssvc_v1: {
additionalProperties: true,
optionalProperties: {
selections: {
elements: {
additionalProperties: true,
properties: {},
optionalProperties: {
name: { type: 'string' },
namespace: { type: 'string' },
version: { type: 'string' },
},
},
},
},
},
},
},
},
},
},
},
},
},
},
})

const validateInput = ajv.compile(inputSchema)

/**
* @param {string | undefined } namespace
*/
function namespaceUsesExtension(namespace) {
return namespace ? namespace.includes('/') : false
}

/**
* For each SSVC decision point given under selections,
* it MUST be tested the namespace does not use an extension
* if the document is not labeled TLP:CLEAR.
* @param {unknown} doc
* @returns
*/
export function informativeTest_6_3_15(doc) {
const ctx = {
infos: /** @type {Array<{ message: string; instancePath: string }>} */ ([]),
}

if (!validateInput(doc)) {
return ctx
}

const vulnerabilities = doc.vulnerabilities

vulnerabilities.forEach((vulnerability, vulnerabilityIndex) => {
/** @type {Array<Metric> | undefined} */
const metrics = vulnerability.metrics
metrics?.forEach((metric, metricIndex) => {
const selections = metric?.content?.ssvc_v1?.selections
selections?.forEach((selection, selectionIndex) => {
if (
namespaceUsesExtension(selection.namespace) &&
doc.document?.distribution?.tlp?.label !== 'TLP:CLEAR'
) {
ctx.infos.push({
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/selections/${selectionIndex}/namespace`,
message: `namespace is private and document is not labeled TLP:CLEAR`,
})
}
})
})
})

return ctx
}
8 changes: 8 additions & 0 deletions tests/csaf_2_1/informativeTest_6_3_15.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import assert from 'node:assert'
import { informativeTest_6_3_15 } from '../../csaf_2_1/informativeTests.js'

describe('informativeTest_6_3_15', function () {
it('only runs on relevant documents', function () {
assert.equal(informativeTest_6_3_15({ document: 'mydoc' }).infos.length, 0)
})
})
1 change: 0 additions & 1 deletion tests/csaf_2_1/oasis.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const excluded = [
'6.2.45',
'6.2.46',
'6.3.14',
'6.3.15',
'6.3.12',
'6.3.13',
'6.3.16',
Expand Down