mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-07-27 01:33:36 +00:00
Filter usr/.env masking to API keys and login/password credentials so ordinary settings cannot corrupt chat text. Keep global and project secrets protected, and cover full-response, prompt, and streaming behavior with a regression test.
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from helpers import secrets
|
|
|
|
|
|
class _Context:
|
|
def get_data(self, key: str):
|
|
return None
|
|
|
|
|
|
def test_agent_secret_manager_masks_runtime_credentials_only(monkeypatch):
|
|
monkeypatch.setattr(secrets.SecretsManager, "_instances", {})
|
|
monkeypatch.setattr(secrets.dotenv, "get_dotenv_file_path", lambda: "usr/.env")
|
|
|
|
contents = {
|
|
"usr/secrets.env": "PROJECT_SECRET=project-value\n",
|
|
"usr/.env": (
|
|
"API_KEY_OPENAI=llm-secret-value\n"
|
|
"ANONYMIZED_TELEMETRY=false\n"
|
|
"DEFAULT_USER_TIMEZONE=Europe/Rome\n"
|
|
),
|
|
}
|
|
monkeypatch.setattr(secrets.files, "read_file", contents.__getitem__)
|
|
|
|
manager = secrets.get_secrets_manager(_Context())
|
|
|
|
assert manager.mask_values(
|
|
"project-value; key=llm-secret-value; avoid falsely accusing a utility"
|
|
) == (
|
|
"§§secret(PROJECT_SECRET); key=§§secret(API_KEY_OPENAI); "
|
|
"avoid falsely accusing a utility"
|
|
)
|
|
assert "ANONYMIZED_TELEMETRY" not in manager.get_secrets_for_prompt()
|
|
|
|
stream_filter = manager.create_streaming_filter()
|
|
assert stream_filter.process_chunk("avoid falsely accusing a utility") == (
|
|
"avoid falsely accusing a utility"
|
|
)
|
|
assert stream_filter.finalize() == ""
|