Skip to content

Commit 8535583

Browse files
authored
Merge pull request #339 from secvisogram/316-mandatory-test-6.1.27.14
feat: add mandatory test 6.1.27.14
2 parents 54d3dd5 + bbc52d5 commit 8535583

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ The following tests are not yet implemented and therefore missing:
315315
- Mandatory Test 6.1.16
316316
- Mandatory Test 6.1.27.12
317317
- Mandatory Test 6.1.27.13
318-
- Mandatory Test 6.1.27.14
319318
- Mandatory Test 6.1.27.15
320319
- Mandatory Test 6.1.27.16
321320
- Mandatory Test 6.1.27.17
@@ -422,6 +421,7 @@ export const mandatoryTest_6_1_27_8: DocumentTest
422421
export const mandatoryTest_6_1_27_9: DocumentTest
423422
export const mandatoryTest_6_1_27_10: DocumentTest
424423
export const mandatoryTest_6_1_27_11: DocumentTest
424+
export const mandatoryTest_6_1_27_14: DocumentTest
425425
export const mandatoryTest_6_1_28: DocumentTest
426426
export const mandatoryTest_6_1_29: DocumentTest
427427
export const mandatoryTest_6_1_30: DocumentTest

csaf_2_1/mandatoryTests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export { mandatoryTest_6_1_8 } from './mandatoryTests/mandatoryTest_6_1_8.js'
4040
export { mandatoryTest_6_1_11 } from './mandatoryTests/mandatoryTest_6_1_11.js'
4141
export { mandatoryTest_6_1_13 } from './mandatoryTests/mandatoryTest_6_1_13.js'
4242
export { mandatoryTest_6_1_10 } from './mandatoryTests/mandatoryTest_6_1_10.js'
43+
export { mandatoryTest_6_1_27_14 } from './mandatoryTests/mandatoryTest_6_1_27_14.js'
4344
export { mandatoryTest_6_1_34 } from './mandatoryTests/mandatoryTest_6_1_34.js'
4445
export { mandatoryTest_6_1_35 } from './mandatoryTests/mandatoryTest_6_1_35.js'
4546
export { mandatoryTest_6_1_9 } from './mandatoryTests/mandatoryTest_6_1_9.js'
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import Ajv from 'ajv/dist/jtd.js'
2+
3+
const ajv = new Ajv()
4+
5+
/*
6+
This is the jtd schema that needs to match the input document so that the
7+
test is activated. If this schema doesn't match it normally means that the input
8+
document does not validate against the csaf json schema or optional fields that
9+
the test checks are not present.
10+
*/
11+
const inputSchema = /** @type {const} */ ({
12+
additionalProperties: true,
13+
properties: {
14+
document: {
15+
additionalProperties: true,
16+
properties: {
17+
category: {
18+
type: 'string',
19+
},
20+
},
21+
optionalProperties: {
22+
notes: {
23+
elements: {
24+
additionalProperties: true,
25+
optionalProperties: {
26+
category: {
27+
type: 'string',
28+
},
29+
},
30+
},
31+
},
32+
},
33+
},
34+
},
35+
})
36+
37+
const validate = ajv.compile(inputSchema)
38+
39+
/**
40+
* This implements the mandatory test 6.1.27.14 of the CSAF 2.1 standard.
41+
*
42+
* @param {unknown} doc
43+
*/
44+
export function mandatoryTest_6_1_27_14(doc) {
45+
/*
46+
The `ctx` variable holds the state that is accumulated during the test ran and is
47+
finally returned by the function.
48+
*/
49+
const ctx = {
50+
errors:
51+
/** @type {Array<{ instancePath: string; message: string }>} */ ([]),
52+
isValid: true,
53+
}
54+
55+
if (
56+
!validate(doc) ||
57+
!['csaf_withdrawn', 'csaf_superseded'].includes(doc.document.category)
58+
)
59+
return ctx
60+
61+
if (!doc.document.notes?.find((n) => n.category === 'description')) {
62+
ctx.isValid = false
63+
ctx.errors.push({
64+
instancePath: '/document/notes',
65+
message: 'needs at least one note with the category "description"',
66+
})
67+
}
68+
69+
return ctx
70+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import assert from 'node:assert/strict'
2+
import { mandatoryTest_6_1_27_14 } from '../../csaf_2_1/mandatoryTests/mandatoryTest_6_1_27_14.js'
3+
4+
describe('mandatoryTest_6_1_27_14', function () {
5+
it('only runs on documents matching the input schema', function () {
6+
assert.equal(
7+
mandatoryTest_6_1_27_14({
8+
document: 'invalid json',
9+
}).isValid,
10+
true
11+
)
12+
})
13+
14+
it('only runs on csaf_withdrawn and csaf_superseded documents', function () {
15+
assert.equal(
16+
mandatoryTest_6_1_27_14({
17+
document: {
18+
category: 'unknown category',
19+
},
20+
}).isValid,
21+
true
22+
)
23+
})
24+
})

tests/csaf_2_1/oasis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const excluded = [
2020
'6.1.27.11',
2121
'6.1.27.12',
2222
'6.1.27.13',
23-
'6.1.27.14',
2423
'6.1.27.15',
2524
'6.1.27.16',
2625
'6.1.27.17',

0 commit comments

Comments
 (0)