Merge "Fix account quota mw for handling a bad source path"

This commit is contained in:
Jenkins 2014-03-15 01:32:45 +00:00 committed by Gerrit Code Review
commit 6cdf784e2f
2 changed files with 19 additions and 3 deletions

View File

@ -52,7 +52,7 @@ Due to the eventual consistency further uploads might be possible until the
account size has been updated. account size has been updated.
""" """
from swift.common.constraints import check_copy_from_header
from swift.common.swob import HTTPForbidden, HTTPRequestEntityTooLarge, \ from swift.common.swob import HTTPForbidden, HTTPRequestEntityTooLarge, \
HTTPBadRequest, wsgify HTTPBadRequest, wsgify
from swift.common.utils import register_swift_info from swift.common.utils import register_swift_info
@ -109,7 +109,11 @@ class AccountQuotaMiddleware(object):
if request.method == 'COPY': if request.method == 'COPY':
copy_from = container + '/' + obj copy_from = container + '/' + obj
else: 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) content_length = (request.content_length or 0)
@ -124,7 +128,7 @@ class AccountQuotaMiddleware(object):
return self.app return self.app
if copy_from: if copy_from:
path = '/' + ver + '/' + account + '/' + copy_from.lstrip('/') path = '/' + ver + '/' + account + '/' + copy_from
object_info = get_object_info(request.environ, self.app, path) object_info = get_object_info(request.environ, self.app, path)
if not object_info or not object_info['length']: if not object_info or not object_info['length']:
content_length = 0 content_length = 0

View File

@ -237,6 +237,18 @@ class TestAccountQuota(unittest.TestCase):
res = req.get_response(app) res = req.get_response(app)
self.assertEquals(res.status_int, 200) 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): def test_exceed_bytes_quota_reseller(self):
headers = [('x-account-bytes-used', '1000'), headers = [('x-account-bytes-used', '1000'),
('x-account-meta-quota-bytes', '0')] ('x-account-meta-quota-bytes', '0')]