File size: 1,549 Bytes
388826c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """Security regressions for product startup diagnostics."""
from __future__ import annotations
import logging
from types import SimpleNamespace
from polyhedra import app as app_module
from polyhedra.messaging import slack as slack_module
def test_create_app_never_logs_slack_signing_secret(monkeypatch, caplog) -> None:
secret = "test-signing-secret-value"
monkeypatch.setenv("SLACK_SIGNING_SECRET", secret)
monkeypatch.setattr(
slack_module,
"SlackIntegration",
lambda: SimpleNamespace(_app=None),
)
with caplog.at_level(logging.INFO, logger="polyhedra.app"):
app_module.create_app()
messages = "\n".join(record.getMessage() for record in caplog.records)
assert "Slack signing secret configured" in messages
assert secret not in messages
assert secret[:4] not in messages
assert secret[-4:] not in messages
def test_create_app_redacts_slack_initialization_errors(monkeypatch, caplog) -> None:
leaked = "credential-that-must-not-appear"
monkeypatch.delenv("SSLKEYLOGFILE", raising=False)
def fail_to_initialize():
raise RuntimeError(f"request failed?token={leaked}")
monkeypatch.setattr(slack_module, "SlackIntegration", fail_to_initialize)
with caplog.at_level(logging.WARNING, logger="polyhedra.app"):
app_module.create_app()
messages = "\n".join(record.getMessage() for record in caplog.records)
assert "Slack Bolt init skipped" in messages
assert leaked not in messages
assert "token=<redacted>" in messages
|