"""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=" in messages