from pyra.security.injection import redact_api_keys def test_anthropic_key_redacted(): text = "sk-ant-api03-abcdefghijklmnopqrstuvwxyz" result = redact_api_keys(text) assert "sk-ant-" not in result assert "[REDACTED]" in result def test_openai_key_redacted(): text = "Key is sk-abcdefghijklmnopqrstu" result = redact_api_keys(text) assert "[REDACTED]" in result def test_google_key_redacted(): text = f"AIza{'B' * 35} is my key" result = redact_api_keys(text) assert "AIza" not in result assert "[REDACTED]" in result def test_clean_text_unchanged(): text = "The answer is 42. No API keys here." result = redact_api_keys(text) assert result == text def test_multiple_keys_in_one_string(): text = ( f"First: sk-ant-{'x' * 20}, " f"Second: sk-{'y' * 25}" ) result = redact_api_keys(text) assert result.count("[REDACTED]") >= 1