|
24 | 24 | from vulnerabilities import models |
25 | 25 | from vulnerabilities.importer import AdvisoryData |
26 | 26 | from vulnerabilities.importer import AffectedPackage |
| 27 | +from vulnerabilities.importer import AffectedPackageV2 |
| 28 | +from vulnerabilities.importer import PackageCommitPatchData |
| 29 | +from vulnerabilities.importer import PatchData |
27 | 30 | from vulnerabilities.importer import Reference |
| 31 | +from vulnerabilities.importer import ReferenceV2 |
28 | 32 | from vulnerabilities.models import AdvisorySeverity |
29 | 33 | from vulnerabilities.models import Alias |
30 | 34 | from vulnerabilities.models import Package |
@@ -735,3 +739,34 @@ def test_constraint_none(self): |
735 | 739 | scoring_system=CVSSV4, |
736 | 740 | scoring_elements="CVSS:4.0/AV:P/AC:H/AT:P/PR:H/UI:A/VC:L/VI:L/VA:H/SC:H/SI:L/SA:L/E:A/CR:M/IR:M/AR:M/MAV:A/MAC:L/MAT:P/MPR:L/MVC:L/MVI:L/MVA:L/MSC:H/MSI:H/MSA:H/S:P/AU:Y/R:U/V:C/RE:M/U:Amber", |
737 | 741 | ) |
| 742 | + |
| 743 | + |
| 744 | +class TestAdvisoryV2Model(DjangoTestCase): |
| 745 | + def setUp(self): |
| 746 | + self.advisoryv2_data1 = AdvisoryData( |
| 747 | + advisory_id="test_adv", |
| 748 | + aliases=[], |
| 749 | + summary="vulnerability description here", |
| 750 | + affected_packages=[ |
| 751 | + AffectedPackageV2( |
| 752 | + package=PackageURL(type="pypi", name="dummy"), |
| 753 | + affected_version_range=VersionRange.from_string("vers:pypi/>=1.0.0|<=2.0.0"), |
| 754 | + introduced_by_commit_patches=[ |
| 755 | + PackageCommitPatchData( |
| 756 | + vcs_url="http://foo.bar/", commit_hash="c4eab154606e801" |
| 757 | + ) |
| 758 | + ], |
| 759 | + ) |
| 760 | + ], |
| 761 | + references_v2=[ReferenceV2(url="https://example.com/with/more/info/CVE-2020-13371337")], |
| 762 | + patches=[PatchData(patch_url="https://foo.bar/", patch_text="test patch")], |
| 763 | + url="https://test.com", |
| 764 | + ) |
| 765 | + |
| 766 | + def test_advisoryv2_to_advisory_data_patch_seralization(self): |
| 767 | + from vulnerabilities.pipes.advisory import insert_advisory_v2 |
| 768 | + |
| 769 | + insert_advisory_v2(advisory=self.advisoryv2_data1, pipeline_id="test_pipeline") |
| 770 | + result = models.AdvisoryV2.objects.first().to_advisory_data() |
| 771 | + |
| 772 | + self.assertEqual(result, self.advisoryv2_data1) |
0 commit comments