예제 #1
0
    def test_not_handled(self):
        app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
        req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': 'PUT'})
        res = req.get_response(app)
        self.assertEquals(res.status_int, 200)

        app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
        req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'GET'})
        res = req.get_response(app)
        self.assertEquals(res.status_int, 200)
예제 #2
0
 def test_exceed_counts_quota_copy_cross_account_PUT_verb(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     a_c_cache = {
         'storage_policy': '0',
         'meta': {
             'quota-count': '2'
         },
         'status': 200,
         'object_count': 1
     }
     a2_c_cache = {
         'storage_policy': '0',
         'meta': {
             'quota-count': '1'
         },
         'status': 200,
         'object_count': 1
     }
     req = Request.blank('/v1/a2/c/o',
                         environ={
                             'REQUEST_METHOD': 'PUT',
                             'swift.container/a/c': a_c_cache,
                             'swift.container/a2/c': a2_c_cache
                         },
                         headers={
                             'X-Copy-From': '/c2/o2',
                             'X-Copy-From-Account': 'a'
                         })
     res = req.get_response(app)
     self.assertEquals(res.status_int, 413)
     self.assertEquals(res.body, 'Upload exceeds quota.')
예제 #3
0
 def test_split_path_empty_container_path_segment(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     req = Request.blank('/v1/a//something/something_else',
                         environ={'REQUEST_METHOD': 'PUT',
                                  'swift.cache': {'key': 'value'}})
     res = req.get_response(app)
     self.assertEquals(res.status_int, 200)
예제 #4
0
    def test_valid_quotas(self):
        req = Request.blank(
            '/v1/a/c',
            environ={'REQUEST_METHOD': 'POST',
                     'HTTP_X_CONTAINER_META_QUOTA_BYTES': '123'})
        res = req.get_response(
            container_quotas.ContainerQuotaMiddleware(FakeApp(), {}))
        self.assertEquals(res.status_int, 200)

        req = Request.blank(
            '/v1/a/c',
            environ={'REQUEST_METHOD': 'POST',
                     'HTTP_X_CONTAINER_META_QUOTA_COUNT': '123'})
        res = req.get_response(
            container_quotas.ContainerQuotaMiddleware(FakeApp(), {}))
        self.assertEquals(res.status_int, 200)
예제 #5
0
 def test_no_quotas(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     req = Request.blank(
         '/v1/a/c/o',
         environ={'REQUEST_METHOD': 'PUT', 'swift.cache': FakeCache({}),
                  'CONTENT_LENGTH': '100'})
     res = req.get_response(app)
     self.assertEquals(res.status_int, 200)
예제 #6
0
 def test_exceed_bytes_quota(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     cache = FakeCache({'bytes': 0, 'meta': {'quota-bytes': '2'}})
     req = Request.blank(
         '/v1/a/c/o',
         environ={'REQUEST_METHOD': 'PUT', 'swift.cache': cache,
                  'CONTENT_LENGTH': '100'})
     res = req.get_response(app)
     self.assertEquals(res.status_int, 413)
예제 #7
0
 def test_not_exceed_counts_quota_copy_from(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     cache = FakeCache({'object_count': 1, 'meta': {'quota-count': '2'}})
     req = Request.blank('/v1/a/c/o',
                         environ={'REQUEST_METHOD': 'PUT',
                         'swift.cache': cache},
                         headers={'x-copy-from': '/c2/o2'})
     res = req.get_response(app)
     self.assertEquals(res.status_int, 200)
예제 #8
0
 def test_bytes_quota_copy_from_no_src(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     cache = FakeCache({'bytes': 0, 'meta': {'quota-bytes': '100'}})
     req = Request.blank('/v1/a/c/o',
                         environ={'REQUEST_METHOD': 'PUT',
                         'swift.object/a/c2/o2': {'length': 10},
                         'swift.cache': cache},
                         headers={'x-copy-from': '/c2/o3'})
     res = req.get_response(app)
     self.assertEquals(res.status_int, 200)
예제 #9
0
 def test_exceed_counts_quota(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     cache = FakeCache({'object_count': 1, 'meta': {'quota-count': '1'}})
     req = Request.blank(
         '/v1/a/c/o',
         environ={'REQUEST_METHOD': 'PUT', 'swift.cache': cache,
                  'CONTENT_LENGTH': '100'})
     res = req.get_response(app)
     self.assertEqual(res.status_int, 413)
     self.assertEqual(res.body, b'Upload exceeds quota.')
예제 #10
0
 def test_auth_fail(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     cache = FakeCache({'object_count': 1, 'meta': {'quota-count': '1'},
                        'write_acl': None})
     req = Request.blank(
         '/v1/a/c/o',
         environ={'REQUEST_METHOD': 'PUT', 'swift.cache': cache,
                  'CONTENT_LENGTH': '100',
                  'swift.authorize': lambda *args: HTTPUnauthorized()})
     res = req.get_response(app)
     self.assertEquals(res.status_int, 401)
예제 #11
0
 def test_exceed_counts_quota_copy_verb(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     cache = FakeCache({'object_count': 1, 'meta': {'quota-count': '1'}})
     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, 413)
     self.assertEquals(res.body, 'Upload exceeds quota.')
예제 #12
0
 def test_not_exceed_bytes_quota_copy_verb(self):
     app = container_quotas.ContainerQuotaMiddleware(FakeApp(), {})
     cache = FakeCache({'bytes': 0, 'meta': {'quota-bytes': '100'}})
     req = Request.blank('/v1/a/c2/o2',
                         environ={
                             'REQUEST_METHOD': 'COPY',
                             'swift.object/a/c2/o2': {
                                 'length': 10
                             },
                             'swift.cache': cache
                         },
                         headers={'Destination': '/c/o'})
     res = req.get_response(app)
     self.assertEqual(res.status_int, 200)