Skip to content

Commit 1e208cf

Browse files
committed
Add a test, and update Kev pipeline
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent f1e9c5a commit 1e208cf

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

vulnerabilities/pipelines/enhance_with_kev.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def add_vulnerability_exploit(kev_vul, logger):
8080
logger(f"No vulnerability found for aliases {cve_id}")
8181
return 0
8282

83+
if not vulnerability:
84+
logger(f"No vulnerability found for aliases {cve_id}")
85+
return 0
86+
8387
Exploit.objects.update_or_create(
8488
vulnerability=vulnerability,
8589
data_source="KEV",

vulnerabilities/tests/pipelines/test_enhance_with_exploitdb.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,18 @@ def test_exploit_db_improver(mock_get):
4545
# Run Exploit-DB Improver again when there are matching aliases.
4646
improver.execute()
4747
assert Exploit.objects.count() == 1
48+
49+
50+
@pytest.mark.django_db
51+
@mock.patch("requests.get")
52+
def test_invalid_exploit_db_improver(mock_get):
53+
mock_response = Mock(status_code=200)
54+
with open(TEST_DATA, "r") as f:
55+
mock_response.text = f.read()
56+
mock_get.return_value = mock_response
57+
58+
improver = ExploitDBImproverPipeline()
59+
Alias.objects.create(alias="CVE-2009-3699", vulnerability=None)
60+
status, _ = improver.execute()
61+
assert status == 0
62+
assert Exploit.objects.count() == 0

vulnerabilities/tests/pipelines/test_enhance_with_kev.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,18 @@ def test_kev_improver(mock_get):
4545
# Run Kev Improver again when there are matching aliases.
4646
improver.execute()
4747
assert Exploit.objects.count() == 1
48+
49+
50+
@pytest.mark.django_db
51+
@mock.patch("requests.get")
52+
def test_invalid_kev_improver(mock_get):
53+
mock_response = Mock(status_code=200)
54+
mock_response.json.return_value = load_json(TEST_DATA)
55+
mock_get.return_value = mock_response
56+
57+
improver = VulnerabilityKevPipeline()
58+
Alias.objects.create(alias="CVE-2021-38647", vulnerability=None)
59+
60+
status, _ = improver.execute()
61+
assert status == 0
62+
assert Exploit.objects.count() == 0

vulnerabilities/tests/pipelines/test_enhance_with_metasploit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,17 @@ def test_metasploit_improver(mock_get):
4242
# Run metasploit Improver again when there are matching aliases.
4343
improver.execute()
4444
assert Exploit.objects.count() == 1
45+
46+
47+
@pytest.mark.django_db
48+
@mock.patch("requests.get")
49+
def test_invalid_metasploit_improver(mock_get):
50+
mock_response = Mock(status_code=200)
51+
mock_response.json.return_value = load_json(TEST_DATA)
52+
mock_get.return_value = mock_response
53+
54+
Alias.objects.create(alias="CVE-2007-4387", vulnerability=None) # Alias without vulnerability
55+
improver = MetasploitImproverPipeline()
56+
status, _ = improver.execute()
57+
assert status == 0
58+
assert Exploit.objects.count() == 0

0 commit comments

Comments
 (0)