Skip to content

Commit 1856a92

Browse files
feat(CSAF2.1): #287 add mandatory test 6.1.42 - refactor input schema
1 parent 982f1eb commit 1856a92

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

csaf_2_1/mandatoryTests/mandatoryTest_6_1_42.js

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,33 @@ import Ajv from 'ajv/dist/jtd.js'
33

44
const ajv = new Ajv()
55

6-
const branchSchema = /** @type {const} */ ({
6+
const fullProductNameSchema = /** @type {const} */ ({
77
additionalProperties: true,
88
optionalProperties: {
9-
branches: {
10-
elements: {
11-
additionalProperties: true,
12-
properties: {},
13-
},
14-
},
15-
product: {
9+
product_identification_helper: {
1610
additionalProperties: true,
1711
optionalProperties: {
18-
product_identification_helper: {
19-
additionalProperties: true,
20-
optionalProperties: {
21-
purls: { elements: { type: 'string' } },
22-
},
23-
},
12+
purls: { elements: { type: 'string' } },
2413
},
2514
},
2615
},
2716
})
2817

29-
const validateBranch = ajv.compile(branchSchema)
30-
31-
const fullProductNameSchema = /** @type {const} */ ({
18+
const branchSchema = /** @type {const} */ ({
3219
additionalProperties: true,
3320
optionalProperties: {
34-
product_identification_helper: {
35-
additionalProperties: true,
36-
optionalProperties: {
37-
purls: { elements: { type: 'string' } },
21+
branches: {
22+
elements: {
23+
additionalProperties: true,
24+
properties: {},
3825
},
3926
},
27+
product: fullProductNameSchema,
4028
},
4129
})
4230

31+
const validateBranch = ajv.compile(branchSchema)
32+
4333
/*
4434
This is the jtd schema that needs to match the input document so that the
4535
test is activated. If this schema doesn't match, it normally means that the input
@@ -81,24 +71,24 @@ const validate = ajv.compile(inputSchema)
8171
/**
8272
*
8373
* @param {PackageURL | null} firstPurl
84-
* @param {PackageURL | null} secondPurl
74+
* @param {PackageURL | null} otherPurl
8575
* @return {Array<string>} the parts of the PURLS that differ
8676
*/
87-
function purlPartsThatDifferExceptQualifiers(firstPurl, secondPurl) {
77+
function purlPartsThatDifferExceptQualifiers(firstPurl, otherPurl) {
8878
/** @type {Array<string>}*/
8979
const partsThatDiffer = []
9080

91-
if (firstPurl && secondPurl) {
92-
if (firstPurl.type !== secondPurl.type) {
81+
if (firstPurl && otherPurl) {
82+
if (firstPurl.type !== otherPurl.type) {
9383
partsThatDiffer.push('type')
9484
}
95-
if (firstPurl.namespace !== secondPurl.namespace) {
85+
if (firstPurl.namespace !== otherPurl.namespace) {
9686
partsThatDiffer.push('namespace')
9787
}
98-
if (firstPurl.name !== secondPurl.name) {
88+
if (firstPurl.name !== otherPurl.name) {
9989
partsThatDiffer.push('name')
10090
}
101-
if (firstPurl.version !== secondPurl.version) {
91+
if (firstPurl.version !== otherPurl.version) {
10292
partsThatDiffer.push('version')
10393
}
10494
}

0 commit comments

Comments
 (0)