Skip to content

Commit c943b14

Browse files
feat(CSAF2.1): #287 add mandatory test 6.1.42 - Part of the PURL that differs is appended to the message.
1 parent 7273f32 commit c943b14

File tree

5 files changed

+18392
-30
lines changed

5 files changed

+18392
-30
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ The following tests are not yet implemented and therefore missing:
317317
- Mandatory Test 6.1.26
318318
- Mandatory Test 6.1.27.13
319319
- Mandatory Test 6.1.27.18
320-
- Mandatory Test 6.1.27.19
321320
- Mandatory Test 6.1.44
322321
- Mandatory Test 6.1.45
323322
- Mandatory Test 6.1.46

csaf-validator-lib.iml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="WEB_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$" />
6+
<orderEntry type="inheritedJdk" />
7+
<orderEntry type="sourceFolder" forTests="false" />
8+
</component>
9+
</module>

csaf_2_1/mandatoryTests/mandatoryTest_6_1_42.js

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,47 @@ const validate = ajv.compile(inputSchema)
8181
/**
8282
*
8383
* @param {PackageURL | null} firstPurl
84-
* @param {PackageURL} secondPurl
85-
* @return {boolean}
84+
* @param {PackageURL | null} secondPurl
85+
* @return {Array<string>} the parts of the PURLS that differ
8686
*/
87-
function onlyDifferInQualifiers(firstPurl, secondPurl) {
88-
return (
89-
!!firstPurl &&
90-
firstPurl.type === secondPurl.type &&
91-
firstPurl.namespace === secondPurl.namespace &&
92-
firstPurl.name === secondPurl.name &&
93-
firstPurl.version === secondPurl.version
94-
)
87+
function purlPartsThatDifferExceptQualifiers(firstPurl, secondPurl) {
88+
/** @type {Array<string>}*/
89+
const partsThatDiffer = []
90+
91+
if (firstPurl && secondPurl) {
92+
if (firstPurl.type !== secondPurl.type) {
93+
partsThatDiffer.push('type')
94+
}
95+
if (firstPurl.namespace !== secondPurl.namespace) {
96+
partsThatDiffer.push('namespace')
97+
}
98+
if (firstPurl.name !== secondPurl.name) {
99+
partsThatDiffer.push('name')
100+
}
101+
if (firstPurl.version !== secondPurl.version) {
102+
partsThatDiffer.push('version')
103+
}
104+
}
105+
return partsThatDiffer
95106
}
96107

97108
/**
98109
* Validates all given PURLs and check whether the PURLs
99110
* differ only in qualifiers to the first URL
100111
*
101112
* @param {Array<string> | undefined} purls PURLs to check
102-
* @return {Array<number>} indexes of the PURLs that differ
113+
* @return {Array<{index:number, purlParts: Array<string> }>} indexes and parts of the PURLs that differ
103114
*/
104115
export function checkPurls(purls) {
105-
/** @type {Array<number>}*/
116+
/** @type {Array<{index:number, purlParts: Array<string> }>} */
106117
const invalidPurls = []
107118
if (purls) {
108119
/** @type {Array<PackageURL | null>} */
109120
const packageUrls = purls.map((purl) => {
110121
try {
111122
return PackageURL.fromString(purl)
112123
} catch (e) {
113-
// ignore
124+
// ignore, tested in CSAF 2.1 test 6.1.13
114125
return null
115126
}
116127
})
@@ -121,9 +132,13 @@ export function checkPurls(purls) {
121132
if (packageUrls.length > 1) {
122133
const firstPurl = packageUrls[0]
123134
for (let i = 1; i < packageUrls.length; i++) {
124-
const packageUrl = packageUrls[i]
125-
if (!packageUrl || !onlyDifferInQualifiers(firstPurl, packageUrl)) {
126-
invalidPurls.push(i)
135+
/** @type {Array<string>}*/
136+
const purlParts = purlPartsThatDifferExceptQualifiers(
137+
firstPurl,
138+
packageUrls[i]
139+
)
140+
if (purlParts.length > 0) {
141+
invalidPurls.push({ index: i, purlParts: purlParts })
127142
}
128143
}
129144
}
@@ -183,15 +198,14 @@ export function mandatoryTest_6_1_42(doc) {
183198
* @param {FullProductName} fullProductName The "full product name" object.
184199
*/
185200
function checkFullProductName(prefix, fullProductName) {
186-
const invalidPurlsIndexes = checkPurls(
201+
const invalidPurls = checkPurls(
187202
fullProductName.product_identification_helper?.purls
188203
)
189-
invalidPurlsIndexes.forEach((invalidPurlIndex) => {
204+
invalidPurls.forEach((invalidPurl) => {
190205
ctx.isValid = false
191206
ctx.errors.push({
192-
instancePath: `${prefix}/product_identification_helper/purls/${invalidPurlIndex}`,
193-
message:
194-
'the PURL differs from the first PURL in other parts than just the qualifiers',
207+
instancePath: `${prefix}/product_identification_helper/purls/${invalidPurl.index}`,
208+
message: `the PURL differs from the first PURL in the following part(s): ${invalidPurl.purlParts.join()}`,
195209
})
196210
})
197211
}
@@ -205,15 +219,14 @@ export function mandatoryTest_6_1_42(doc) {
205219
* @param {Branch} branch The "branch" object.
206220
*/
207221
function checkBranch(prefix, branch) {
208-
const invalidPurlsIndexes = checkPurls(
222+
const invalidPurls = checkPurls(
209223
branch.product?.product_identification_helper?.purls
210224
)
211-
invalidPurlsIndexes.forEach((invalidPurlIndex) => {
225+
invalidPurls.forEach((invalidPurl) => {
212226
ctx.isValid = false
213227
ctx.errors.push({
214-
instancePath: `${prefix}/product/product_identification_helper/purls/${invalidPurlIndex}`,
215-
message:
216-
'the PURL differs from the first PURL in other parts than just the qualifiers',
228+
instancePath: `${prefix}/product/product_identification_helper/purls/${invalidPurl.index}`,
229+
message: `the PURL differs from the first PURL in the following parts: ${invalidPurl.purlParts.join()}`,
217230
})
218231
})
219232
branch.branches?.forEach((branch, index) => {

0 commit comments

Comments
 (0)