Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ The following tests are not yet implemented and therefore missing:
- Recommended Test 6.2.40
- Recommended Test 6.2.41
- Recommended Test 6.2.42
- Recommended Test 6.2.43
- Recommended Test 6.2.44
- Recommended Test 6.2.45
- Recommended Test 6.2.46
Expand Down Expand Up @@ -461,6 +460,7 @@ export const recommendedTest_6_2_17: DocumentTest
export const recommendedTest_6_2_18: DocumentTest
export const recommendedTest_6_2_22: DocumentTest
export const recommendedTest_6_2_23: DocumentTest
export const recommendedTest_6_2_43: DocumentTest
```

[(back to top)](#bsi-csaf-validator-lib)
Expand Down
1 change: 1 addition & 0 deletions csaf_2_1/recommendedTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export { recommendedTest_6_2_27 } from './recommendedTests/recommendedTest_6_2_2
export { recommendedTest_6_2_28 } from './recommendedTests/recommendedTest_6_2_28.js'
export { recommendedTest_6_2_29 } from './recommendedTests/recommendedTest_6_2_29.js'
export { recommendedTest_6_2_38 } from './recommendedTests/recommendedTest_6_2_38.js'
export { recommendedTest_6_2_43 } from './recommendedTests/recommendedTest_6_2_43.js'
49 changes: 49 additions & 0 deletions csaf_2_1/recommendedTests/recommendedTest_6_2_43.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Ajv from 'ajv/dist/jtd.js'
const ajv = new Ajv()

/*
This is the jtd schema that needs to match the input document so that the
test is activated. If this schema doesn't match, it normally means that the input
document does not validate against the csaf JSON schema or optional fields that
the test checks are not present.
*/
const inputSchema = /** @type {const} */ ({
additionalProperties: true,
properties: {
document: {
additionalProperties: true,
properties: {
license_expression: {
type: 'string',
},
},
},
},
})

const validateSchema = ajv.compile(inputSchema)

/**
* It MUST be tested that the license expression is present and set
*
* @param {unknown} doc
*/
export function recommendedTest_6_2_43(doc) {
/*
The `ctx` variable holds the state that is accumulated during the test run and is
finally returned by the function.
*/
const ctx = {
warnings:
/** @type {Array<{ instancePath: string; message: string }>} */ ([]),
}

if (!validateSchema(doc)) {
ctx.warnings.push({
message: 'License expression is not set',
instancePath: '/document/license_expression',
})
}

return ctx
}
1 change: 0 additions & 1 deletion tests/csaf_2_1/oasis.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const excluded = [
'6.2.40',
'6.2.41',
'6.2.42',
'6.2.43',
'6.2.44',
'6.2.45',
'6.2.46',
Expand Down
11 changes: 11 additions & 0 deletions tests/csaf_2_1/recommendedTest_6_2_43.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import assert from 'node:assert'
import { recommendedTest_6_2_43 } from '../../csaf_2_1/recommendedTests.js'

describe('recommendedTest_6_2_43', function () {
it('only runs on relevant documents', function () {
assert.equal(
recommendedTest_6_2_43({ vulnerabilities: 'mydoc' }).warnings.length,
1
)
})
})