fix: Upload-Sanitizing, atomare Import-Reihenfolge, idempotentes UNBEKANNT-Konto
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ from sqlalchemy.orm import Session
|
||||
from sqlalchemy.pool import StaticPool
|
||||
|
||||
from app.db import Base, get_session
|
||||
import app.models # noqa: F401 ensures all ORM tables are registered on Base.metadata
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -46,3 +46,28 @@ def test_upload_preview_confirm(client, fake_parse, tmp_path, monkeypatch):
|
||||
assert prev2["duplicates"] == 1
|
||||
client.post(f"/api/imports/{sid2}/confirm", headers=H)
|
||||
assert len(client.get("/api/transactions", headers=H).json()) == 1
|
||||
|
||||
|
||||
def test_upload_sanitizes_path_traversal_filename(client, fake_parse, tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("FB_INBOX_DIR", str(tmp_path / "inbox"))
|
||||
monkeypatch.setenv("FB_UPLOADS_DIR", str(tmp_path / "uploads"))
|
||||
from app.config import get_settings
|
||||
get_settings.cache_clear()
|
||||
r = client.post("/api/imports/upload", headers=H,
|
||||
files={"file": ("../evil.pdf", b"%PDF-fake", "application/pdf")})
|
||||
assert r.status_code == 201
|
||||
# Der Dateiname darf keine Pfad-Anteile aus dem Client uebernehmen: nur
|
||||
# der Basisname landet im Uploads-Verzeichnis, nichts entkommt nach oben.
|
||||
assert not (tmp_path / "evil.pdf").exists()
|
||||
assert (tmp_path / "uploads" / "evil.pdf").exists()
|
||||
assert not (tmp_path / "inbox" / "evil.pdf").exists()
|
||||
|
||||
|
||||
def test_upload_rejects_non_pdf(client, tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("FB_INBOX_DIR", str(tmp_path / "inbox"))
|
||||
monkeypatch.setenv("FB_UPLOADS_DIR", str(tmp_path / "uploads"))
|
||||
from app.config import get_settings
|
||||
get_settings.cache_clear()
|
||||
r = client.post("/api/imports/upload", headers=H,
|
||||
files={"file": ("x.txt", b"not a pdf", "text/plain")})
|
||||
assert r.status_code == 400
|
||||
|
||||
Reference in New Issue
Block a user