Skip to content

Free, open source blog writer for Claude Code. Researches current sources, writes answer-first posts for Google and AI answers, has an independent reviewer score each one out of 100 and ships only after five delivery gates. 32 skills, 30 /blog commands, 5 agents. Active development at AI-Marketing-Hub/claude-blog; public releases ship here.

3.4 KB
Raw Blame
"""Bound public ownership-commit adjudication without ignoring other findings."""
import importlib.util
from pathlib import Path

import pytest


ROOT = Path(__file__).resolve().parents[1]
SPEC = importlib.util.spec_from_file_location("legacy_secret_policy", ROOT / "scripts/check_secrets.py")
POLICY = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(POLICY)
PUBLIC_COMMIT = sorted(POLICY.REVIEWED_LEGACY_COMMITS)[0]


def declaration(path, commit):
    if path.startswith("data/"):
        return f'  "commit": "{commit}",'
    if path.endswith(".ps1"):
        return f'$Baseline = "{commit}"'
    if path.endswith("test_windows_installer_ownership.py"):
        return f'    assert "{commit}" in source'
    return f'    "{commit}",'


@pytest.mark.parametrize("path", sorted(POLICY.LEGACY_COMMIT_PATHS))
def test_reviewed_public_commit_is_adjudicated_only_in_evidence_paths(path):
    line = declaration(path, PUBLIC_COMMIT)
    assert POLICY.is_adjudicated(path, {"type": "Hex High Entropy String"}, line)
    assert not POLICY.is_adjudicated("scripts/unrelated.py", {"type": "Hex High Entropy String"}, line)


def test_unknown_or_mixed_high_entropy_values_remain_unadjudicated():
    path = "data/legacy-install-ownership.json"
    unknown = "abcdef0123456789" * 2 + "abcdef01"
    assert not POLICY.is_adjudicated(path, {"type": "Hex High Entropy String"}, declaration(path, unknown))
    line = declaration(path, PUBLIC_COMMIT)
    assert not POLICY.is_adjudicated(path, {"type": "Hex High Entropy String"}, line + " " + unknown)
    assert not POLICY.is_adjudicated(path, {"type": "Hex High Entropy String"}, line + " " + "a" * 64)
    assert not POLICY.is_adjudicated(path, {"type": "Secret Keyword"}, line)


def test_public_commit_on_line_does_not_disable_credential_detection(tmp_path, monkeypatch):
    monkeypatch.setattr(POLICY, "ROOT", tmp_path)
    path = tmp_path / "data/legacy-install-ownership.json"
    path.parent.mkdir()
    # Construct the hostile fixture at runtime so no real credential is stored.
    path.write_text(PUBLIC_COMMIT + " " + "ghp_" + "A" * 36 + "\n")
    assert POLICY.scan_forbidden_values() == [{"file": "data/legacy-install-ownership.json", "line": 1, "type": "GitHub token"}]


@pytest.mark.parametrize("field", ["captured_excerpt_sha256", "normalized_full_document_sha256"])
def test_packaged_evidence_digests_remain_narrowly_adjudicated(field):
    line = f'  "{field}": "' + "a1" * 32 + '",'
    finding = {"type": "Hex High Entropy String"}
    assert POLICY.is_adjudicated("brain/references/evidence/review.json", finding, line)
    assert not POLICY.is_adjudicated(
        "brain/references/evidence/review.json", finding, line.replace("a1" * 32, "a1" * 31)
    )
    assert not POLICY.is_adjudicated(
        "brain/references/evidence/review.json", finding, line.replace(field, "unknown_digest")
    )
    assert not POLICY.is_adjudicated(
        "brain/references/evidence/review.json", {"type": "Secret Keyword"}, line
    )


def test_packaged_evidence_digest_does_not_disable_credential_detection(tmp_path, monkeypatch):
    monkeypatch.setattr(POLICY, "ROOT", tmp_path)
    path = tmp_path / "brain/references/evidence/review.json"
    path.parent.mkdir(parents=True)
    path.write_text(
        '"captured_excerpt_sha256": "' + "a1" * 32 + '", "value": "'
        + "ghp_" + "B" * 36 + '"\n'
    )
    assert POLICY.scan_forbidden_values() == [
        {"file": "brain/references/evidence/review.json", "line": 1, "type": "GitHub token"}
    ]