|
1 | 1 | """Headless tests for the analysis batch: self-heal analytics + secrets |
2 | 2 | scanning. Pure stdlib; events/data supplied inline (no log file needed).""" |
| 3 | +import string |
| 4 | + |
3 | 5 | import je_auto_control as ac |
4 | 6 | from je_auto_control.utils.heal_analytics import heal_stats |
5 | 7 | from je_auto_control.utils.secrets_scan import scan_secrets |
@@ -32,18 +34,24 @@ def test_heal_stats_empty(): |
32 | 34 | # --- secrets scan --------------------------------------------------------- |
33 | 35 |
|
34 | 36 | def test_scan_secrets_by_key_value_and_entropy(): |
| 37 | + # Build secret-shaped values at runtime so no secret-like literal sits in |
| 38 | + # the source (which would trip gitleaks / Sonar on this test file itself). |
| 39 | + aws_key = "AKIA" + "Q" * 16 # AWS-shaped, not real |
| 40 | + entropy_blob = "".join(string.ascii_letters[(i * 7) % 52] |
| 41 | + for i in range(40)) # high-entropy token |
35 | 42 | data = { |
36 | 43 | "login": {"password": "hunter2pass", "user": "ada"}, |
37 | 44 | "ref": "${secrets.TOKEN}", # vault ref -> ignored |
38 | | - "aws": "AKIAIOSFODNN7EXAMPLE", |
| 45 | + "aws": aws_key, |
39 | 46 | "note": "hello world", # benign -> ignored |
40 | | - "blob": "aGVsbG9Xb3JsZFNlY3JldEtleTEyMzQ1Njc4OQ", # high entropy |
| 47 | + "blob": entropy_blob, |
41 | 48 | } |
42 | 49 | findings = scan_secrets(data) |
43 | 50 | kinds = {f["kind"] for f in findings} |
44 | 51 | paths = {f["path"] for f in findings} |
45 | 52 | assert "hardcoded-secret-key" in kinds # password |
46 | 53 | assert "aws-access-key" in kinds |
| 54 | + assert "high-entropy-string" in kinds |
47 | 55 | assert "$.login.password" in paths |
48 | 56 | assert all("hunter2" not in f["preview"] for f in findings) # masked |
49 | 57 | assert not any(f["path"] == "$.ref" for f in findings) # vault ok |
|
0 commit comments