chore: 502 bei propfind-fail, min_length path, exact-call assertion

This commit is contained in:
2026-05-04 22:45:23 +02:00
parent 8c50ab008c
commit a91150c41f
2 changed files with 27 additions and 10 deletions

View File

@@ -4,8 +4,8 @@ from pathlib import PurePosixPath
from urllib.parse import unquote
import httpx
from fastapi import APIRouter, BackgroundTasks, Header, status
from pydantic import BaseModel
from fastapi import APIRouter, BackgroundTasks, Header, HTTPException, status
from pydantic import BaseModel, Field
from app.config import get_settings
from app.ingest.extractors import SUPPORTED_TYPES
@@ -19,7 +19,7 @@ router = APIRouter()
class BulkRequest(BaseModel):
path: str
path: str = Field(min_length=1)
PROPFIND_BODY = """<?xml version="1.0"?>
@@ -74,12 +74,19 @@ async def bulk_import(
settings = get_settings()
verify_secret(x_webhook_secret, settings.webhook_secret)
files = await list_files_recursive(
settings.nextcloud_webdav_url,
settings.nextcloud_user,
settings.nextcloud_app_password,
body.path,
)
try:
files = await list_files_recursive(
settings.nextcloud_webdav_url,
settings.nextcloud_user,
settings.nextcloud_app_password,
body.path,
)
except (RuntimeError, httpx.HTTPError, ET.ParseError) as exc:
logger.exception(
"bulk listing failed",
extra={"event": "bulk_listing_failed", "path": body.path, "error": str(exc)},
)
raise HTTPException(status_code=502, detail="webdav listing failed") from exc
dispatched = 0
for f in files:

View File

@@ -1,6 +1,9 @@
from unittest.mock import AsyncMock
from unittest.mock import AsyncMock, call
from fastapi.testclient import TestClient
from app.webhook.models import EventType
def _make_app(monkeypatch):
monkeypatch.setenv("NEXTCLOUD_WEBDAV_URL", "http://nc")
@@ -45,6 +48,13 @@ def test_bulk_import_lists_and_dispatches(monkeypatch):
assert r.status_code == 202
body = r.json()
assert body["dispatched"] == 2 # only .pdf and .docx, not the json sidecar
process_mock.assert_has_calls(
[
call("Documents/THB/Studium/2.Semester/Databases/a.pdf", EventType.CREATED),
call("Documents/THB/Studium/2.Semester/Databases/b.docx", EventType.CREATED),
]
)
assert process_mock.await_count == 2
def test_bulk_import_rejects_wrong_secret(monkeypatch):