Skip to content

Commit d8322e4

Browse files
feat(CSAF2.1): #197 add recommended test 6.2.43
1 parent fbc3fd4 commit d8322e4

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ The following tests are not yet implemented and therefore missing:
363363
- Recommended Test 6.2.40
364364
- Recommended Test 6.2.41
365365
- Recommended Test 6.2.42
366-
- Recommended Test 6.2.43
367366
- Recommended Test 6.2.44
368367
- Recommended Test 6.2.45
369368
- Recommended Test 6.2.46
@@ -462,6 +461,7 @@ export const recommendedTest_6_2_16: DocumentTest
462461
export const recommendedTest_6_2_17: DocumentTest
463462
export const recommendedTest_6_2_18: DocumentTest
464463
export const recommendedTest_6_2_22: DocumentTest
464+
export const recommendedTest_6_2_43: DocumentTest
465465
```
466466
467467
[(back to top)](#bsi-csaf-validator-lib)

csaf_2_1/recommendedTests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ export { recommendedTest_6_2_27 } from './recommendedTests/recommendedTest_6_2_2
3131
export { recommendedTest_6_2_28 } from './recommendedTests/recommendedTest_6_2_28.js'
3232
export { recommendedTest_6_2_29 } from './recommendedTests/recommendedTest_6_2_29.js'
3333
export { recommendedTest_6_2_38 } from './recommendedTests/recommendedTest_6_2_38.js'
34+
export { recommendedTest_6_2_43 } from './recommendedTests/recommendedTest_6_2_43.js'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Ajv from 'ajv/dist/jtd.js'
2+
const ajv = new Ajv()
3+
4+
/*
5+
This is the jtd schema that needs to match the input document so that the
6+
test is activated. If this schema doesn't match, it normally means that the input
7+
document does not validate against the csaf JSON schema or optional fields that
8+
the test checks are not present.
9+
*/
10+
const inputSchema = /** @type {const} */ ({
11+
additionalProperties: true,
12+
properties: {
13+
document: {
14+
additionalProperties: true,
15+
properties: {
16+
license_expression: {
17+
type: 'string',
18+
},
19+
},
20+
},
21+
},
22+
})
23+
24+
const validateSchema = ajv.compile(inputSchema)
25+
26+
/**
27+
* It MUST be tested that the license expression is present and set
28+
*
29+
* @param {unknown} doc
30+
*/
31+
export function recommendedTest_6_2_43(doc) {
32+
/*
33+
The `ctx` variable holds the state that is accumulated during the test run and is
34+
finally returned by the function.
35+
*/
36+
const ctx = {
37+
warnings:
38+
/** @type {Array<{ instancePath: string; message: string }>} */ ([]),
39+
}
40+
41+
if (!validateSchema(doc)) {
42+
ctx.warnings.push({
43+
message: 'License expression is not set',
44+
instancePath: '/document/license_expression',
45+
})
46+
}
47+
48+
return ctx
49+
}

tests/csaf_2_1/oasis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ const excluded = [
6363
'6.2.40',
6464
'6.2.41',
6565
'6.2.42',
66-
'6.2.43',
6766
'6.2.44',
6867
'6.2.45',
6968
'6.2.46',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import assert from 'node:assert'
2+
import { recommendedTest_6_2_43 } from '../../csaf_2_1/recommendedTests.js'
3+
4+
describe('recommendedTest_6_2_43', function () {
5+
it('only runs on relevant documents', function () {
6+
assert.equal(
7+
recommendedTest_6_2_43({ vulnerabilities: 'mydoc' }).warnings.length,
8+
1
9+
)
10+
})
11+
})

0 commit comments

Comments
 (0)