Skip to content

feat: add mandatory test 6.1.27.14 #339

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ The following tests are not yet implemented and therefore missing:
- Mandatory Test 6.1.16
- Mandatory Test 6.1.27.12
- Mandatory Test 6.1.27.13
- Mandatory Test 6.1.27.14
- Mandatory Test 6.1.27.15
- Mandatory Test 6.1.27.16
- Mandatory Test 6.1.27.17
Expand Down Expand Up @@ -422,6 +421,7 @@ export const mandatoryTest_6_1_27_8: DocumentTest
export const mandatoryTest_6_1_27_9: DocumentTest
export const mandatoryTest_6_1_27_10: DocumentTest
export const mandatoryTest_6_1_27_11: DocumentTest
export const mandatoryTest_6_1_27_14: DocumentTest
export const mandatoryTest_6_1_28: DocumentTest
export const mandatoryTest_6_1_29: DocumentTest
export const mandatoryTest_6_1_30: DocumentTest
Expand Down
1 change: 1 addition & 0 deletions csaf_2_1/mandatoryTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export { mandatoryTest_6_1_1 } from './mandatoryTests/mandatoryTest_6_1_1.js'
export { mandatoryTest_6_1_8 } from './mandatoryTests/mandatoryTest_6_1_8.js'
export { mandatoryTest_6_1_11 } from './mandatoryTests/mandatoryTest_6_1_11.js'
export { mandatoryTest_6_1_13 } from './mandatoryTests/mandatoryTest_6_1_13.js'
export { mandatoryTest_6_1_27_14 } from './mandatoryTests/mandatoryTest_6_1_27_14.js'
export { mandatoryTest_6_1_34 } from './mandatoryTests/mandatoryTest_6_1_34.js'
export { mandatoryTest_6_1_35 } from './mandatoryTests/mandatoryTest_6_1_35.js'
export { mandatoryTest_6_1_9 } from './mandatoryTests/mandatoryTest_6_1_9.js'
Expand Down
70 changes: 70 additions & 0 deletions csaf_2_1/mandatoryTests/mandatoryTest_6_1_27_14.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import Ajv from 'ajv/dist/jtd.js'

const ajv = new Ajv()

/*
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: {
document: {
additionalProperties: true,
properties: {
category: {
type: 'string',
},
},
optionalProperties: {
notes: {
elements: {
additionalProperties: true,
optionalProperties: {
category: {
type: 'string',
},
},
},
},
},
},
},
})

const validate = ajv.compile(inputSchema)

/**
* This implements the mandatory test 6.1.27.14 of the CSAF 2.1 standard.
*
* @param {unknown} doc
*/
export function mandatoryTest_6_1_27_14(doc) {
/*
The `ctx` variable holds the state that is accumulated during the test ran and is
finally returned by the function.
*/
const ctx = {
errors:
/** @type {Array<{ instancePath: string; message: string }>} */ ([]),
isValid: true,
}

if (
!validate(doc) ||
!['csaf_withdrawn', 'csaf_superseded'].includes(doc.document.category)
)
return ctx

if (!doc.document.notes?.find((n) => n.category === 'description')) {
ctx.isValid = false
ctx.errors.push({
instancePath: '/document/notes',
message: 'needs at least one note with the category "description"',
})
}

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

describe('mandatoryTest_6_1_27_14', function () {
it('only runs on documents matching the input schema', function () {
assert.equal(
mandatoryTest_6_1_27_14({
document: 'invalid json',
}).isValid,
true
)
})

it('only runs on csaf_withdrawn and csaf_superseded documents', function () {
assert.equal(
mandatoryTest_6_1_27_14({
document: {
category: 'unknown category',
},
}).isValid,
true
)
})
})
1 change: 0 additions & 1 deletion tests/csaf_2_1/oasis.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const excluded = [
'6.1.27.11',
'6.1.27.12',
'6.1.27.13',
'6.1.27.14',
'6.1.27.15',
'6.1.27.16',
'6.1.27.17',
Expand Down