diff --git a/swift/common/middleware/account_quotas.py b/swift/common/middleware/account_quotas.py index 8ea804cac3..633a686800 100644 --- a/swift/common/middleware/account_quotas.py +++ b/swift/common/middleware/account_quotas.py @@ -84,6 +84,8 @@ class AccountQuotaMiddleware(object): return HTTPForbidden() account_info = get_account_info(request.environ, self.app) + if not account_info or not account_info['bytes']: + return self.app new_size = int(account_info['bytes']) + (request.content_length or 0) quota = int(account_info['meta'].get('quota-bytes', -1)) diff --git a/test/unit/common/middleware/test_account_quotas.py b/test/unit/common/middleware/test_account_quotas.py index ffbec27d09..752bcc3ebe 100644 --- a/test/unit/common/middleware/test_account_quotas.py +++ b/test/unit/common/middleware/test_account_quotas.py @@ -29,6 +29,15 @@ class FakeCache(object): pass +class FakeBadApp(object): + def __init__(self, headers=[]): + self.headers = headers + + def __call__(self, env, start_response): + start_response('404 NotFound', self.headers) + return [] + + class FakeApp(object): def __init__(self, headers=[]): self.headers = headers @@ -88,6 +97,26 @@ class TestAccountQuota(unittest.TestCase): res = req.get_response(app) self.assertEquals(res.status_int, 200) + def test_bad_application_quota(self): + headers = [] + app = account_quotas.AccountQuotaMiddleware(FakeBadApp(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, 404) + + def test_no_info_quota(self): + headers = [] + 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_not_exceed_bytes_quota(self): headers = [('x-account-bytes-used', '1000'), ('x-account-meta-quota-bytes', 2000)]