-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add mandatory test 6.1.53 #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,96 @@ | ||||||
| import Ajv from 'ajv/dist/jtd.js' | ||||||
| import { compareZonedDateTimes } from '../dateHelper.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: { | ||||||
| tracking: { | ||||||
| additionalProperties: true, | ||||||
| properties: { | ||||||
| revision_history: { | ||||||
| elements: { | ||||||
| additionalProperties: true, | ||||||
| optionalProperties: { | ||||||
| date: { type: 'string' }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| vulnerabilities: { | ||||||
| elements: { | ||||||
| additionalProperties: true, | ||||||
| optionalProperties: { | ||||||
| first_known_exploitation_dates: { | ||||||
| elements: { | ||||||
| additionalProperties: true, | ||||||
| optionalProperties: { | ||||||
| date: { type: 'string' }, | ||||||
| exploitation_date: { type: 'string' }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| }) | ||||||
|
|
||||||
| const validate = ajv.compile(inputSchema) | ||||||
|
|
||||||
| /** | ||||||
| * This implements the mandatory test 6.1.53 of the CSAF 2.1 standard. | ||||||
| * | ||||||
| * @param {any} doc | ||||||
| */ | ||||||
| export function mandatoryTest_6_1_53(doc) { | ||||||
| /* | ||||||
| The `ctx` variable holds the state that is accumulated during the test ran and is | ||||||
| finally returned by the function. | ||||||
| */ | ||||||
| const ctx = { | ||||||
| errors: | ||||||
| /** @type {Array<{ instancePath: string; message: string }>} */ ([]), | ||||||
| isValid: true, | ||||||
| } | ||||||
|
|
||||||
| if (!validate(doc)) { | ||||||
| return ctx | ||||||
| } | ||||||
|
|
||||||
| doc.vulnerabilities?.forEach((vulnerability, vulnerabilityIndex) => { | ||||||
| const exploitDate = vulnerability.first_known_exploitation_dates || [] | ||||||
| exploitDate.forEach((exploit, exploitIdx) => { | ||||||
| const date = exploit.date | ||||||
| const exploitationDate = exploit.exploitation_date | ||||||
|
Comment on lines
+77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kinda dislike the variable being named |
||||||
|
|
||||||
| if ( | ||||||
| compareZonedDateTimes( | ||||||
| /** @type {string} */ (date), | ||||||
| /** @type {string} */ (exploitationDate) | ||||||
| ) < 0 | ||||||
christopher-exx marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| ) { | ||||||
| ctx.isValid = false | ||||||
| ctx.errors.push({ | ||||||
| instancePath: `/vulnerabilities/${vulnerabilityIndex}/first_known_exploitation_dates/${exploitIdx}`, | ||||||
| message: 'the "exploitation_date" is newer than the "date"', | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is unspecific what "the date" means.
Suggested change
|
||||||
| }) | ||||||
| } | ||||||
| }) | ||||||
| }) | ||||||
|
|
||||||
| return ctx | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { mandatoryTest_6_1_53 } from '../../csaf_2_1/mandatoryTests/mandatoryTest_6_1_53.js' | ||
|
|
||
| describe('mandatoryTest_6_1_53', function () { | ||
| it('only runs on relevant documents', function () { | ||
| assert.equal(mandatoryTest_6_1_53({ document: 'mydoc' }).isValid, true) | ||
| }) | ||
|
|
||
| it('skips empty vulnerability', function () { | ||
| assert.equal( | ||
| mandatoryTest_6_1_53({ | ||
| document: { | ||
| tracking: { | ||
| revision_history: [], | ||
| }, | ||
|
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| }, | ||
| vulnerabilities: [ | ||
| {}, // should be ignored | ||
| { | ||
| first_known_exploitation_dates: [ | ||
| { | ||
| date: '2024-01-24T12:34:56.789Z', | ||
| exploitation_date: '2024-01-24T13:00:00.000Z', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }).isValid, | ||
| false | ||
| ) | ||
| }) | ||
|
|
||
| it('skips empty first_known_exploitation_date', function () { | ||
| assert.equal( | ||
| mandatoryTest_6_1_53({ | ||
| document: { | ||
| tracking: { | ||
| revision_history: [], | ||
| }, | ||
| }, | ||
|
Comment on lines
+36
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here |
||
| vulnerabilities: [ | ||
| { | ||
| first_known_exploitation_dates: [ | ||
| {}, // should be ignored | ||
| { | ||
| date: '2024-01-24T12:34:56.789Z', | ||
| exploitation_date: '2024-01-24T13:00:00.000Z', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }).isValid, | ||
| false | ||
| ) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,6 @@ const excluded = [ | |
| '6.1.49', | ||
| '6.1.50', | ||
| '6.1.51', | ||
| '6.1.53', | ||
| '6.1.54', | ||
| '6.1.55', | ||
| '6.1.56', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is not relevant in the test.