-
Notifications
You must be signed in to change notification settings - Fork 9
feat(csaf2.1): add recommendedTest_6_2_49.js #680
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
bendo-eXX
wants to merge
1
commit into
main
Choose a base branch
from
feat/196-csaf-2.1_recommended_test_6.2.49
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
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,84 @@ | ||
| import { Ajv } from 'ajv/dist/jtd.js' | ||
| import { walkPath } from '../../lib/walkPaths.js' | ||
|
|
||
| const ajv = new Ajv() | ||
|
|
||
| const branchSchema = /** @type {const} */ ({ | ||
| additionalProperties: true, | ||
| optionalProperties: { | ||
| category: { type: 'string' }, | ||
| name: { type: 'string' }, | ||
| }, | ||
| }) | ||
|
|
||
| const validateBranch = ajv.compile(branchSchema) | ||
|
|
||
| // regex to match the prefix of a product version range that uses the `vers` comparator | ||
| const VERS_PREFIX = /^vers:[a-z\.\-\+][a-z0-9\.\-\+]*\// | ||
|
|
||
| // regex to match an upper open ended constraint, e.g. `>=1.0.0` or `>1.0.0` | ||
| const UPPER_OPEN_ENDED_CONSTRAINT = /^>=?/ | ||
|
|
||
| /** | ||
| * This implements the recommended test 6.2.49 of the CSAF 2.1 standard. | ||
| * | ||
| * @param {unknown} doc | ||
| */ | ||
| export async function recommendedTest_6_2_49(doc) { | ||
| const ctx = { | ||
| warnings: | ||
| /** @type {Array<{ instancePath: string; message: string }>} */ ([]), | ||
| } | ||
|
|
||
| await walkPath( | ||
| doc, | ||
| '/product_tree/branches[*]', | ||
| async (instancePath, value) => { | ||
| if (!validateBranch(value)) return | ||
| const branch = /** @type {{ category?: string; name?: string }} */ (value) | ||
|
|
||
| if ( | ||
| branch.category !== 'product_version_range' || | ||
| typeof branch.name !== 'string' | ||
| ) { | ||
| return | ||
| } | ||
|
|
||
| if (isUpperOpenEnded(branch.name)) { | ||
| ctx.warnings.push({ | ||
| instancePath: `${instancePath}/name`, | ||
| message: `The product version range "${branch.name}" is upper open ended.`, | ||
| }) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| return ctx | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether the last bound defining constraint of a product version | ||
| * range (vers or vls) is upper open ended. | ||
| * | ||
| * @param {string} name | ||
| * @returns {boolean} | ||
| */ | ||
| function isUpperOpenEnded(name) { | ||
| const trimmed = name.trim() | ||
| if (trimmed === 'vers:all/*') return false | ||
|
|
||
| const versMatch = trimmed.match(VERS_PREFIX) | ||
| const constraints = versMatch ? trimmed.slice(versMatch[0].length) : trimmed | ||
|
|
||
| const boundConstraints = constraints | ||
| .split('|') | ||
| .map((constraint) => constraint.trim()) | ||
| .filter( | ||
| (constraint) => constraint.length > 0 && !constraint.startsWith('!=') | ||
| ) | ||
|
|
||
| if (boundConstraints.length === 0) return false | ||
|
|
||
| const lastConstraint = boundConstraints[boundConstraints.length - 1] | ||
| return UPPER_OPEN_ENDED_CONSTRAINT.test(lastConstraint) | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -39,7 +39,6 @@ const excluded = [ | |
| '6.2.44', | ||
| '6.2.45', | ||
| '6.2.46', | ||
| '6.2.49', | ||
| '6.2.50.1', | ||
| '6.2.50.2', | ||
| '6.2.50.3', | ||
|
|
||
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,41 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { recommendedTest_6_2_49 } from '../../csaf_2_1/recommendedTests/recommendedTest_6_2_49.js' | ||
|
|
||
| describe('recommendedTest_6_2_49', function () { | ||
| it('skips invalid child branches that do not pass schema validation', async function () { | ||
| const result = await recommendedTest_6_2_49({ | ||
| product_tree: { | ||
| branches: [42, null], | ||
| }, | ||
| }) | ||
| assert.equal(result.warnings.length, 0) | ||
| }) | ||
|
|
||
| it('does not warn for the special "all versions" vers string', async function () { | ||
| const result = await recommendedTest_6_2_49({ | ||
| product_tree: { | ||
| branches: [ | ||
| { | ||
| category: 'product_version_range', | ||
| name: 'vers:all/*', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| assert.equal(result.warnings.length, 0) | ||
| }) | ||
|
|
||
| it('does not warn when only exclusion constraints are present', async function () { | ||
| const result = await recommendedTest_6_2_49({ | ||
| product_tree: { | ||
| branches: [ | ||
| { | ||
| category: 'product_version_range', | ||
| name: 'vers:intdot/!=5.1|!=6.3.0', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| assert.equal(result.warnings.length, 0) | ||
| }) | ||
| }) |
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
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 think this type cast is not needed as the validator already infers the type: