Skip to content

Commit 6963b41

Browse files
refactor: simplify implementation
1 parent e0a7d65 commit 6963b41

File tree

1 file changed

+38
-42
lines changed

1 file changed

+38
-42
lines changed

csaf_2_1/mandatoryTests/mandatoryTest_6_1_48.js

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -78,51 +78,47 @@ export function mandatoryTest_6_1_48(doc) {
7878
doc.vulnerabilities.forEach((vulnerability, vulnerabilityIndex) => {
7979
vulnerability.metrics?.forEach((metric, metricIndex) => {
8080
const selections = metric.content?.ssvc_v1.selections
81-
if (selections) {
82-
selections.forEach((selection, selectionIndex) => {
83-
if (selection.namespace) {
84-
if (registeredSsvcNamespaces.includes(selection.namespace)) {
85-
const decisionPoints = ssvcDecisionPoints.decisionPoints
86-
87-
// check if a decision point with these properties exists
88-
const currentDecisionPoints = decisionPoints.filter(
89-
(dp) =>
90-
dp.name === selection.name &&
91-
dp.namespace === selection.namespace &&
92-
dp.version === selection.version
81+
const selectionsWithRegisteredNamespace = selections?.filter(
82+
(s) =>
83+
s.namespace !== undefined &&
84+
registeredSsvcNamespaces.includes(s.namespace)
85+
)
86+
selectionsWithRegisteredNamespace?.forEach(
87+
(selection, selectionIndex) => {
88+
// check if a decision point with these properties exists
89+
const filteredDecisionPoints =
90+
ssvcDecisionPoints.decisionPoints.filter(
91+
(dp) =>
92+
dp.name === selection.name &&
93+
dp.namespace === selection.namespace &&
94+
dp.version === selection.version
95+
)
96+
if (filteredDecisionPoints.length === 0) {
97+
ctx.isValid = false
98+
ctx.errors.push({
99+
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/selections/${selectionIndex}`,
100+
message: `there exists no decision point with name ${selection.name} and version ${selection.version} in the namespace ${selection.namespace}`,
101+
})
102+
} else {
103+
// name, namespace and version define a unique decisionPoint, i.e. the array filteredDecisionPoints
104+
// can only have zero (catched in the previous if-statement) or one entry.
105+
// Therefore, it is sufficient to access the first and only entry in filteredDecisionPoints here
106+
if (
107+
selection.values &&
108+
!areValuesValidAndinOrder(
109+
filteredDecisionPoints[0].values.map((value) => value.name),
110+
selection.values
93111
)
94-
if (currentDecisionPoints.length === 0) {
95-
ctx.isValid = false
96-
ctx.errors.push({
97-
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/selections/${selectionIndex}`,
98-
message: `there exists no decision point with name ${selection.name} and version ${selection.version} in the namespace ${selection.namespace}`,
99-
})
100-
} else {
101-
if (selection.values) {
102-
// name, namespace and version define a unique decisionPoint, i.e. the array currentDecisionPoint
103-
// can only have zero (catched in the previous if-statement) or one entry.
104-
// Therefore, it is sufficient to access the first and only entry in currentDecisionPoint here
105-
if (
106-
!areValuesValidAndinOrder(
107-
currentDecisionPoints[0].values.map(
108-
(value) => value.name
109-
),
110-
selection.values
111-
)
112-
) {
113-
ctx.isValid = false
114-
ctx.errors.push({
115-
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/selections/${selectionIndex}`,
116-
message: `this decision point contains invalid values or its values are not in order`,
117-
})
118-
}
119-
}
120-
}
112+
) {
113+
ctx.isValid = false
114+
ctx.errors.push({
115+
instancePath: `/vulnerabilities/${vulnerabilityIndex}/metrics/${metricIndex}/content/ssvc_v1/selections/${selectionIndex}`,
116+
message: `this decision point contains invalid values or its values are not in order`,
117+
})
121118
}
122-
// in the else-case, i.e. if a non-registered namespace is used, this test shall pass
123119
}
124-
})
125-
}
120+
}
121+
)
126122
})
127123
})
128124

0 commit comments

Comments
 (0)