diff --git a/swift/common/middleware/account_quotas.py b/swift/common/middleware/account_quotas.py index e4aa235049..ec4a3fda2e 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 d24af41bfb..e040dd6a6c 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')]