File tree Expand file tree Collapse file tree 4 files changed +95
-1
lines changed Expand file tree Collapse file tree 4 files changed +95
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export { mandatoryTest_6_1_1 } from './mandatoryTests/mandatoryTest_6_1_1.js'
3838export { mandatoryTest_6_1_8 } from './mandatoryTests/mandatoryTest_6_1_8.js'
3939export { mandatoryTest_6_1_11 } from './mandatoryTests/mandatoryTest_6_1_11.js'
4040export { mandatoryTest_6_1_13 } from './mandatoryTests/mandatoryTest_6_1_13.js'
41+ export { mandatoryTest_6_1_27_14 } from './mandatoryTests/mandatoryTest_6_1_27_14.js'
4142export { mandatoryTest_6_1_34 } from './mandatoryTests/mandatoryTest_6_1_34.js'
4243export { mandatoryTest_6_1_35 } from './mandatoryTests/mandatoryTest_6_1_35.js'
4344export { 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` ,
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 @@ -22,7 +22,6 @@ const excluded = [
2222 '6.1.27.11' ,
2323 '6.1.27.12' ,
2424 '6.1.27.13' ,
25- '6.1.27.14' ,
2625 '6.1.27.15' ,
2726 '6.1.27.16' ,
2827 '6.1.27.17' ,
You can’t perform that action at this time.
0 commit comments