Skip to content
Draft
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: 2 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node-option:
- "experimental-wasm-modules"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ The following tests are not yet implemented and therefore missing:
- Mandatory Test 6.1.47
- Mandatory Test 6.1.48
- Mandatory Test 6.1.49
- Mandatory Test 6.1.50
- Mandatory Test 6.1.53
- Mandatory Test 6.1.54
- Mandatory Test 6.1.55
Expand Down Expand Up @@ -424,6 +423,7 @@ export const mandatoryTest_6_1_42: DocumentTest
export const mandatoryTest_6_1_43: DocumentTest
export const mandatoryTest_6_1_44: DocumentTest
export const mandatoryTest_6_1_45: DocumentTest
export const mandatoryTest_6_1_50: DocumentTest
export const mandatoryTest_6_1_51: DocumentTest
export const mandatoryTest_6_1_52: DocumentTest
```
Expand Down
1 change: 1 addition & 0 deletions csaf_2_1/mandatoryTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ export { mandatoryTest_6_1_42 } from './mandatoryTests/mandatoryTest_6_1_42.js'
export { mandatoryTest_6_1_43 } from './mandatoryTests/mandatoryTest_6_1_43.js'
export { mandatoryTest_6_1_44 } from './mandatoryTests/mandatoryTest_6_1_44.js'
export { mandatoryTest_6_1_45 } from './mandatoryTests/mandatoryTest_6_1_45.js'
export { mandatoryTest_6_1_50 } from '../lib/mandatoryTests/mandatoryTest_6_1_50.js'
export { mandatoryTest_6_1_51 } from './mandatoryTests/mandatoryTest_6_1_51.js'
export { mandatoryTest_6_1_52 } from './mandatoryTests/mandatoryTest_6_1_52.js'
115 changes: 115 additions & 0 deletions lib/mandatoryTests/mandatoryTest_6_1_50.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import Ajv from 'ajv/dist/jtd.js'
import { parse } from '@csaf-rs/vers-rs'

const ajv = new Ajv()

const inputSchema = /** @type {const} */ ({
additionalProperties: true,
optionalProperties: {
product_tree: {
additionalProperties: true,
optionalProperties: {
branches: { elements: { additionalProperties: true, properties: {} } },
},
},
},
})

const branchSchema = /** @type {const} */ ({
additionalProperties: true,
optionalProperties: {
category: { type: 'string' },
name: { type: 'string' },
branches: { elements: { additionalProperties: true, properties: {} } },
},
})

const validateInput = ajv.compile(inputSchema)
const validateBranch = ajv.compile(branchSchema)

/**
* @param {any} doc
*/
export function mandatoryTest_6_1_50(doc) {
/** @type {Array<{ message: string; instancePath: string }>} */
const errors = []

if (!validateInput(doc)) {
return { isValid: true, errors }
}

let isValid = true

// Check branches if they exist
if (doc.product_tree?.branches) {
isValid = checkBranches({
path: '/product_tree/branches',
branches: doc.product_tree.branches,
errors,
})
}

return { isValid, errors }
}

/**
* @param {object} params
* @param {string} params.path
* @param {unknown[]} params.branches
* @param {Array<{ message: string; instancePath: string }>} params.errors
* @returns {boolean} isValid
*/
function checkBranches({ path, branches, errors }) {
let isValid = true

branches.forEach((branch, branchIndex) => {
if (!validateBranch(branch)) {
return
}

if (
branch.category === 'product_version_range' &&
typeof branch.name === 'string'
) {
const version = branch.name

if (version.startsWith('vers:')) {
const parseResult = parseVers(version)
if (!parseResult.ok) {
isValid = false
errors.push({
message: `${parseResult.error}`,
instancePath: `${path}/${branchIndex}`,
})
}
} else {
// TODO: Vers-like Specifier (VLS) – noch nicht implementiert, da kein Repository vorhanden
}
}

// Recursively check nested branches
if (Array.isArray(branch.branches)) {
const nestedValid = checkBranches({
path: `${path}/${branchIndex}/branches`,
branches: branch.branches,
errors,
})
if (!nestedValid) isValid = false
}
})

return isValid
}

/**
* @param {string} version
* @returns {{ ok: true } | { ok: false; error: string }}
*/
function parseVers(version) {
try {
parse(version)
return { ok: true }
} catch (e) {
return { ok: false, error: e instanceof Error ? e.message : String(e) }
}
}
13 changes: 10 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"pretest": "tsc -b .",
"test": "prettier --check . && node scripts/test.js",
"test-vers": "node --experimental-wasm-modules csaf_2_1/test-vers-integration.js",
"pretest-report": "tsc -b .",
"test-report": "prettier --check . && node scripts/test.js --reporter json > test-results.json",
"test-coverage": "c8 node scripts/test.js",
Expand All @@ -23,6 +24,7 @@
"access": "public"
},
"dependencies": {
"@csaf-rs/vers-rs": "^0.1.2",
"@js-joda/core": "^5.6.1",
"@js-joda/timezone": "^2.18.2",
"ajv": "^8.11.2",
Expand Down
1 change: 0 additions & 1 deletion tests/csaf_2_1/oasis.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const excluded = [
'6.1.47',
'6.1.48',
'6.1.49',
'6.1.50',
'6.1.53',
'6.1.54',
'6.1.55',
Expand Down
Loading