Skip to content

Commit efee6b1

Browse files
Merge pull request #246 from secvisogram/196-csaf-2.1_optional_test_6.2.22
feat: add optional test 6.2.22
2 parents f8a4481 + 650cd5b commit efee6b1

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

csaf_2_1/optionalTests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export {
1919
optionalTest_6_2_20,
2020
} from '../optionalTests.js'
2121
export { optionalTest_6_2_3 } from './optionalTests/optionalTest_6_2_3.js'
22+
export { optionalTest_6_2_22 } from './optionalTests/optionalTest_6_2_22.js'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import Ajv from 'ajv/dist/jtd.js'
2+
3+
const ajv = new Ajv()
4+
5+
const inputSchema = /** @type {const} */ ({
6+
additionalProperties: true,
7+
properties: {
8+
document: {
9+
additionalProperties: true,
10+
properties: {
11+
title: { type: 'string' },
12+
tracking: {
13+
additionalProperties: true,
14+
properties: {
15+
id: { type: 'string' },
16+
},
17+
},
18+
},
19+
},
20+
},
21+
})
22+
23+
const validate = ajv.compile(inputSchema)
24+
25+
/**
26+
* @param {any} doc
27+
*/
28+
export function optionalTest_6_2_22(doc) {
29+
/** @type {Array<{ message: string; instancePath: string }>} */
30+
const warnings = []
31+
const context = { warnings }
32+
33+
if (!validate(doc)) {
34+
return context
35+
}
36+
37+
const trackingId = doc.document.tracking.id
38+
const documentTitle = doc.document.title
39+
if (documentTitle.includes(trackingId)) {
40+
context.warnings.push({
41+
message: `document title contains the tracking id ${trackingId}`,
42+
instancePath: `/document/title`,
43+
})
44+
}
45+
46+
return context
47+
}

tests/csaf_2_1/oasis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const excluded = [
3838
'6.2.11',
3939
'6.2.19',
4040
'6.2.21',
41-
'6.2.22',
4241
'6.2.23',
4342
'6.2.24',
4443
'6.2.25',
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 { optionalTest_6_2_22 } from '../../csaf_2_1/optionalTests.js'
3+
4+
describe('optionalTest_6_2_22', function () {
5+
it('only runs on relevant documents', function () {
6+
assert.equal(
7+
optionalTest_6_2_22({ vulnerabilities: 'mydoc' }).warnings.length,
8+
0
9+
)
10+
})
11+
})

0 commit comments

Comments
 (0)