File tree Expand file tree Collapse file tree 5 files changed +96
-2
lines changed Expand file tree Collapse file tree 5 files changed +96
-2
lines changed Original file line number Diff line number Diff 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
422421export const mandatoryTest_6_1_27_9: DocumentTest
423422export const mandatoryTest_6_1_27_10: DocumentTest
424423export const mandatoryTest_6_1_27_11: DocumentTest
424+ export const mandatoryTest_6_1_27_14: DocumentTest
425425export const mandatoryTest_6_1_28: DocumentTest
426426export const mandatoryTest_6_1_29: DocumentTest
427427export const mandatoryTest_6_1_30: DocumentTest
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ export { mandatoryTest_6_1_8 } from './mandatoryTests/mandatoryTest_6_1_8.js'
4040export { mandatoryTest_6_1_11 } from './mandatoryTests/mandatoryTest_6_1_11.js'
4141export { mandatoryTest_6_1_13 } from './mandatoryTests/mandatoryTest_6_1_13.js'
4242export { 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'
4344export { mandatoryTest_6_1_34 } from './mandatoryTests/mandatoryTest_6_1_34.js'
4445export { mandatoryTest_6_1_35 } from './mandatoryTests/mandatoryTest_6_1_35.js'
4546export { mandatoryTest_6_1_9 } from './mandatoryTests/mandatoryTest_6_1_9.js'
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ } )
Original file line number Diff line number Diff 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' ,
You can’t perform that action at this time.
0 commit comments