Exemple #1
0
 def test_check_object_creation_content_type(self):
     headers = {'Transfer-Encoding': 'chunked',
                'Content-Type': 'text/plain'}
     self.assertEquals(constraints.check_object_creation(Request.blank('/',
         headers=headers), 'object_name'), None)
     headers = {'Transfer-Encoding': 'chunked'}
     self.assert_(isinstance(constraints.check_object_creation(
         Request.blank('/', headers=headers), 'object_name'),
         HTTPBadRequest))
Exemple #2
0
 def test_check_object_creation_name_length(self):
     headers = {'Transfer-Encoding': 'chunked',
                'Content-Type': 'text/plain'}
     name = 'o' * constraints.MAX_OBJECT_NAME_LENGTH
     self.assertEquals(constraints.check_object_creation(Request.blank('/',
         headers=headers), name), None)
     name = 'o' * (constraints.MAX_OBJECT_NAME_LENGTH + 1)
     self.assert_(isinstance(constraints.check_object_creation(
         Request.blank('/', headers=headers), name),
         HTTPBadRequest))
Exemple #3
0
 def test_check_object_creation_bad_content_type(self):
     headers = {'Transfer-Encoding': 'chunked',
                'Content-Type': '\xff\xff'}
     resp = constraints.check_object_creation(
         Request.blank('/', headers=headers), 'object_name')
     self.assert_(isinstance(resp, HTTPBadRequest))
     self.assert_('Content-Type' in resp.body)
Exemple #4
0
 def test_check_object_creation_content_length(self):
     headers = {'Content-Length': str(constraints.MAX_FILE_SIZE),
                'Content-Type': 'text/plain'}
     self.assertEquals(constraints.check_object_creation(Request.blank('/',
         headers=headers), 'object_name'), None)
     headers = {'Content-Length': str(constraints.MAX_FILE_SIZE + 1),
                'Content-Type': 'text/plain'}
     self.assert_(isinstance(constraints.check_object_creation(
         Request.blank('/', headers=headers), 'object_name'),
         HTTPRequestEntityTooLarge))
     headers = {'Transfer-Encoding': 'chunked',
                'Content-Type': 'text/plain'}
     self.assertEquals(constraints.check_object_creation(Request.blank('/',
         headers=headers), 'object_name'), None)
     headers = {'Content-Type': 'text/plain'}
     self.assert_(isinstance(constraints.check_object_creation(
         Request.blank('/', headers=headers), 'object_name'),
         HTTPLengthRequired))
Exemple #5
0
 def test_check_object_manifest_header(self):
     resp = constraints.check_object_creation(Request.blank('/',
         headers={'X-Object-Manifest': 'container/prefix', 'Content-Length':
         '0', 'Content-Type': 'text/plain'}), 'manifest')
     self.assert_(not resp)
     resp = constraints.check_object_creation(Request.blank('/',
         headers={'X-Object-Manifest': 'container', 'Content-Length': '0',
         'Content-Type': 'text/plain'}), 'manifest')
     self.assert_(isinstance(resp, HTTPBadRequest))
     resp = constraints.check_object_creation(Request.blank('/',
         headers={'X-Object-Manifest': '/container/prefix',
         'Content-Length': '0', 'Content-Type': 'text/plain'}), 'manifest')
     self.assert_(isinstance(resp, HTTPBadRequest))
     resp = constraints.check_object_creation(Request.blank('/',
         headers={'X-Object-Manifest': 'container/prefix?query=param',
         'Content-Length': '0', 'Content-Type': 'text/plain'}), 'manifest')
     self.assert_(isinstance(resp, HTTPBadRequest))
     resp = constraints.check_object_creation(Request.blank('/',
         headers={'X-Object-Manifest': 'container/prefix&query=param',
         'Content-Length': '0', 'Content-Type': 'text/plain'}), 'manifest')
     self.assert_(isinstance(resp, HTTPBadRequest))
     resp = constraints.check_object_creation(Request.blank('/',
         headers={'X-Object-Manifest': 'http://host/container/prefix',
         'Content-Length': '0', 'Content-Type': 'text/plain'}), 'manifest')
     self.assert_(isinstance(resp, HTTPBadRequest))
Exemple #6
0
 """Handle HTTP PUT requests for the Chase Object Server."""
 try:
     device, partition, account, container, obj = \
         split_path(unquote(request.path), 5, 5, True)
 except ValueError, err:
     return HTTPBadRequest(body=str(err),
                           request=request,
                           content_type='text/plain')
 if self.mount_check and not check_mount(self.devices, device):
     return Response(status='507 %s is not mounted' % device)
 if 'x-timestamp' not in request.headers or \
             not check_float(request.headers['x-timestamp']):
     return HTTPBadRequest(body='Missing timestamp',
                           request=request,
                           content_type='text/plain')
 error_response = check_object_creation(request, obj)
 if error_response:
     return error_response
 new_delete_at = int(request.headers.get('X-Delete-At') or 0)
 if new_delete_at and new_delete_at < time.time():
     return HTTPBadRequest(body='X-Delete-At in past',
                           request=request,
                           content_type='text/plain')
 file = DiskFile(self.devices,
                 device,
                 partition,
                 account,
                 container,
                 obj,
                 self.logger,
                 disk_chunk_size=self.disk_chunk_size)
Exemple #7
0
    def PUT(self, request):
        """Handle HTTP PUT requests for the Chase Object Server."""
        try:
            device, partition, account, container, obj = \
                split_path(unquote(request.path), 5, 5, True)
        except ValueError, err:
            return HTTPBadRequest(body=str(err), request=request,
                        content_type='text/plain')
        if self.mount_check and not check_mount(self.devices, device):
            return Response(status='507 %s is not mounted' % device)
        if 'x-timestamp' not in request.headers or \
                    not check_float(request.headers['x-timestamp']):
            return HTTPBadRequest(body='Missing timestamp', request=request,
                        content_type='text/plain')
        error_response = check_object_creation(request, obj)
        if error_response:
            return error_response
        new_delete_at = int(request.headers.get('X-Delete-At') or 0)
        if new_delete_at and new_delete_at < time.time():
            return HTTPBadRequest(body='X-Delete-At in past', request=request,
                                  content_type='text/plain')
        file = DiskFile(self.devices, device, partition, account, container,
                        obj, self.logger, disk_chunk_size=self.disk_chunk_size)
        orig_timestamp = file.metadata.get('X-Timestamp')
        upload_expiration = time.time() + self.max_upload_time
        etag = md5()
        upload_size = 0
        last_sync = 0
        with file.mkstemp() as (fd, tmppath):
            if 'content-length' in request.headers: