-
Notifications
You must be signed in to change notification settings - Fork 9
feat(CSAF2.1): #287 add mandatory test 6.1.26 #380
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
Open
rainer-exxcellent
wants to merge
4
commits into
main
Choose a base branch
from
feat/287-csaf-2.1-mandatory-test-6.1.26
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
05bfb5f
feat(CSAF2.1): #287 add mandatory test 6.1.26
rainer-exxcellent 963f2d6
feat(CSAF2.1): #287 add mandatory test 6.1.42 - change variable name
rainer-exxcellent 2fdc487
feat(CSAF2.1): #287 add mandatory test 6.1.42 - fix quotes
rainer-exxcellent 87aee97
feat(CSAF2.1): #287 add mandatory test 6.1.26 - changed some comments…
rainer-exxcellent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import Ajv from 'ajv/dist/jtd.js' | ||
|
|
||
| const jtdAjv = 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: { | ||
| category: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| const validateInput = jtdAjv.compile(inputSchema) | ||
|
|
||
| const allowedCategoryNames = [ | ||
| 'csaf_base', | ||
| 'csaf_security_incident_response', | ||
| 'csaf_informational_advisory', | ||
| 'csaf_security_advisory', | ||
| 'csaf_vex', | ||
| 'csaf_deprecated_security_advisory', | ||
| 'csaf_withdrawn', | ||
| 'csaf_superseded', | ||
| ] | ||
|
|
||
| // lowercase category names with without the prefix csaf_ and removed dash, whitespace, and underscore characters | ||
| // without csaf_base | ||
| const prohibitedCategoriesWithoutPrefix = [ | ||
| 'securityincidentresponse', | ||
| 'informationaladvisory', | ||
| 'securityadvisory', | ||
| 'vex', | ||
| 'deprecatedsecurityadvisory', | ||
| 'withdrawn', | ||
| 'superseded', | ||
| ] | ||
|
|
||
| /** | ||
| * It MUST be tested that the document category is not equal to the (case-insensitive) name (without the prefix csaf_) | ||
| * or value of any other profile than "CSAF Base". Any occurrences of dash, whitespace, and underscore characters are | ||
| * removed from the values on both sides before the match. | ||
| * Also, the value MUST NOT start with the reserved prefix csaf_ except if the value is csaf_base. | ||
| * @param {unknown} doc | ||
| */ | ||
| export function mandatoryTest_6_1_26(doc) { | ||
| const ctx = { | ||
| errors: | ||
| /** @type {Array<{ instancePath: string; message: string }>} */ ([]), | ||
| isValid: true, | ||
| } | ||
| if (!validateInput(doc)) { | ||
| return ctx | ||
| } | ||
|
|
||
| /** @type {string} */ | ||
| const category = doc.document.category | ||
|
|
||
| // Skip test for the allowedCategoryNames in /document/category: | ||
| if (allowedCategoryNames.includes(category)) { | ||
| return ctx | ||
| } | ||
|
|
||
| // Fail on reserved prefix | ||
| if (category.toLowerCase().startsWith('csaf_')) { | ||
| ctx.isValid = false | ||
| ctx.errors.push({ | ||
| instancePath: '/document/category', | ||
| message: 'reserved prefix "csaf_" used', | ||
| }) | ||
|
|
||
| return ctx | ||
| } | ||
|
|
||
| // Fail on name case-insensitive similarity | ||
| if ( | ||
| prohibitedCategoriesWithoutPrefix.includes( | ||
| //remove occurrences of dash, whitespace, and underscore characters | ||
| category.replace(/[_-\s]+/g, '').toLowerCase() | ||
| ) | ||
| ) { | ||
| ctx.isValid = false | ||
| ctx.errors.push({ | ||
| instancePath: '/document/category', | ||
| message: 'value prohibited', | ||
| }) | ||
| } | ||
| return ctx | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { mandatoryTest_6_1_26 } from '../../csaf_2_1/mandatoryTests/mandatoryTest_6_1_26.js' | ||
|
|
||
| describe('mandatoryTest_6_1_26', function () { | ||
| it('only runs on relevant documents', function () { | ||
| assert.equal(mandatoryTest_6_1_26({ document: 'mydoc' }).isValid, true) | ||
| }) | ||
| it('check use of reserved prefix csaf_ except if the value is csaf_base', function () { | ||
| assert.equal( | ||
| mandatoryTest_6_1_26({ | ||
| document: { | ||
| category: 'csaf_invalid', | ||
| }, | ||
| }).isValid, | ||
| false | ||
| ) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I guess this does not match the unicode variants...