Merge "Fix 500 from account-quota middleware"

This commit is contained in:
Jenkins 2013-10-16 04:01:30 +00:00 committed by Gerrit Code Review
commit 2b639f5ecc
2 changed files with 17 additions and 1 deletions

View File

@ -114,7 +114,10 @@ class AccountQuotaMiddleware(object):
return self.app return self.app
new_size = int(account_info['bytes']) + content_length new_size = int(account_info['bytes']) + content_length
quota = int(account_info['meta'].get('quota-bytes', -1)) try:
quota = int(account_info['meta'].get('quota-bytes', -1))
except ValueError:
return self.app
if 0 <= quota < new_size: if 0 <= quota < new_size:
return HTTPRequestEntityTooLarge() return HTTPRequestEntityTooLarge()

View File

@ -113,6 +113,19 @@ 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_bogus_quota_is_ignored(self):
# This can happen if the metadata was set by a user prior to the
# activation of the account-quota middleware
headers = [('x-account-bytes-used', '1000'),
('x-account-meta-quota-bytes', 'pasty-plastogene')]
app = account_quotas.AccountQuotaMiddleware(FakeApp(headers))
cache = FakeCache(None)
req = Request.blank('/v1/a/c/o',
environ={'REQUEST_METHOD': 'PUT',
'swift.cache': cache})
res = req.get_response(app)
self.assertEquals(res.status_int, 200)
def test_exceed_bytes_quota(self): def test_exceed_bytes_quota(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')]