Spaces:
Sleeping
Sleeping
File size: 1,648 Bytes
c704030 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | """
tests/test_auth.py
Tests for the /auth.md agent onboarding route.
"""
import sys
import os
import pytest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
@pytest.fixture(scope="module")
def flask_app(tmp_path_factory):
tmp_dir = tmp_path_factory.mktemp("auth_test_db")
db_path = str(tmp_dir / "test.db")
os.environ.pop("AGENTCACHE_SECRET", None)
os.environ.pop("AGENTMEMORY_SECRET", None)
from db import StateKV
original_init = StateKV.__init__
def patched_init(self, db_path_arg=None, **kwargs):
original_init(self, db_path=db_path, **kwargs)
StateKV.__init__ = patched_init
import app as app_module
flask_application = app_module.create_app()
StateKV.__init__ = original_init
flask_application.config["TESTING"] = True
return flask_application
@pytest.fixture(scope="module")
def client(flask_app):
return flask_app.test_client()
def test_auth_md_endpoint(client):
resp = client.get("/auth.md")
assert resp.status_code == 200
assert resp.headers["Content-Type"].startswith("text/markdown")
content = resp.data.decode("utf-8")
assert "# Agent Cache" in content
assert "Authorization" in content
assert "agent_observe" in content
def test_auth_md_endpoint_with_secret(flask_app):
os.environ["AGENTCACHE_SECRET"] = "super-secret-token"
try:
client = flask_app.test_client()
resp = client.get("/auth.md")
assert resp.status_code == 200
content = resp.data.decode("utf-8")
assert "# Agent Cache" in content
finally:
os.environ.pop("AGENTCACHE_SECRET", None)
|