From 597072cc95660d83d6e3d71e6d43a4295ff02ed4 Mon Sep 17 00:00:00 2001 From: Greg Lange <greglange@gmail.com> Date: Thu, 2 May 2013 18:28:14 +0000 Subject: [PATCH] Fix obscure double url bug in container quota middleware With the container quota middleware on, if you made a request similar to the following one you'd get a 500 response. curl -i -X PUT -H 'X-Auth-Token: token' http://127.0.0.1:8080/v1/AUTH_testhttp://something/something_else (Note the double url.) This was due to a mismatch in how split_path() was called in the middleware and in the get_container_info(). This change fixes that mismatch and the bug. Change-Id: Ie42ab585b942b7201e13b02a0c706532952aac60 --- swift/common/middleware/container_quotas.py | 4 ++-- test/unit/common/middleware/test_quotas.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/swift/common/middleware/container_quotas.py b/swift/common/middleware/container_quotas.py index 34643a7bbc..d8d3df0316 100644 --- a/swift/common/middleware/container_quotas.py +++ b/swift/common/middleware/container_quotas.py @@ -64,12 +64,12 @@ class ContainerQuotaMiddleware(object): @wsgify def __call__(self, req): try: - (version, account, container, obj) = req.split_path(2, 4, True) + (version, account, container, obj) = req.split_path(3, 4, True) except ValueError: return self.app # verify new quota headers are properly formatted - if container and not obj and req.method in ('PUT', 'POST'): + if not obj and req.method in ('PUT', 'POST'): val = req.headers.get('X-Container-Meta-Quota-Bytes') if val and not val.isdigit(): return HTTPBadRequest(body='Invalid bytes quota.') diff --git a/test/unit/common/middleware/test_quotas.py b/test/unit/common/middleware/test_quotas.py index 89e2204f54..0d9147d8b7 100644 --- a/test/unit/common/middleware/test_quotas.py +++ b/test/unit/common/middleware/test_quotas.py @@ -48,6 +48,14 @@ def start_response(*args): class TestContainerQuotas(unittest.TestCase): + def test_split_path_empty_container_path_segment(self): + app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) + req = Request.blank('/v1/a//something/something_else', + environ={'REQUEST_METHOD': 'PUT', + 'swift.cache': {'key':'value'}}) + res = req.get_response(app) + self.assertEquals(res.status_int, 200) + def test_not_handled(self): app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {}) req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': 'PUT'})