Skip to content

Commit 974b174

Browse files
committed
fix(dav): raise error if content length of put request is zero
1 parent 646b5f4 commit 974b174

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: alexandria/core/tests/test_dav.py

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from rest_framework import status
1414
from rest_framework.status import HTTP_200_OK, HTTP_404_NOT_FOUND
1515
from webtest import TestApp, TestRequest
16+
from webtest.app import AppError
1617
from wsgidav.dav_error import HTTP_FORBIDDEN
1718

1819
from alexandria.core.models import File
@@ -222,3 +223,15 @@ def test_dav_url_schemes_unconfigured(db, file_factory, manabi, settings):
222223
file.get_webdav_url("foobar", "foobar")
223224

224225
assert str(e.value).startswith(f'The MIME type "{mime_type}"')
226+
227+
228+
def test_dav_without_content(db, manabi, settings, file_factory):
229+
settings.ALEXANDRIA_MANABI_DAV_URI_SCHEMES = {"text/plain": "ms-word:ofe|u|"}
230+
231+
file = file_factory(name="test.txt", mime_type="text/plain")
232+
dav_app = TestApp(get_dav())
233+
234+
with pytest.raises(AppError) as e:
235+
dav_app.put(get_webdav_url_without_uri_scheme(file, "admin", "admin"), b"")
236+
237+
assert "400 Bad Request" in str(e)

Diff for: alexandria/dav_provider.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.core.exceptions import ValidationError
66
from django.core.files.base import File as DjangoFile
77
from manabi.filesystem import ManabiFileResourceMixin, ManabiProvider
8-
from wsgidav.dav_error import HTTP_FORBIDDEN, DAVError
8+
from wsgidav.dav_error import HTTP_BAD_REQUEST, HTTP_FORBIDDEN, DAVError
99
from wsgidav.dav_provider import DAVNonCollection
1010

1111
from alexandria.core.validations import validate_file
@@ -93,6 +93,8 @@ def begin_write(self, *, content_type=None):
9393
assert not self.is_collection
9494
if self.provider.readonly: # pragma: no cover
9595
raise DAVError(HTTP_FORBIDDEN)
96+
if int(self.environ["CONTENT_LENGTH"]) == 0:
97+
raise DAVError(HTTP_BAD_REQUEST)
9698
return self.memory_file
9799

98100
def end_write(self, *, with_errors):

0 commit comments

Comments
 (0)