From 91f6fac4235a1f4d32934d1652081a1c29cfc0e4 Mon Sep 17 00:00:00 2001 From: ybadaoui-ostorlab Date: Mon, 21 Oct 2024 13:08:44 +0100 Subject: [PATCH] add unittest for triggring network exception to fix code coverage --- tests/exploits/jetpack_version_detection_test.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/exploits/jetpack_version_detection_test.py b/tests/exploits/jetpack_version_detection_test.py index 7486b37..063038c 100644 --- a/tests/exploits/jetpack_version_detection_test.py +++ b/tests/exploits/jetpack_version_detection_test.py @@ -1,5 +1,6 @@ """Unit tests for Agent Asteroid: Jetpack Exploit""" +import pytest import requests_mock as req_mock from agent import definitions @@ -60,3 +61,16 @@ def testCVE20249487_whenNotVulnerable_reportNothing( assert accept is True assert len(vulnerabilities) == 0 + + +def testCVE20249487_whenNetworkErrorOccurs_reportNothing( + caplog: pytest.LogCaptureFixture, +) -> None: + """Jetpack Exploit unit test: case when network error occurs.""" + + exploit_instance = jetpack_version_detection.JetpackExploit() + target = definitions.Target("http", "nonexesit", 80) + + vulnerabilities = exploit_instance.check(target) + assert len(vulnerabilities) == 0 + assert "Network error occurred" in caplog.text