251e509ee0
Unit tests: - test_security_boundaries.py: vault block, vault lock sentinel - test_security_injection.py: all 4 injection categories, case-insensitive - test_vault_rw.py: roundtrip, file permissions (chmod 400), no key in config - test_config.py: schema roundtrip, no api_key field, chmod 600 on config.yaml - test_memory_reader.py: list, read, sandboxing, context loading - test_memory_writer.py: write, append, index update, traversal blocked, chmod 600 - test_providers.py: required fields, unique IDs, litellm prefix format - test_renderer.py: key redaction for sk-ant-, sk-, AIza patterns Security tests: - test_vault_ai_isolation.py: 7 traversal patterns blocked via memory read/write - test_path_traversal.py: 20+ traversal patterns — all rejected for read and write - test_prompt_injection.py: 21-item corpus + 5 clean texts (no false positives) Integration tests: - test_lmstudio.py: live call to localhost:1234, streaming, full stack session, injection scan on real output (skips if LM Studio not running) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import pytest
|
|
from pyra.setup.providers import PROVIDERS, PROVIDERS_BY_ID, get_provider
|
|
|
|
|
|
def test_all_providers_have_required_fields():
|
|
for p in PROVIDERS:
|
|
assert p.id, f"Provider missing id: {p}"
|
|
assert p.display_name, f"Provider missing display_name: {p.id}"
|
|
assert p.default_model, f"Provider missing default_model: {p.id}"
|
|
assert p.litellm_prefix, f"Provider missing litellm_prefix: {p.id}"
|
|
assert p.group in ("Local", "Cloud"), f"Invalid group for {p.id}: {p.group!r}"
|
|
|
|
|
|
def test_cloud_providers_have_key_env_var():
|
|
for p in PROVIDERS:
|
|
if p.requires_key:
|
|
assert p.key_env_var, f"Cloud provider {p.id} missing key_env_var"
|
|
|
|
|
|
def test_local_providers_have_connectivity_check():
|
|
for p in PROVIDERS:
|
|
if not p.requires_key:
|
|
assert p.connectivity_check, f"Local provider {p.id} missing connectivity_check"
|
|
assert p.base_url, f"Local provider {p.id} missing base_url"
|
|
|
|
|
|
def test_provider_ids_unique():
|
|
ids = [p.id for p in PROVIDERS]
|
|
assert len(ids) == len(set(ids)), "Duplicate provider IDs found"
|
|
|
|
|
|
def test_get_provider_known():
|
|
p = get_provider("anthropic")
|
|
assert p.id == "anthropic"
|
|
|
|
|
|
def test_get_provider_unknown_raises():
|
|
with pytest.raises(KeyError):
|
|
get_provider("nonexistent_provider_xyz")
|
|
|
|
|
|
def test_lmstudio_is_local():
|
|
p = get_provider("lmstudio")
|
|
assert not p.requires_key
|
|
assert p.group == "Local"
|
|
assert "1234" in p.base_url
|
|
|
|
|
|
def test_litellm_prefix_ends_with_slash():
|
|
for p in PROVIDERS:
|
|
assert p.litellm_prefix.endswith("/"), (
|
|
f"Provider {p.id} litellm_prefix should end with /: {p.litellm_prefix!r}"
|
|
)
|