Files
memory-gateway/plugins/memory-gateway-agent/tests/test_safety.py

25 lines
767 B
Python

from __future__ import annotations
from memory_gateway_plugin.safety import detect_large_log, sanitize_memory_content, validate_memory_write
def test_safety_rejects_private_key():
content = "-----BEGIN PRIVATE KEY-----\nabc\n-----END PRIVATE KEY-----"
result = validate_memory_write(content)
assert result["allowed"] is False
assert result["reason"] == "secret_like_content"
def test_safety_rejects_large_log():
content = "\n".join(f"2026-05-06 10:00:{i:02d} ERROR failure" for i in range(10))
blocked, reason = detect_large_log(content)
assert blocked is True
assert reason == "large_or_raw_log"
def test_safety_sanitizes_secret_when_called_directly():
assert "sk-test" not in sanitize_memory_content("api_key=sk-test")