From 1df5d046ee1c7abcfd9185569e780975f68a2349 Mon Sep 17 00:00:00 2001 From: Faizan Date: Tue, 23 Jan 2024 10:40:29 -0500 Subject: [PATCH] changing trivy_image folder to just trivy to match API changes --- .../{trivy_image => trivy}/__init__.py | 0 .../plugins/{trivy_image => trivy}/main.py | 0 .../{trivy_image => trivy}/settings.json | 0 backend/engine/tests/test_trivy_image.py | 2 +- backend/engine/tests/test_trivy_sca.py | 28 +++++++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) rename backend/engine/plugins/{trivy_image => trivy}/__init__.py (100%) rename backend/engine/plugins/{trivy_image => trivy}/main.py (100%) rename backend/engine/plugins/{trivy_image => trivy}/settings.json (100%) diff --git a/backend/engine/plugins/trivy_image/__init__.py b/backend/engine/plugins/trivy/__init__.py similarity index 100% rename from backend/engine/plugins/trivy_image/__init__.py rename to backend/engine/plugins/trivy/__init__.py diff --git a/backend/engine/plugins/trivy_image/main.py b/backend/engine/plugins/trivy/main.py similarity index 100% rename from backend/engine/plugins/trivy_image/main.py rename to backend/engine/plugins/trivy/main.py diff --git a/backend/engine/plugins/trivy_image/settings.json b/backend/engine/plugins/trivy/settings.json similarity index 100% rename from backend/engine/plugins/trivy_image/settings.json rename to backend/engine/plugins/trivy/settings.json diff --git a/backend/engine/tests/test_trivy_image.py b/backend/engine/tests/test_trivy_image.py index ffc6d6ee..347932ca 100644 --- a/backend/engine/tests/test_trivy_image.py +++ b/backend/engine/tests/test_trivy_image.py @@ -6,7 +6,7 @@ import pytest from docker import builder, remover -from engine.plugins.trivy_image import main as Trivy +from engine.plugins.trivy import main as Trivy TEST_DIR = os.path.dirname(os.path.abspath(__file__)) diff --git a/backend/engine/tests/test_trivy_sca.py b/backend/engine/tests/test_trivy_sca.py index 9409aac3..0ae8233e 100644 --- a/backend/engine/tests/test_trivy_sca.py +++ b/backend/engine/tests/test_trivy_sca.py @@ -6,6 +6,7 @@ from docker import builder, remover from engine.plugins.trivy_sca import main as Trivy +from engine.plugins.lib.trivy_common.generate_locks import check_package_files TEST_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -112,6 +113,33 @@ def setUp(self) -> None: with open(TEST_OUTPUT) as output_file: self.demo_results_dict = json.load(output_file) + def test_lock_file_exists(self): + with patch(f"{AUDIT_PREFIX}os.path.exists", return_value=True): + with patch(f"{AUDIT_PREFIX}subprocess.run") as mock_proc: + mock_proc.stderr = mock_proc.stdout = None + mock_proc.return_value = CompletedProcess(args="", returncode=0) + + actual = check_package_files("foo") + + self.assertNotIn("warning", actual["results"]) + self.assertFalse(actual["lockfile_missing"]) + + def test_lock_file_missing(self): + with patch(f"{AUDIT_PREFIX}os.path.exists", return_value=False): + with patch(f"{AUDIT_PREFIX}subprocess.run") as mock_proc: + mock_proc.stderr = mock_proc.stdout = None + mock_proc.return_value = CompletedProcess(args="", returncode=0) + + actual = check_package_files("foo") + + self.assertIn("warning", actual["results"]) + expected_msg = ( + "No package-lock.json file was found in path foo. " + "Please consider creating a package-lock file for this project." + ) + self.assertEqual(actual["results"]["warning"], expected_msg) + self.assertTrue(actual["lockfile_missing"]) + def test_check_output(self): check_output_list = Trivy.parse_output(self.demo_results_dict) self.assertIn(TEST_CHECK_OUTPUT_PACKAGE_LOCK, check_output_list)