Skip to content

Commit f73837f

Browse files
committed
fix: remove dependency on VulnTotal utils
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 31c3b2b commit f73837f

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

‎vulnerabilities/pipelines/v2_importers/redhat_importer.py‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
3131
from vulnerabilities.pipes import extractcode_utils
3232
from vulnerabilities.severity_systems import REDHAT_AGGREGATE
33+
from vulnerabilities.utils import get_item
3334
from vulnerabilities.utils import load_json
34-
from vulntotal import vulntotal_utils
3535

3636

3737
class RedHatImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
@@ -135,7 +135,7 @@ def parse_advisory(self, record):
135135
)
136136
)
137137

138-
impacts = get_item(advisory, "product_tree", "branches", 0, "branches", default=[])
138+
impacts = get_item(advisory, "product_tree", "branches", 0, "branches") or []
139139
for impact in impacts:
140140
if impact["category"] == "product_family":
141141
continue
@@ -145,7 +145,6 @@ def parse_advisory(self, record):
145145
"product",
146146
"product_identification_helper",
147147
"purl",
148-
default=None,
149148
):
150149
if not purl.startswith("pkg:rpm/"):
151150
continue
@@ -188,11 +187,3 @@ def clean_download(self):
188187

189188
def on_failure(self):
190189
self.clean_download()
191-
192-
193-
def get_item(entity, *attributes, default=None):
194-
try:
195-
result = vulntotal_utils.get_item(entity, *attributes)
196-
except (KeyError, IndexError, TypeError) as e:
197-
result = default
198-
return result

‎vulnerabilities/tests/pipelines/v2_importers/test_redhat_importer_v2.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from vulnerabilities.models import PackageV2
1818
from vulnerabilities.pipelines.v2_importers.redhat_importer import RedHatImporterPipeline
1919
from vulnerabilities.tests import util_tests
20+
from vulnerabilities.tests.pipelines import TestLogger
2021
from vulnerabilities.utils import normalize_list
2122

2223
TEST_DATA = Path(__file__).parent.parent.parent / "test_data" / "redhat" / "csaf_2_0"
@@ -25,10 +26,15 @@
2526
class TestArchLinuxImporterPipeline(TestCase):
2627
@patch("vulnerabilities.pipelines.v2_importers.redhat_importer.RedHatImporterPipeline.fetch")
2728
def test_redhat_advisories_v2(self, mock_fetch):
29+
logger = TestLogger()
30+
2831
mock_fetch.__name__ = "fetch"
2932
pipeline = RedHatImporterPipeline()
3033
pipeline.location = TEST_DATA
31-
pipeline.execute()
34+
pipeline.log = logger.write
35+
exit_code, _ = pipeline.execute()
36+
37+
self.assertEqual(exit_code, 0)
3238
self.assertEqual(6, AdvisoryV2.objects.count())
3339
self.assertEqual(93, PackageV2.objects.count())
3440
expected_file = TEST_DATA.parent / "redhat_advisoryv2-expected.json"

0 commit comments

Comments
 (0)