diff --git a/installer/tests/test_scan.py b/installer/tests/test_scan.py index 06e84ec..a54775d 100644 --- a/installer/tests/test_scan.py +++ b/installer/tests/test_scan.py @@ -49,6 +49,9 @@ def fake_runner(trivy_json=TRIVY_CLEAN, semgrep_json=SEMGREP_EMPTY, gitleaks_jso sbom_rc=0, trivy_fail_target=None, zap_rc=0, zap_out=None, probe=None): """Return a runner that answers canned output per tool and records argv in `calls`.""" def _run(argv): + # scan._exe gives the full path of a tool found next to the interpreter but not on PATH (semgrep in + # .venv/bin when the suite runs on .venv/bin/python); answer and record by the bare name. + argv = [Path(argv[0]).name, *argv[1:]] if argv else argv if calls is not None: calls.append(list(argv)) tool = argv[0] @@ -790,6 +793,20 @@ def test_semgrep_runs_all_four_spec_packs_with_error_flag(self): self.assertIn("--error", argv) self.assertIn("--json", argv) + def test_a_tool_resolved_to_a_full_path_is_still_faked(self): + # Running the suite on .venv/bin/python, where semgrep sits beside the interpreter but not on PATH, + # used to make 20 scan tests fail and 1 error: the fake runner did not know "/…/.venv/bin/semgrep". + calls = [] + real_exe = scan._exe + scan._exe = lambda name: f"/opt/grdm/.venv/bin/{name}" + try: + code, data, _ = self.run_scan(fake_runner(semgrep_json=SEMGREP_WARNING, semgrep_rc=1, calls=calls)) + finally: + scan._exe = real_exe + self.assertEqual(code, exit_codes.OK) + self.assertEqual([t["result"] for t in data["tools"] if t["name"] == "semgrep"], ["ok"]) + self.assertTrue(any(c[:2] == ["semgrep", "scan"] for c in calls)) + def test_trivy_enumerates_every_compose_image_plus_checkouts_plus_repo(self): self.write_compose({ "web": hardened("grdm-dev/web:abc123", ports=["127.0.0.1:5000:5000"], networks=["grdm", "grdm-edge"]),