Fix 500 from account-quota middleware

If a user had set X-Account-Meta-Quota-Bytes to something non-integer
prior to the installation of the account-quota middleware, then the
quota check would choke on it. Now a non-integer value is treated as
"no quota".

Change-Id: I5c38911be1f66fa293aea9c78590d4ce7d184113
This commit is contained in:
Samuel Merritt 2013-10-09 12:25:42 -07:00
parent 7accddf1c3
commit 2419df2730
2 changed files with 17 additions and 1 deletions

View File

@ -114,7 +114,10 @@ class AccountQuotaMiddleware(object):
return self.app
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:
return HTTPRequestEntityTooLarge()

View File

@ -113,6 +113,19 @@ class TestAccountQuota(unittest.TestCase):
res = req.get_response(app)
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):
headers = [('x-account-bytes-used', '1000'),
('x-account-meta-quota-bytes', '0')]