fix(security): update tests for verdict and --force changes
This commit is contained in:
@@ -84,13 +84,13 @@ class TestDetermineVerdict:
|
|||||||
f = Finding("x", "high", "network", "f.py", 1, "m", "d")
|
f = Finding("x", "high", "network", "f.py", 1, "m", "d")
|
||||||
assert _determine_verdict([f]) == "caution"
|
assert _determine_verdict([f]) == "caution"
|
||||||
|
|
||||||
def test_medium_finding_caution(self):
|
def test_medium_finding_safe(self):
|
||||||
f = Finding("x", "medium", "structural", "f.py", 1, "m", "d")
|
f = Finding("x", "medium", "structural", "f.py", 1, "m", "d")
|
||||||
assert _determine_verdict([f]) == "caution"
|
assert _determine_verdict([f]) == "safe"
|
||||||
|
|
||||||
def test_low_finding_caution(self):
|
def test_low_finding_safe(self):
|
||||||
f = Finding("x", "low", "obfuscation", "f.py", 1, "m", "d")
|
f = Finding("x", "low", "obfuscation", "f.py", 1, "m", "d")
|
||||||
assert _determine_verdict([f]) == "caution"
|
assert _determine_verdict([f]) == "safe"
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -145,21 +145,21 @@ class TestShouldAllowInstall:
|
|||||||
allowed, _ = should_allow_install(self._result("community", "dangerous", f), force=False)
|
allowed, _ = should_allow_install(self._result("community", "dangerous", f), force=False)
|
||||||
assert allowed is False
|
assert allowed is False
|
||||||
|
|
||||||
def test_force_overrides_dangerous_for_community(self):
|
def test_force_does_not_override_dangerous_for_community(self):
|
||||||
f = [Finding("x", "critical", "c", "f", 1, "m", "d")]
|
f = [Finding("x", "critical", "c", "f", 1, "m", "d")]
|
||||||
allowed, reason = should_allow_install(
|
allowed, reason = should_allow_install(
|
||||||
self._result("community", "dangerous", f), force=True
|
self._result("community", "dangerous", f), force=True
|
||||||
)
|
)
|
||||||
assert allowed is True
|
assert allowed is False
|
||||||
assert "Force-installed" in reason
|
assert "Blocked" in reason
|
||||||
|
|
||||||
def test_force_overrides_dangerous_for_trusted(self):
|
def test_force_does_not_override_dangerous_for_trusted(self):
|
||||||
f = [Finding("x", "critical", "c", "f", 1, "m", "d")]
|
f = [Finding("x", "critical", "c", "f", 1, "m", "d")]
|
||||||
allowed, reason = should_allow_install(
|
allowed, reason = should_allow_install(
|
||||||
self._result("trusted", "dangerous", f), force=True
|
self._result("trusted", "dangerous", f), force=True
|
||||||
)
|
)
|
||||||
assert allowed is True
|
assert allowed is False
|
||||||
assert "Force-installed" in reason
|
assert "Blocked" in reason
|
||||||
|
|
||||||
# -- agent-created policy --
|
# -- agent-created policy --
|
||||||
|
|
||||||
|
|||||||
@@ -661,7 +661,7 @@ def should_allow_install(result: ScanResult, force: bool = False) -> Tuple[bool,
|
|||||||
if decision == "allow":
|
if decision == "allow":
|
||||||
return True, f"Allowed ({result.trust_level} source, {result.verdict} verdict)"
|
return True, f"Allowed ({result.trust_level} source, {result.verdict} verdict)"
|
||||||
|
|
||||||
if force and result.verdict != "dangerous":
|
if force and not (result.verdict == "dangerous" and result.trust_level in ("community", "trusted")):
|
||||||
return True, (
|
return True, (
|
||||||
f"Force-installed despite {result.verdict} verdict "
|
f"Force-installed despite {result.verdict} verdict "
|
||||||
f"({len(result.findings)} findings)"
|
f"({len(result.findings)} findings)"
|
||||||
|
|||||||
Reference in New Issue
Block a user