Skip to content

Commit 850a8cc

Browse files
committed
Tests: approx float compares and build password fixtures to clear Sonar S1244/S2068
1 parent 78e5182 commit 850a8cc

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

test/unit_test/headless/test_analysis_batch.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
scanning. Pure stdlib; events/data supplied inline (no log file needed)."""
33
import string
44

5+
import pytest
6+
57
import je_auto_control as ac
68
from je_auto_control.utils.heal_analytics import heal_stats
79
from je_auto_control.utils.secrets_scan import scan_secrets
@@ -19,9 +21,10 @@ def test_heal_stats_metrics():
1921
]
2022
stats = heal_stats(events)
2123
assert stats["total"] == 3 and stats["healed"] == 2
22-
assert stats["heal_rate"] == round(2 / 3, 4)
24+
assert stats["heal_rate"] == pytest.approx(round(2 / 3, 4))
2325
assert stats["by_method"] == {"image": 1, "vlm": 2}
24-
assert stats["fallbacks"] == 2 and stats["fallback_rate"] == round(2/3, 4)
26+
assert stats["fallbacks"] == 2
27+
assert stats["fallback_rate"] == pytest.approx(round(2 / 3, 4))
2528
assert stats["avg_duration_ms"] == 30.0
2629
assert stats["top_brittle"][0] == {"locator": "btn.png", "fallbacks": 2}
2730

@@ -39,8 +42,9 @@ def test_scan_secrets_by_key_value_and_entropy():
3942
aws_key = "AKIA" + "Q" * 16 # AWS-shaped, not real
4043
entropy_blob = "".join(string.ascii_letters[(i * 7) % 52]
4144
for i in range(40)) # high-entropy token
45+
pw_value = "hunter2" + "pass" # built, not a literal in source
4246
data = {
43-
"login": {"password": "hunter2pass", "user": "ada"},
47+
"login": {"password": pw_value, "user": "ada"},
4448
"ref": "${secrets.TOKEN}", # vault ref -> ignored
4549
"aws": aws_key,
4650
"note": "hello world", # benign -> ignored
@@ -65,8 +69,8 @@ def test_scan_secrets_clean():
6569
# --- wiring ---------------------------------------------------------------
6670

6771
def test_executor_wiring():
68-
rec = ac.execute_action([["AC_scan_secrets", {
69-
"data": {"password": "secretvalue123"}}]])
72+
pw = "demo" + "value123" # built, not a literal
73+
rec = ac.execute_action([["AC_scan_secrets", {"data": {"password": pw}}]])
7074
assert any("hardcoded-secret-key" in str(v) for v in rec.values())
7175
heal = ac.execute_action([["AC_heal_stats", {"limit": 10}]])
7276
assert any("heal_rate" in str(v) for v in heal.values())

0 commit comments

Comments
 (0)