Esempio n. 1
0
 def _test_get_response(self, method, container='bucket', obj=None,
                        permission=None, skip_check=False,
                        req_klass=S3Request, fake_swift_resp=None):
     path = '/' + container + ('/' + obj if obj else '')
     req = Request.blank(path,
                         environ={'REQUEST_METHOD': method},
                         headers={'Authorization': 'AWS test:tester:hmac',
                                  'Date': self.get_date_header()})
     if issubclass(req_klass, S3AclRequest):
         s3_req = req_klass(
             req.environ, MagicMock(),
             True, self.conf.storage_domain,
             self.conf.location, self.conf.force_swift_request_proxy_log,
             self.conf.dns_compliant_bucket_names,
             self.conf.allow_multipart_uploads, self.conf.allow_no_owner)
     else:
         s3_req = req_klass(
             req.environ, MagicMock(),
             True, self.conf.storage_domain,
             self.conf.location, self.conf.force_swift_request_proxy_log,
             self.conf.dns_compliant_bucket_names,
             self.conf.allow_multipart_uploads, self.conf.allow_no_owner)
     s3_req.set_acl_handler(
         get_acl_handler(s3_req.controller_name)(s3_req, DebugLogger()))
     with patch('swift.common.middleware.s3api.s3request.S3Request.'
                '_get_response') as mock_get_resp, \
             patch('swift.common.middleware.s3api.subresource.ACL.'
                   'check_permission') as m_check_permission:
         mock_get_resp.return_value = fake_swift_resp \
             or FakeResponse(self.conf.s3_acl)
         return mock_get_resp, m_check_permission,\
             s3_req.get_response(self.s3api)
Esempio n. 2
0
 def _test_get_response(self, method, container='bucket', obj=None,
                        permission=None, skip_check=False,
                        req_klass=S3Request, fake_swift_resp=None):
     path = '/' + container + ('/' + obj if obj else '')
     req = Request.blank(path,
                         environ={'REQUEST_METHOD': method},
                         headers={'Authorization': 'AWS test:tester:hmac',
                                  'Date': self.get_date_header()})
     if issubclass(req_klass, S3AclRequest):
         s3_req = req_klass(
             req.environ, MagicMock(),
             True, self.conf.storage_domain,
             self.conf.location, self.conf.force_swift_request_proxy_log,
             self.conf.dns_compliant_bucket_names,
             self.conf.allow_multipart_uploads, self.conf.allow_no_owner)
     else:
         s3_req = req_klass(
             req.environ, MagicMock(),
             True, self.conf.storage_domain,
             self.conf.location, self.conf.force_swift_request_proxy_log,
             self.conf.dns_compliant_bucket_names,
             self.conf.allow_multipart_uploads, self.conf.allow_no_owner)
     s3_req.set_acl_handler(
         get_acl_handler(s3_req.controller_name)(s3_req, DebugLogger()))
     with patch('swift.common.middleware.s3api.s3request.S3Request.'
                '_get_response') as mock_get_resp, \
             patch('swift.common.middleware.s3api.subresource.ACL.'
                   'check_permission') as m_check_permission:
         mock_get_resp.return_value = fake_swift_resp \
             or FakeResponse(self.conf.s3_acl)
         return mock_get_resp, m_check_permission,\
             s3_req.get_response(self.s3api)
Esempio n. 3
0
 def test_get_acl_handler(self):
     expected_handlers = (('Bucket', BucketAclHandler), ('Object',
                                                         ObjectAclHandler),
                          ('S3Acl', S3AclHandler), ('Part', PartAclHandler),
                          ('Upload', UploadAclHandler),
                          ('Uploads', UploadsAclHandler), ('Foo',
                                                           BaseAclHandler))
     for name, expected in expected_handlers:
         handler = get_acl_handler(name)
         self.assertTrue(issubclass(handler, expected))
Esempio n. 4
0
    def handle_request(self, req):
        self.logger.debug('Calling S3Api Middleware')
        try:
            controller = req.controller(self.app, self.conf, self.logger)
        except S3NotImplemented:
            # TODO: Probably we should distinct the error to log this warning
            self.logger.warning('multipart: No SLO middleware in pipeline')
            raise

        acl_handler = get_acl_handler(req.controller_name)(req, self.logger)
        req.set_acl_handler(acl_handler)

        if hasattr(controller, req.method):
            handler = getattr(controller, req.method)
            if not getattr(handler, 'publicly_accessible', False):
                raise MethodNotAllowed(req.method,
                                       req.controller.resource_type())
            res = handler(req)
        else:
            raise MethodNotAllowed(req.method, req.controller.resource_type())

        return res
Esempio n. 5
0
File: s3api.py Progetto: mahak/swift
    def handle_request(self, req):
        self.logger.debug('Calling S3Api Middleware')
        try:
            controller = req.controller(self.app, self.conf, self.logger)
        except S3NotImplemented:
            # TODO: Probably we should distinct the error to log this warning
            self.logger.warning('multipart: No SLO middleware in pipeline')
            raise

        acl_handler = get_acl_handler(req.controller_name)(req, self.logger)
        req.set_acl_handler(acl_handler)

        if hasattr(controller, req.method):
            handler = getattr(controller, req.method)
            if not getattr(handler, 'publicly_accessible', False):
                raise MethodNotAllowed(req.method,
                                       req.controller.resource_type())
            res = handler(req)
        else:
            raise MethodNotAllowed(req.method,
                                   req.controller.resource_type())

        return res