summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Boucher <fabien.boucher@enovance.com>2013-11-25 23:26:09 +0100
committerFabien Boucher <fabien.boucher@enovance.com>2014-02-19 13:32:32 +0100
commit7188275ac24ecf26951ba5ab248934890becbc21 (patch)
tree9fb5a7757b9cf3358c815247d5f8fddac24deee4
parente60d541d9a2523b07b0f09b01a15c2037bfd88f7 (diff)
downloadswift-7188275ac24ecf26951ba5ab248934890becbc21.tar.gz
Fix account quota mw for handling a bad source path
The copy source must be container/object. This patch avoids the server to return an internal server error when user provides a path without a container. Change-Id: I8ea4e62b2a00c4b4a1666d30411a6c93a4f848a5 Fixes: bug #1254626
-rw-r--r--swift/common/middleware/account_quotas.py10
-rw-r--r--test/unit/common/middleware/test_account_quotas.py12
2 files changed, 19 insertions, 3 deletions
diff --git a/swift/common/middleware/account_quotas.py b/swift/common/middleware/account_quotas.py
index e4aa23504..ec4a3fda2 100644
--- a/swift/common/middleware/account_quotas.py
+++ b/swift/common/middleware/account_quotas.py
@@ -52,7 +52,7 @@ Due to the eventual consistency further uploads might be possible until the
account size has been updated.
"""
-
+from swift.common.constraints import check_copy_from_header
from swift.common.swob import HTTPForbidden, HTTPRequestEntityTooLarge, \
HTTPBadRequest, wsgify
from swift.common.utils import register_swift_info
@@ -109,7 +109,11 @@ class AccountQuotaMiddleware(object):
if request.method == 'COPY':
copy_from = container + '/' + obj
else:
- copy_from = request.headers.get('X-Copy-From')
+ if 'x-copy-from' in request.headers:
+ src_cont, src_obj = check_copy_from_header(request)
+ copy_from = "%s/%s" % (src_cont, src_obj)
+ else:
+ copy_from = None
content_length = (request.content_length or 0)
@@ -124,7 +128,7 @@ class AccountQuotaMiddleware(object):
return self.app
if copy_from:
- path = '/' + ver + '/' + account + '/' + copy_from.lstrip('/')
+ path = '/' + ver + '/' + account + '/' + copy_from
object_info = get_object_info(request.environ, self.app, path)
if not object_info or not object_info['length']:
content_length = 0
diff --git a/test/unit/common/middleware/test_account_quotas.py b/test/unit/common/middleware/test_account_quotas.py
index d24af41bf..e040dd6a6 100644
--- a/test/unit/common/middleware/test_account_quotas.py
+++ b/test/unit/common/middleware/test_account_quotas.py
@@ -237,6 +237,18 @@ class TestAccountQuota(unittest.TestCase):
res = req.get_response(app)
self.assertEquals(res.status_int, 200)
+ def test_quota_copy_from_bad_src(self):
+ headers = [('x-account-bytes-used', '0'),
+ ('x-account-meta-quota-bytes', '1000')]
+ app = account_quotas.AccountQuotaMiddleware(FakeApp(headers))
+ cache = FakeCache(None)
+ req = Request.blank('/v1/a/c/o',
+ environ={'REQUEST_METHOD': 'PUT',
+ 'swift.cache': cache},
+ headers={'x-copy-from': 'bad_path'})
+ res = req.get_response(app)
+ self.assertEquals(res.status_int, 412)
+
def test_exceed_bytes_quota_reseller(self):
headers = [('x-account-bytes-used', '1000'),
('x-account-meta-quota-bytes', '0')]