Skip to content

Commit

Permalink
changing trivy_image folder to just trivy to match API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
faizanH committed Jan 23, 2024
1 parent 3520f26 commit 1df5d04
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/engine/tests/test_trivy_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand Down
28 changes: 28 additions & 0 deletions backend/engine/tests/test_trivy_sca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1df5d04

Please sign in to comment.