enforce account quotas on empty accounts

Change-Id: Icade637b0d384dcc87aaa31da3861cd2646d4ccd
Closes-Bug: #1827394
This commit is contained in:
John Dickinson 2019-05-02 10:53:44 -06:00 committed by Tim Burke
parent 5cd854b783
commit 0606f404fe
2 changed files with 29 additions and 1 deletions

View File

@ -109,7 +109,7 @@ class AccountQuotaMiddleware(object):
account_info = get_account_info(request.environ, self.app,
swift_source='AQ')
if not account_info or not account_info['bytes']:
if not account_info:
return self.app
try:
quota = int(account_info['meta'].get('quota-bytes', -1))

View File

@ -210,6 +210,34 @@ class TestAccountQuota(unittest.TestCase):
res = req.get_response(app)
self.assertEqual(res.status_int, 200)
def test_exceed_quota_bytes_on_empty_account_not_authorized(self):
headers = [('x-account-bytes-used', '0'),
('x-account-meta-quota-bytes', '10')]
app = FakeAuthFilter(
account_quotas.AccountQuotaMiddleware(FakeApp(headers)))
cache = FakeCache(None)
req = Request.blank('/v1/a/c/o', method='PUT',
headers={'x-auth-token': 'secret',
'content-length': '100'},
environ={'swift.cache': cache})
res = req.get_response(app)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_exceed_quota_bytes_not_authorized(self):
headers = [('x-account-bytes-used', '100'),
('x-account-meta-quota-bytes', '1000')]
app = FakeAuthFilter(
account_quotas.AccountQuotaMiddleware(FakeApp(headers)))
cache = FakeCache(None)
req = Request.blank('/v1/a/c/o', method='PUT',
headers={'x-auth-token': 'secret',
'content-length': '901'},
environ={'swift.cache': cache})
res = req.get_response(app)
self.assertEqual(res.status_int, 413)
self.assertEqual(res.body, b'Upload exceeds quota.')
def test_over_quota_container_create_still_works(self):
headers = [('x-account-bytes-used', '1001'),
('x-account-meta-quota-bytes', '1000')]