31 lines
1023 B
Python
31 lines
1023 B
Python
from fastapi.testclient import TestClient
|
|
from app.main import app
|
|
|
|
|
|
def test_file_download(tmp_path, monkeypatch):
|
|
from app.core import settings
|
|
|
|
root = tmp_path / "dl"
|
|
root.mkdir()
|
|
(root / "song.flac").write_bytes(b"FAKEDATA")
|
|
monkeypatch.setattr(settings, "DOWNLOAD_DIR", str(root))
|
|
|
|
c = TestClient(app)
|
|
r = c.get("/api/files/download", params={"path": "song.flac"})
|
|
assert r.status_code == 200
|
|
assert r.content == b"FAKEDATA"
|
|
assert "attachment" in r.headers.get("content-disposition", "")
|
|
|
|
|
|
def test_file_download_blocked(tmp_path, monkeypatch):
|
|
from app.core import settings
|
|
|
|
root = tmp_path / "dl"
|
|
root.mkdir()
|
|
monkeypatch.setattr(settings, "DOWNLOAD_DIR", str(root))
|
|
|
|
c = TestClient(app)
|
|
assert c.get("/api/files/download", params={"path": "../../etc/passwd"}).status_code == 403
|
|
assert c.get("/api/files/download", params={"path": "missing.mp3"}).status_code == 404
|
|
assert c.get("/api/files/download", params={"path": ""}).status_code == 404
|