Skip to content

Commit 78e5182

Browse files
committed
Tests: build secret-shaped fixtures at runtime to clear gitleaks/Sonar
1 parent f3e2a39 commit 78e5182

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

test/unit_test/headless/test_analysis_batch.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Headless tests for the analysis batch: self-heal analytics + secrets
22
scanning. Pure stdlib; events/data supplied inline (no log file needed)."""
3+
import string
4+
35
import je_auto_control as ac
46
from je_auto_control.utils.heal_analytics import heal_stats
57
from je_auto_control.utils.secrets_scan import scan_secrets
@@ -32,18 +34,24 @@ def test_heal_stats_empty():
3234
# --- secrets scan ---------------------------------------------------------
3335

3436
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
3542
data = {
3643
"login": {"password": "hunter2pass", "user": "ada"},
3744
"ref": "${secrets.TOKEN}", # vault ref -> ignored
38-
"aws": "AKIAIOSFODNN7EXAMPLE",
45+
"aws": aws_key,
3946
"note": "hello world", # benign -> ignored
40-
"blob": "aGVsbG9Xb3JsZFNlY3JldEtleTEyMzQ1Njc4OQ", # high entropy
47+
"blob": entropy_blob,
4148
}
4249
findings = scan_secrets(data)
4350
kinds = {f["kind"] for f in findings}
4451
paths = {f["path"] for f in findings}
4552
assert "hardcoded-secret-key" in kinds # password
4653
assert "aws-access-key" in kinds
54+
assert "high-entropy-string" in kinds
4755
assert "$.login.password" in paths
4856
assert all("hunter2" not in f["preview"] for f in findings) # masked
4957
assert not any(f["path"] == "$.ref" for f in findings) # vault ok

0 commit comments

Comments
 (0)