From 08bf527b33b58dc71fb2bec1d0ad9be08515c934 Mon Sep 17 00:00:00 2001 From: Igor Davydenko Date: Wed, 18 Mar 2020 20:30:27 +0100 Subject: [PATCH] fix: Ensure upload URLs with trailing slashes working as well --- CHANGELOG.rst | 5 +++++ aiohttp_tus/__init__.py | 2 +- aiohttp_tus/data.py | 5 ++++- pyproject.toml | 2 +- tests/test_tus.py | 22 ++++++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f1f202c..3129044 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ ChangeLog ========= +1.0.0b2 (In Development) +======================== + +- Ensure trailing slash upload URLs working as well + 1.0.0b1 (2020-03-18) ==================== diff --git a/aiohttp_tus/__init__.py b/aiohttp_tus/__init__.py index 6acecb4..bb7c47e 100644 --- a/aiohttp_tus/__init__.py +++ b/aiohttp_tus/__init__.py @@ -2,4 +2,4 @@ __all__ = ("setup_tus",) __license__ = "BSD-3-Clause" -__version__ = "1.0.0b1" +__version__ = "1.0.0b2" diff --git a/aiohttp_tus/data.py b/aiohttp_tus/data.py index 45959b9..3128c28 100644 --- a/aiohttp_tus/data.py +++ b/aiohttp_tus/data.py @@ -2,6 +2,7 @@ import json import shutil import uuid +from contextlib import suppress from pathlib import Path from typing import Awaitable, Callable, Optional, Tuple @@ -164,7 +165,9 @@ def get_config(request: web.Request) -> Config: config_key = get_upload_url(config_key) try: - return container[config_key] # type: ignore + with suppress(KeyError): + return container[config_key] # type: ignore + return container[f"{config_key}/"] # type: ignore except KeyError: raise KeyError("Unable to find aiohttp_tus config for specified URL") diff --git a/pyproject.toml b/pyproject.toml index 9347458..caa3e46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ show_missing = true [tool.poetry] name = "aiohttp-tus" -version = "1.0.0b1" +version = "1.0.0b2" description = "tus.io protocol implementation for aiohttp.web applications" authors = ["Igor Davydenko "] license = "BSD-3-Clause" diff --git a/tests/test_tus.py b/tests/test_tus.py index 8064128..97cb85b 100644 --- a/tests/test_tus.py +++ b/tests/test_tus.py @@ -152,6 +152,7 @@ async def test_overwrite_file_disallowed(aiohttp_test_client, loop): "upload_url, canonical_upload_url, upload_suffix, tus_upload_url, match_info", ( (TEST_UPLOAD_URL, TEST_UPLOAD_URL, None, TEST_UPLOAD_URL, {}), + (f"{TEST_UPLOAD_URL}/", f"{TEST_UPLOAD_URL}/", None, f"{TEST_UPLOAD_URL}/", {}), ( r"/user/{username}/uploads", r"/user/{username}/uploads", @@ -159,6 +160,13 @@ async def test_overwrite_file_disallowed(aiohttp_test_client, loop): "/user/playpauseanddtop/uploads", {}, ), + ( + r"/user/{username}/uploads/", + r"/user/{username}/uploads/", + None, + "/user/playpauseanddtop/uploads/", + {}, + ), ( r"/user/{username:([a-zA-Z0-9_-])+}/uploads", r"/user/{username}/uploads", @@ -166,6 +174,13 @@ async def test_overwrite_file_disallowed(aiohttp_test_client, loop): "/user/playpauseanddtop/uploads", {}, ), + ( + r"/user/{username:([a-zA-Z0-9_-])+}/uploads/", + r"/user/{username}/uploads/", + None, + "/user/playpauseanddtop/uploads/", + {}, + ), ( r"/user/{username}/uploads", r"/user/{username}/uploads", @@ -173,6 +188,13 @@ async def test_overwrite_file_disallowed(aiohttp_test_client, loop): "/user/playpauseandstop/uploads", {"username": "playpauseandstop"}, ), + ( + r"/user/{username}/uploads/", + r"/user/{username}/uploads/", + r"{username}", + "/user/playpauseandstop/uploads/", + {"username": "playpauseandstop"}, + ), ), ) async def test_upload(