def test_exceed_bytes_quota_reseller(self): headers = [('x-account-bytes-used', '1000'), ('x-account-meta-quota-bytes', '0')] app = account_quotas.AccountQuotaMiddleware(FakeApp(headers)) cache = FakeCache(None) req = Request.blank('/v1/a', environ={'REQUEST_METHOD': 'PUT', 'swift.cache': cache, 'reseller_request': True}) res = req.get_response(app) 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_over_quota_obj_post_still_works(self): headers = [('x-account-bytes-used', '1001'), ('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': 'POST', 'HTTP_X_OBJECT_META_BERT': 'ernie', 'swift.cache': cache}) res = req.get_response(app) self.assertEquals(res.status_int, 200)
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_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_container_request_ignores_attempt_to_set_quotas(self): # As with an object, if you try to set X-Account-Meta-* on a # container, it's ignored. headers = [('x-account-bytes-used', '1000')] app = account_quotas.AccountQuotaMiddleware(FakeApp(headers)) cache = FakeCache(None) req = Request.blank('/v1/a/c', headers={'X-Account-Meta-Quota-Bytes': '99999'}, environ={'REQUEST_METHOD': 'PUT', 'swift.cache': cache}) res = req.get_response(app) self.assertEquals(res.status_int, 200)
def test_under_quota_authorized(self): headers = [('x-account-bytes-used', '0'), ('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'}, environ={'swift.cache': cache}) res = req.get_response(app) self.assertEqual(res.status_int, 200)
def test_not_exceed_bytes_quota_copy_verb(self): headers = [('x-account-bytes-used', '0'), ('x-account-meta-quota-bytes', '1000'), ('content-length', '1000')] app = account_quotas.AccountQuotaMiddleware(FakeApp(headers)) cache = FakeCache(None) req = Request.blank('/v1/a/c2/o2', environ={'REQUEST_METHOD': 'COPY', 'swift.cache': cache}, headers={'Destination': '/c/o'}) res = req.get_response(app) self.assertEquals(res.status_int, 200)
def test_obj_request_ignores_attempt_to_set_quotas(self): # If you try to set X-Account-Meta-* on an object, it's ignored, so # the quota middleware shouldn't complain about it even if we're not a # reseller admin. headers = [('x-account-bytes-used', '1000')] app = account_quotas.AccountQuotaMiddleware(FakeApp(headers)) cache = FakeCache(None) req = Request.blank('/v1/a/c/o', headers={'X-Account-Meta-Quota-Bytes': '99999'}, environ={'REQUEST_METHOD': 'PUT', 'swift.cache': cache}) res = req.get_response(app) self.assertEquals(res.status_int, 200)
def test_delete_quotas_reseller(self): headers = [ ('x-account-bytes-used', '0'), ] app = account_quotas.AccountQuotaMiddleware(FakeApp(headers)) req = Request.blank('/v1/a', environ={ 'REQUEST_METHOD': 'POST', 'HTTP_X_ACCOUNT_META_QUOTA_BYTES': '', 'reseller_request': True }) 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')] 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.assertEqual(res.status_int, 413) self.assertEqual(res.body, b'Upload exceeds quota.')
def test_unauthorized(self): headers = [ ('x-account-bytes-used', '1000'), ] 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) #Response code of 200 because authentication itself is not done here self.assertEquals(res.status_int, 200)
def test_delete_quotas(self): headers = [ ('x-account-bytes-used', '0'), ] app = account_quotas.AccountQuotaMiddleware(FakeApp(headers)) cache = FakeCache(None) req = Request.blank('/v1/a', environ={ 'REQUEST_METHOD': 'POST', 'swift.cache': cache, 'HTTP_X_ACCOUNT_META_QUOTA_BYTES': '' }) res = req.get_response(app) self.assertEquals(res.status_int, 403)
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.')