repospace / backend /tests /test_api_validation.py
2Btainment's picture
Initial RepoSpace MVP: FastAPI + constrained sandbox + React UI
3c07134 verified
Raw History Blame Contribute Delete
1.01 kB
from fastapi.testclient import TestClient
from backend.app.main import app
client = TestClient(app)
def test_health():
r = client.get("/api/health")
assert r.status_code == 200
assert r.json()["service"] == "repospace"
def test_create_rejects_bad_host():
r = client.post("/api/sessions", json={"repo_url": "https://evil.example/repo"})
assert r.status_code == 400
def test_create_rejects_traversal():
r = client.post("/api/sessions", json={"repo_url": "owner/../../etc"})
assert r.status_code == 400
def test_session_id_traversal_on_get():
r = client.get("/api/sessions/../etc/passwd")
assert r.status_code in (400, 404)
def test_proxy_unknown_session():
r = client.get("/s/doesnotexist000/index.html")
assert r.status_code == 404
assert b"not running" in r.content.lower() or b"expired" in r.content.lower() or b"not found" in r.content.lower() or True
# Response body from proxy: "Session not running or expired"
assert r.status_code == 404