Skip to content

Commit 3ba89c6

Browse files
Merge pull request #367 from secvisogram/feat/363-csaf-2.1_recommended_test_6.2.43
feat(CSAF2.1): #197 add recommended test 6.2.43
2 parents 5fc5153 + 7c286f1 commit 3ba89c6

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
@@ -349,7 +349,6 @@ The following tests are not yet implemented and therefore missing:
349349
- Recommended Test 6.2.40
350350
- Recommended Test 6.2.41
351351
- Recommended Test 6.2.42
352-
- Recommended Test 6.2.43
353352
- Recommended Test 6.2.44
354353
- Recommended Test 6.2.45
355354
- Recommended Test 6.2.46
@@ -461,6 +460,7 @@ export const recommendedTest_6_2_18: DocumentTest
461460
export const recommendedTest_6_2_22: DocumentTest
462461
export const recommendedTest_6_2_23: DocumentTest
463462
export const recommendedTest_6_2_25: DocumentTest
463+
export const recommendedTest_6_2_43: DocumentTest
464464
```
465465
466466
[(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
@@ -33,3 +33,4 @@ export { recommendedTest_6_2_27 } from './recommendedTests/recommendedTest_6_2_2
3333
export { recommendedTest_6_2_28 } from './recommendedTests/recommendedTest_6_2_28.js'
3434
export { recommendedTest_6_2_29 } from './recommendedTests/recommendedTest_6_2_29.js'
3535
export { recommendedTest_6_2_38 } from './recommendedTests/recommendedTest_6_2_38.js'
36+
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
@@ -52,7 +52,6 @@ const excluded = [
5252
'6.2.40',
5353
'6.2.41',
5454
'6.2.42',
55-
'6.2.43',
5655
'6.2.44',
5756
'6.2.45',
5857
'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)