🐛(backend) allow any type of extensions for media download
The regex to validate media file extensions was too restrictive.
This commit is contained in:
committed by
Samuel Paccoud
parent
54a75bc338
commit
ef2127585c
@@ -21,6 +21,7 @@ and this project adheres to
|
|||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
|
- 🐛(backend) allow any type of extensions for media download #671
|
||||||
- ♻️(frontend) improve table pdf rendering
|
- ♻️(frontend) improve table pdf rendering
|
||||||
|
|
||||||
## [2.2.0] - 2025-02-10
|
## [2.2.0] - 2025-02-10
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ ATTACHMENTS_FOLDER = "attachments"
|
|||||||
UUID_REGEX = (
|
UUID_REGEX = (
|
||||||
r"[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
|
r"[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"
|
||||||
)
|
)
|
||||||
FILE_EXT_REGEX = r"\.[a-zA-Z]{3,4}"
|
FILE_EXT_REGEX = r"\.[a-zA-Z0-9]{1,10}"
|
||||||
MEDIA_STORAGE_URL_PATTERN = re.compile(
|
MEDIA_STORAGE_URL_PATTERN = re.compile(
|
||||||
f"{settings.MEDIA_URL:s}(?P<pk>{UUID_REGEX:s})/"
|
f"{settings.MEDIA_URL:s}(?P<pk>{UUID_REGEX:s})/"
|
||||||
f"(?P<key>{ATTACHMENTS_FOLDER:s}/{UUID_REGEX:s}{FILE_EXT_REGEX:s})$"
|
f"(?P<key>{ATTACHMENTS_FOLDER:s}/{UUID_REGEX:s}{FILE_EXT_REGEX:s})$"
|
||||||
|
|||||||
@@ -64,6 +64,30 @@ def test_api_documents_media_auth_anonymous_public():
|
|||||||
assert response.content.decode("utf-8") == "my prose"
|
assert response.content.decode("utf-8") == "my prose"
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_documents_media_auth_extensions():
|
||||||
|
"""Files with extensions of any format should work."""
|
||||||
|
document = factories.DocumentFactory(link_reach="public")
|
||||||
|
|
||||||
|
extensions = [
|
||||||
|
"c",
|
||||||
|
"go",
|
||||||
|
"gif",
|
||||||
|
"mp4",
|
||||||
|
"woff2",
|
||||||
|
"appimage",
|
||||||
|
]
|
||||||
|
for ext in extensions:
|
||||||
|
filename = f"{uuid.uuid4()!s}.{ext:s}"
|
||||||
|
key = f"{document.pk!s}/attachments/{filename:s}"
|
||||||
|
|
||||||
|
original_url = f"http://localhost/media/{key:s}"
|
||||||
|
response = APIClient().get(
|
||||||
|
"/api/v1.0/documents/media-auth/", HTTP_X_ORIGINAL_URL=original_url
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("reach", ["authenticated", "restricted"])
|
@pytest.mark.parametrize("reach", ["authenticated", "restricted"])
|
||||||
def test_api_documents_media_auth_anonymous_authenticated_or_restricted(reach):
|
def test_api_documents_media_auth_anonymous_authenticated_or_restricted(reach):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user