|
20 | 20 | from unittest import TestCase
|
21 | 21 |
|
22 | 22 | from cyclonedx.model import XsUri
|
23 |
| -from cyclonedx.model.impact_analysis import ImpactAnalysisAffectedStatus |
| 23 | +from cyclonedx.model.impact_analysis import ( |
| 24 | + ImpactAnalysisAffectedStatus, |
| 25 | + ImpactAnalysisJustification, |
| 26 | + ImpactAnalysisResponse, |
| 27 | + ImpactAnalysisState, |
| 28 | +) |
24 | 29 | from cyclonedx.model.vulnerability import (
|
25 | 30 | BomTarget,
|
26 | 31 | BomTargetVersionRange,
|
27 | 32 | Vulnerability,
|
28 | 33 | VulnerabilityAdvisory,
|
| 34 | + VulnerabilityAnalysis, |
29 | 35 | VulnerabilityRating,
|
30 | 36 | VulnerabilityReference,
|
31 | 37 | VulnerabilityScoreSource,
|
@@ -334,3 +340,24 @@ def test_sort(self) -> None:
|
334 | 340 | sorted_targets = sorted(targets)
|
335 | 341 | expected_targets = reorder(targets, expected_order)
|
336 | 342 | self.assertListEqual(sorted_targets, expected_targets)
|
| 343 | + |
| 344 | + |
| 345 | +class TestModelVulnerabilityAnalysis(TestCase): |
| 346 | + |
| 347 | + def test_sort(self) -> None: |
| 348 | + # expected sort order: ([state], [justification], [responses], [detail], [first_issued], [last_updated]) |
| 349 | + expected_order = [3, 1, 0, 2, 5, 4] |
| 350 | + analyses = [ |
| 351 | + VulnerabilityAnalysis(state=ImpactAnalysisState.EXPLOITABLE), |
| 352 | + VulnerabilityAnalysis(state=ImpactAnalysisState.EXPLOITABLE, |
| 353 | + responses=[ImpactAnalysisResponse.CAN_NOT_FIX]), |
| 354 | + VulnerabilityAnalysis(state=ImpactAnalysisState.NOT_AFFECTED, |
| 355 | + justification=ImpactAnalysisJustification.CODE_NOT_PRESENT), |
| 356 | + VulnerabilityAnalysis(state=ImpactAnalysisState.EXPLOITABLE, |
| 357 | + justification=ImpactAnalysisJustification.REQUIRES_ENVIRONMENT), |
| 358 | + VulnerabilityAnalysis(first_issued=datetime(2024, 4, 4), last_updated=datetime(2025, 5, 5)), |
| 359 | + VulnerabilityAnalysis(first_issued=datetime(2023, 3, 3), last_updated=datetime(2023, 3, 3)), |
| 360 | + ] |
| 361 | + sorted_analyses = sorted(analyses) |
| 362 | + expected_analyses = reorder(analyses, expected_order) |
| 363 | + self.assertListEqual(sorted_analyses, expected_analyses) |
0 commit comments