File size: 1,011 Bytes
3c07134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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