예제 #1
0
    def test_copy_object_2d_way(self):
        # create source object
        src_object_name = data_utils.rand_name(name='SrcObject')
        src_data = data_utils.arbitrary_string(size=len(src_object_name) * 2,
                                               base_text=src_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   src_object_name, src_data)
        # create destination object
        dst_object_name = data_utils.rand_name(name='DstObject')
        dst_data = data_utils.arbitrary_string(size=len(dst_object_name) * 3,
                                               base_text=dst_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   dst_object_name, dst_data)
        # copy source object to destination
        resp, _ = self.object_client.copy_object_2d_way(self.container_name,
                                                        src_object_name,
                                                        dst_object_name)
        self.assertHeaders(resp, 'Object', 'COPY')
        #Bug 1417469
        #self.assertEqual(
        #    resp['x-copied-from'],
        #    self.container_name + "/" + src_object_name)

        # check data
        self._check_copied_obj(dst_object_name, src_data)
예제 #2
0
 def test_arbitrary_string(self):
     actual = data_utils.arbitrary_string()
     self.assertEqual(actual, "test")
     actual = data_utils.arbitrary_string(size=30, base_text="abc")
     self.assertEqual(actual, "abc" * (30 / len("abc")))
     actual = data_utils.arbitrary_string(size=5, base_text="deadbeaf")
     self.assertEqual(actual, "deadb")
예제 #3
0
    def test_copy_object_in_same_container(self):
        # create source object
        src_object_name = data_utils.rand_name(name='SrcObject')
        src_data = data_utils.arbitrary_string(size=len(src_object_name) * 2,
                                               base_text=src_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   src_object_name,
                                                   src_data)
        # create destination object
        dst_object_name = data_utils.rand_name(name='DstObject')
        dst_data = data_utils.arbitrary_string(size=len(dst_object_name) * 3,
                                               base_text=dst_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   dst_object_name,
                                                   dst_data)
        # copy source object to destination
        resp, _ = self.object_client.copy_object_in_same_container(
            self.container_name, src_object_name, dst_object_name)
        self.assertEqual(resp['status'], '201')
        self.assertHeaders(resp, 'Object', 'PUT')

        # check data
        resp, body = self.object_client.get_object(self.container_name,
                                                   dst_object_name)
        self.assertEqual(body, src_data)
예제 #4
0
    def test_copy_object_2d_way(self):
        # create source object
        src_object_name = data_utils.rand_name(name='SrcObject')
        src_data = data_utils.arbitrary_string(size=len(src_object_name) * 2,
                                               base_text=src_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   src_object_name, src_data)
        # create destination object
        dst_object_name = data_utils.rand_name(name='DstObject')
        dst_data = data_utils.arbitrary_string(size=len(dst_object_name) * 3,
                                               base_text=dst_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   dst_object_name, dst_data)
        # copy source object to destination
        resp, _ = self.object_client.copy_object_2d_way(self.container_name,
                                                        src_object_name,
                                                        dst_object_name)
        self.assertEqual(resp['status'], '201')
        self.assertHeaders(resp, 'Object', 'COPY')

        self.assertIn('last-modified', resp)
        self.assertIn('x-copied-from', resp)
        self.assertIn('x-copied-from-last-modified', resp)
        self.assertNotEqual(len(resp['last-modified']), 0)
        self.assertEqual(
            resp['x-copied-from'],
            self.container_name + "/" + src_object_name)
        self.assertNotEqual(len(resp['x-copied-from-last-modified']), 0)

        # check data
        resp, body = self.object_client.get_object(self.container_name,
                                                   dst_object_name)
        self.assertEqual(body, src_data)
    def test_copy_object_2d_way(self):
        # Copy storage object

        # Create source Object
        src_object_name = rand_name(name='SrcObject')
        src_data = arbitrary_string(size=len(src_object_name) * 2,
                                    base_text=src_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   src_object_name, src_data)

        # Create destination Object
        dst_object_name = rand_name(name='DstObject')
        dst_data = arbitrary_string(size=len(dst_object_name) * 3,
                                    base_text=dst_object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   dst_object_name, dst_data)

        # Copy source object to destination
        resp, _ = self.object_client.copy_object_2d_way(self.container_name,
                                                        src_object_name,
                                                        dst_object_name)
        self.assertEqual(resp['status'], '201')

        # Check data
        resp, body = self.object_client.get_object(self.container_name,
                                                   dst_object_name)
        self.assertEqual(body, src_data)
예제 #6
0
 def test_create_object(self):
     # create object
     object_name = rand_name(name="TestObject")
     data = arbitrary_string()
     resp, _ = self.object_client.create_object(self.container_name, object_name, data)
     # create another object
     object_name = rand_name(name="TestObject")
     data = arbitrary_string()
     resp, _ = self.object_client.create_object(self.container_name, object_name, data)
     self.assertEqual(resp["status"], "201")
예제 #7
0
    def generate_message_body(cls, repeat=1):
        '''Wrapper utility that sets the metadata of a queue.'''
        message_ttl = data_utils.rand_int_id(start=60,
                                             end=CONF.queuing.max_message_ttl)

        key = data_utils.arbitrary_string(size=20, base_text='QueuingKey')
        value = data_utils.arbitrary_string(size=20, base_text='QueuingValue')
        message_body = {key: value}

        rbody = ([{'body': message_body, 'ttl': message_ttl}] * repeat)
        return rbody
예제 #8
0
 def test_create_object(self):
     # create object
     object_name = data_utils.rand_name(name='TestObject')
     data = data_utils.arbitrary_string()
     resp, _ = self.object_client.create_object(self.container_name,
                                                object_name, data)
     # create another object
     object_name = data_utils.rand_name(name='TestObject')
     data = data_utils.arbitrary_string()
     resp, _ = self.object_client.create_object(self.container_name,
                                                object_name, data)
     self.assertEqual(resp['status'], '201')
     self.assertHeaders(resp, 'Object', 'PUT')
    def test_create_object(self):
        # Create storage object, test response

        #Create Object
        object_name = rand_name(name='TestObject')
        data = arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)

        #Create another Object
        object_name = rand_name(name='TestObject')
        data = arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        self.assertEqual(resp['status'], '201')
예제 #10
0
 def test_copy_object_2d_way(self):
     # create source object
     src_object_name = rand_name(name="SrcObject")
     src_data = arbitrary_string(size=len(src_object_name) * 2, base_text=src_object_name)
     resp, _ = self.object_client.create_object(self.container_name, src_object_name, src_data)
     # create destination object
     dst_object_name = rand_name(name="DstObject")
     dst_data = arbitrary_string(size=len(dst_object_name) * 3, base_text=dst_object_name)
     resp, _ = self.object_client.create_object(self.container_name, dst_object_name, dst_data)
     # copy source object to destination
     resp, _ = self.object_client.copy_object_2d_way(self.container_name, src_object_name, dst_object_name)
     self.assertEqual(resp["status"], "201")
     # check data
     resp, body = self.object_client.get_object(self.container_name, dst_object_name)
     self.assertEqual(body, src_data)
예제 #11
0
    def test_copy_object_across_containers(self):
        # create a container to use as  asource container
        src_container_name = data_utils.rand_name(name="TestSourceContainer")
        self.container_client.create_container(src_container_name)
        self.containers.append(src_container_name)
        # create a container to use as a destination container
        dst_container_name = data_utils.rand_name(name="TestDestinationContainer")
        self.container_client.create_container(dst_container_name)
        self.containers.append(dst_container_name)
        # create object in source container
        object_name = data_utils.rand_name(name="Object")
        data = data_utils.arbitrary_string(size=len(object_name) * 2, base_text=object_name)
        resp, _ = self.object_client.create_object(src_container_name, object_name, data)
        # set object metadata
        meta_key = data_utils.rand_name(name="test-")
        meta_value = data_utils.rand_name(name="MetaValue-")
        orig_metadata = {meta_key: meta_value}
        resp, _ = self.object_client.update_object_metadata(src_container_name, object_name, orig_metadata)
        self.assertIn(int(resp["status"]), HTTP_SUCCESS)
        self.assertHeaders(resp, "Object", "POST")

        # copy object from source container to destination container
        resp, _ = self.object_client.copy_object_across_containers(
            src_container_name, object_name, dst_container_name, object_name
        )
        self.assertEqual(resp["status"], "201")
        self.assertHeaders(resp, "Object", "PUT")

        # check if object is present in destination container
        resp, body = self.object_client.get_object(dst_container_name, object_name)
        self.assertEqual(body, data)
        actual_meta_key = "x-object-meta-" + meta_key
        self.assertIn(actual_meta_key, resp)
        self.assertEqual(resp[actual_meta_key], meta_value)
예제 #12
0
    def _create_manifest(self):
        # Create a manifest file for SLO uploading
        object_name = data_utils.rand_name(name='TestObject')
        object_name_base_1 = object_name + '_01'
        object_name_base_2 = object_name + '_02'
        data_size = MIN_SEGMENT_SIZE
        self.content = data_utils.arbitrary_string(data_size)
        self._create_object(self.container_name,
                            object_name_base_1,
                            self.content)
        self._create_object(self.container_name,
                            object_name_base_2,
                            self.content)

        path_object_1 = '/%s/%s' % (self.container_name,
                                    object_name_base_1)
        path_object_2 = '/%s/%s' % (self.container_name,
                                    object_name_base_2)
        data_manifest = [{'path': path_object_1,
                          'etag': hashlib.md5(self.content).hexdigest(),
                          'size_bytes': data_size},
                         {'path': path_object_2,
                          'etag': hashlib.md5(self.content).hexdigest(),
                          'size_bytes': data_size}]

        return json.dumps(data_manifest)
예제 #13
0
    def test_access_public_object_with_another_user_creds(self):
        # make container public-readable and access an object in it using
        # another user's credentials
        cont_headers = {"X-Container-Read": ".r:*,.rlistings"}
        resp_meta, body = self.container_client.update_container_metadata(
            self.container_name, metadata=cont_headers, metadata_prefix=""
        )
        self.assertIn(int(resp_meta["status"]), HTTP_SUCCESS)
        self.assertHeaders(resp_meta, "Container", "POST")

        # create object
        object_name = data_utils.rand_name(name="Object")
        data = data_utils.arbitrary_string(size=len(object_name) * 1, base_text=object_name)
        resp, _ = self.object_client.create_object(self.container_name, object_name, data)
        self.assertEqual(resp["status"], "201")
        self.assertHeaders(resp, "Object", "PUT")

        # list container metadata
        resp, _ = self.container_client.list_container_metadata(self.container_name)
        self.assertIn(int(resp["status"]), HTTP_SUCCESS)
        self.assertHeaders(resp, "Container", "HEAD")

        self.assertIn("x-container-read", resp)
        self.assertEqual(resp["x-container-read"], ".r:*,.rlistings")

        # get auth token of alternative user
        token = self.identity_client_alt.get_auth()
        headers = {"X-Auth-Token": token}
        # access object using alternate user creds
        resp, body = self.custom_object_client.get_object(self.container_name, object_name, metadata=headers)
        self.assertHeaders(resp, "Object", "GET")

        self.assertEqual(body, data)
예제 #14
0
    def test_object_metadata(self):
        # add metadata to storage object, test if metadata is retrievable

        # create Object
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        # set object metadata
        meta_key = data_utils.rand_name(name='test-')
        meta_value = data_utils.rand_name(name='MetaValue-')
        orig_metadata = {meta_key: meta_value}
        resp, _ = self.object_client.update_object_metadata(
            self.container_name, object_name, orig_metadata)
        self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
        self.assertHeaders(resp, 'Object', 'POST')

        # get object metadata
        resp, resp_metadata = self.object_client.list_object_metadata(
            self.container_name, object_name)
        self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
        self.assertHeaders(resp, 'Object', 'HEAD')

        actual_meta_key = 'x-object-meta-' + meta_key
        self.assertIn(actual_meta_key, resp)
        self.assertEqual(resp[actual_meta_key], meta_value)
예제 #15
0
    def test_put_object_using_temp_url(self):
        # make sure the metadata has been set
        new_data = data_utils.arbitrary_string(
            size=len(self.object_name),
            base_text=data_utils.rand_name(name="random"))

        expires = self._get_expiry_date()
        url = self._get_temp_url(self.container_name,
                                 self.object_name, "PUT",
                                 expires, self.key)

        # trying to put random data in the object using temp url
        resp, body = self.object_client.put_object_using_temp_url(
            url, new_data)

        self.assertIn(int(resp['status']), HTTP_SUCCESS)

        # Testing a HEAD on this Temp URL
        resp, body = self.object_client.head(url)
        self.assertIn(int(resp['status']), HTTP_SUCCESS)

        # Validate that the content of the object has been modified
        url = self._get_temp_url(self.container_name,
                                 self.object_name, "GET",
                                 expires, self.key)

        _, body = self.object_client.get_object_using_temp_url(url)
        self.assertEqual(body, new_data)
예제 #16
0
    def test_access_public_object_with_another_user_creds(self):
        # make container public-readable and access an object in it using
        # another user's credentials
        cont_headers = {'X-Container-Read': '.r:*,.rlistings'}
        resp_meta, body = self.container_client.update_container_metadata(
            self.container_name, metadata=cont_headers,
            metadata_prefix='')
        self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)

        # create object
        object_name = rand_name(name='Object')
        data = arbitrary_string(size=len(object_name) * 1,
                                base_text=object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        self.assertEqual(resp['status'], '201')

        # list container metadata
        resp, _ = self.container_client.list_container_metadata(
            self.container_name)
        self.assertIn(int(resp['status']), HTTP_SUCCESS)
        self.assertIn('x-container-read', resp)
        self.assertEqual(resp['x-container-read'], '.r:*,.rlistings')

        # get auth token of alternative user
        token = self.identity_client_alt.get_auth()
        headers = {'X-Auth-Token': token}
        # access object using alternate user creds
        resp, body = self.custom_object_client.get_object(
            self.container_name, object_name,
            metadata=headers)
        self.assertEqual(body, data)
예제 #17
0
    def test_access_public_container_object_without_using_creds(self):
        # make container public-readable and access an object in it object
        # anonymously, without using credentials

        # update container metadata to make it publicly readable
        cont_headers = {'X-Container-Read': '.r:*,.rlistings'}
        resp_meta, body = self.container_client.update_container_metadata(
            self.container_name, metadata=cont_headers, metadata_prefix='')
        self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
        # create object
        object_name = rand_name(name='Object')
        data = arbitrary_string(size=len(object_name),
                                base_text=object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        self.assertEqual(resp['status'], '201')

        # list container metadata
        resp_meta, _ = self.container_client.list_container_metadata(
            self.container_name)
        self.assertIn(int(resp['status']), HTTP_SUCCESS)
        self.assertIn('x-container-read', resp_meta)
        self.assertEqual(resp_meta['x-container-read'], '.r:*,.rlistings')

        # trying to get object with empty headers as it is public readable
        resp, body = self.custom_object_client.get_object(
            self.container_name, object_name, metadata={})
        self.assertEqual(body, data)
예제 #18
0
    def test_object_upload_in_segments(self):
        # create object
        object_name = rand_name(name='LObject')
        data = arbitrary_string()
        segments = 10
        data_segments = [data + str(i) for i in xrange(segments)]
        # uploading segments
        for i in xrange(segments):
            resp, _ = self.object_client.create_object_segments(
                self.container_name, object_name, i, data_segments[i])
            self.assertEqual(resp['status'], '201')
        # creating a manifest file
        metadata = {'X-Object-Manifest': '%s/%s/'
                    % (self.container_name, object_name)}
        self.object_client.create_object(self.container_name,
                                         object_name, data='')
        resp, _ = self.object_client.update_object_metadata(
            self.container_name, object_name, metadata, metadata_prefix='')
        resp, _ = self.object_client.list_object_metadata(
            self.container_name, object_name)
        self.assertIn('x-object-manifest', resp)
        self.assertEqual(resp['x-object-manifest'],
                         '%s/%s/' % (self.container_name, object_name))

        # downloading the object
        resp, body = self.object_client.get_object(
            self.container_name, object_name)
        self.assertEqual(''.join(data_segments), body)
예제 #19
0
    def test_access_public_container_object_without_using_creds(self):
        # make container public-readable and access an object in it object
        # anonymously, without using credentials

        # update container metadata to make it publicly readable
        cont_headers = {"X-Container-Read": ".r:*,.rlistings"}
        resp_meta, body = self.container_client.update_container_metadata(
            self.container_name, metadata=cont_headers, metadata_prefix=""
        )
        self.assertIn(int(resp_meta["status"]), HTTP_SUCCESS)
        self.assertHeaders(resp_meta, "Container", "POST")

        # create object
        object_name = data_utils.rand_name(name="Object")
        data = data_utils.arbitrary_string(size=len(object_name), base_text=object_name)
        resp, _ = self.object_client.create_object(self.container_name, object_name, data)
        self.assertEqual(resp["status"], "201")
        self.assertHeaders(resp, "Object", "PUT")

        # list container metadata
        resp_meta, _ = self.container_client.list_container_metadata(self.container_name)
        self.assertIn(int(resp_meta["status"]), HTTP_SUCCESS)
        self.assertHeaders(resp_meta, "Container", "HEAD")

        self.assertIn("x-container-read", resp_meta)
        self.assertEqual(resp_meta["x-container-read"], ".r:*,.rlistings")

        # trying to get object with empty headers as it is public readable
        resp, body = self.custom_object_client.get_object(self.container_name, object_name, metadata={})
        self.assertHeaders(resp, "Object", "GET")

        self.assertEqual(body, data)
    def test_list_container_contents_json(self):
        # add metadata to an object

        # create a container
        container_name = rand_name(name='TestContainer')
        resp, _ = self.container_client.create_container(container_name)
        self.containers.append(container_name)
        # create object
        object_name = rand_name(name='TestObject')
        data = arbitrary_string()
        resp, _ = self.object_client.create_object(container_name,
                                                   object_name, data)
        # set object metadata
        meta_key = rand_name(name='Meta-Test-')
        meta_value = rand_name(name='MetaValue-')
        orig_metadata = {meta_key: meta_value}
        resp, _ = self.object_client.update_object_metadata(container_name,
                                                            object_name,
                                                            orig_metadata)
        # get container contents list
        params = {'format': 'json'}
        resp, object_list = \
            self.container_client.\
            list_container_contents(container_name, params=params)
        self.assertEqual(resp['status'], '200')
        self.assertIsNotNone(object_list)

        object_names = [obj['name'] for obj in object_list]
        self.assertIn(object_name, object_names)
예제 #21
0
    def test_upload_valid_object(self):
        object_name = data_utils.rand_name(name="TestObject")
        data = data_utils.arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)

        self.assertHeaders(resp, 'Object', 'PUT')
    def test_web_error(self):
        headers = {'web-listings': 'true',
                   'web-error': self.object_name}

        self.container_client.update_container_metadata(
            self.container_name, metadata=headers)

        # Create object to return when requested object not found
        object_name_404 = "404" + self.object_name
        object_data_404 = data_utils.arbitrary_string()
        self.object_client.create_object(self.container_name,
                                         object_name_404,
                                         object_data_404)

        # Do not set auth in HTTP headers for next request
        self.custom_object_client.auth_provider.set_alt_auth_data(
            request_part='headers',
            auth_data=None
        )

        # Request non-existing object
        resp, body = self.custom_object_client.get_object(self.container_name,
                                                          "notexisting")
        self.assertEqual(resp['status'], '404')
        self.assertEqual(body, object_data_404)
예제 #23
0
    def test_get_object_after_expiry_time(self):
        # GET object after expiry time
        #TODO(harika-vakadi): Similar test case has to be created for
        # "X-Delete-At", after this test case works.

        #Create Object
        object_name = rand_name(name='TestObject')
        data = arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)

        #Update object metadata with expiry time of 3 seconds
        metadata = {'X-Delete-After': '3'}
        resp, _ = \
            self.object_client.update_object_metadata(self.container_name,
                                                      object_name, metadata,
                                                      metadata_prefix='')

        resp, _ = \
            self.object_client.list_object_metadata(self.container_name,
                                                    object_name)

        self.assertEqual(resp['status'], '200')
        self.assertIn('x-delete-at', resp)

        resp, body = self.object_client.get_object(self.container_name,
                                                   object_name)
        self.assertEqual(resp['status'], '200')
        # Check data
        self.assertEqual(body, data)
        # Sleep for over 5 seconds, so that object is expired
        sleep(5)
        # Verification of raised exception after object gets expired
        self.assertRaises(exceptions.NotFound, self.object_client.get_object,
                          self.container_name, object_name)
예제 #24
0
    def setUpClass(cls):
        super(ObjectTempUrlTest, cls).setUpClass()

        # skip this test if TempUrl isn't enabled in the conf file.
        if not cls.tempurl_available:
            skip_msg = ("%s skipped as TempUrl middleware not available"
                        % cls.__name__)
            raise cls.skipException(skip_msg)

        # create a container
        cls.container_name = data_utils.rand_name(name='TestContainer')
        cls.container_client.create_container(cls.container_name)
        cls.containers = [cls.container_name]

        # update account metadata
        cls.key = 'Meta'
        cls.metadatas = []
        cls.metadata = {'Temp-URL-Key': cls.key}
        cls.metadatas.append(cls.metadata)
        cls.account_client.create_account_metadata(metadata=cls.metadata)

        # create an object
        cls.object_name = data_utils.rand_name(name='ObjectTemp')
        cls.content = data_utils.arbitrary_string(size=len(cls.object_name),
                                                  base_text=cls.object_name)
        cls.object_client.create_object(cls.container_name,
                                        cls.object_name, cls.content)
예제 #25
0
    def test_put_object_using_temp_url(self):
        new_data = data_utils.arbitrary_string(
            size=len(self.object_name),
            base_text=data_utils.rand_name(name="random"))

        expires = self._get_expiry_date()
        url = self._get_temp_url(self.container_name,
                                 self.object_name, "PUT",
                                 expires, self.key)

        # trying to put random data in the object using temp url
        resp, body = self.object_client.put(url, new_data, None)
        self.assertHeaders(resp, 'Object', 'PUT')

        # Testing a HEAD on this Temp URL
        resp, body = self.object_client.head(url)
        self.assertHeaders(resp, 'Object', 'HEAD')

        # Validate that the content of the object has been modified
        url = self._get_temp_url(self.container_name,
                                 self.object_name, "GET",
                                 expires, self.key)

        _, body = self.object_client.get(url)
        self.assertEqual(body, new_data)
    def test_object_metadata(self):
        # Add metadata to storage object, test if metadata is retrievable

        #Create Object
        object_name = rand_name(name='TestObject')
        data = arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)

        #Set Object Metadata
        meta_key = rand_name(name='test-')
        meta_value = rand_name(name='MetaValue-')
        orig_metadata = {meta_key: meta_value}

        resp, _ = \
            self.object_client.update_object_metadata(self.container_name,
                                                      object_name,
                                                      orig_metadata)
        self.assertEqual(resp['status'], '202')

        #Get Object Metadata
        resp, resp_metadata = \
            self.object_client.list_object_metadata(self.container_name,
                                                    object_name)
        self.assertEqual(resp['status'], '200')
        actual_meta_key = 'x-object-meta-' + meta_key
        self.assertTrue(actual_meta_key in resp)
        self.assertEqual(resp[actual_meta_key], meta_value)
    def test_get_object_after_expiry_time(self):
        # TODO(harika-vakadi): similar test case has to be created for
        # "X-Delete-At", after this test case works.

        # create object
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        # update object metadata with expiry time of 3 seconds
        metadata = {'X-Delete-After': '3'}
        resp, _ = \
            self.object_client.update_object_metadata(self.container_name,
                                                      object_name, metadata,
                                                      metadata_prefix='')
        resp, _ = \
            self.object_client.list_object_metadata(self.container_name,
                                                    object_name)
        self.assertEqual(resp['status'], '200')
        self.assertHeaders(resp, 'Object', 'HEAD')
        self.assertIn('x-delete-at', resp)
        resp, body = self.object_client.get_object(self.container_name,
                                                   object_name)
        self.assertEqual(resp['status'], '200')
        self.assertHeaders(resp, 'Object', 'GET')
        self.assertIn('x-delete-at', resp)
        # check data
        self.assertEqual(body, data)
        # sleep for over 5 seconds, so that object expires
        time.sleep(5)
        # object should not be there anymore
        self.assertRaises(exceptions.NotFound, self.object_client.get_object,
                          self.container_name, object_name)
예제 #28
0
    def test_update_object_metadata_with_create_and_remove_metadata(self):
        # creation and deletion of metadata with one request
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        create_metadata = {'X-Object-Meta-test-meta1': 'Meta1'}
        self.object_client.create_object(self.container_name,
                                         object_name,
                                         data,
                                         metadata=create_metadata)

        update_metadata = {'X-Object-Meta-test-meta2': 'Meta2',
                           'X-Remove-Object-Meta-test-meta1': 'Meta1'}
        resp, _ = self.object_client.update_object_metadata(
            self.container_name,
            object_name,
            update_metadata,
            metadata_prefix='')
        self.assertHeaders(resp, 'Object', 'POST')

        resp, _ = self.object_client.list_object_metadata(
            self.container_name,
            object_name)
        self.assertNotIn('x-object-meta-test-meta1', resp)
        self.assertIn('x-object-meta-test-meta2', resp)
        self.assertEqual(resp['x-object-meta-test-meta2'], 'Meta2')
예제 #29
0
    def test_get_object_if_different(self):
        # http://en.wikipedia.org/wiki/HTTP_ETag
        # Make a conditional request for an object using the If-None-Match
        # header, it should get downloaded only if the local file is different,
        # otherwise the response code should be 304 Not Modified
        object_name = data_utils.rand_name(name="TestObject")
        data = data_utils.arbitrary_string()
        self.object_client.create_object(self.container_name, object_name, data)
        # local copy is identical, no download
        md5 = hashlib.md5(data).hexdigest()
        headers = {"If-None-Match": md5}
        url = "%s/%s" % (self.container_name, object_name)
        resp, _ = self.object_client.get(url, headers=headers)
        self.assertEqual(resp["status"], "304")

        # When the file is not downloaded from Swift server, response does
        # not contain 'X-Timestamp' header. This is the special case, therefore
        # the existence of response headers is checked without custom matcher.
        self.assertIn("content-type", resp)
        self.assertIn("x-trans-id", resp)
        self.assertIn("date", resp)
        self.assertIn("accept-ranges", resp)
        # Check only the format of common headers with custom matcher
        self.assertThat(resp, custom_matchers.AreAllWellFormatted())

        # local copy is different, download
        local_data = "something different"
        md5 = hashlib.md5(local_data).hexdigest()
        headers = {"If-None-Match": md5}
        resp, body = self.object_client.get(url, headers=headers)
        self.assertIn(int(resp["status"]), HTTP_SUCCESS)
        self.assertHeaders(resp, "Object", "GET")
예제 #30
0
    def test_object_upload_in_segments(self):
        #Attempt to upload object in segments

        #Create Object
        object_name = rand_name(name='LObject')
        data = arbitrary_string(size=len(object_name),
                                base_text=object_name)
        segments = 10
        self.object_client.create_object(self.container_name,
                                         object_name, data)
        #Uploading 10 segments
        for i in range(segments):
            resp, _ = self.object_client.create_object_segments(
                self.container_name, object_name,
                i, data)
        # Creating a Manifest File (Metadata Update)

        metadata = {'X-Object-Manifest': '%s/%s/'
                    % (self.container_name, object_name)}
        resp, _ = self.object_client.update_object_metadata(
            self.container_name, object_name,
            metadata, metadata_prefix='')
        resp, _ = self.object_client.list_object_metadata(
            self.container_name, object_name)
        self.assertIn('x-object-manifest', resp)
        self.assertEqual(resp['x-object-manifest'],
                         '%s/%s/' % (self.container_name, object_name))

        #Downloading the object
        resp, body = self.object_client.get_object(
            self.container_name, object_name)

        self.assertEqual(data * segments, body)
예제 #31
0
    def test_access_public_container_object_without_using_creds(self):
        # make container public-readable and access an object in it object
        # anonymously, without using credentials

        # update container metadata to make it publicly readable
        cont_headers = {'X-Container-Read': '.r:*,.rlistings'}
        resp_meta, body = self.container_client.update_container_metadata(
            self.container_name, metadata=cont_headers, metadata_prefix='')
        self.assertHeaders(resp_meta, 'Container', 'POST')

        # create object
        object_name = data_utils.rand_name(name='Object')
        data = data_utils.arbitrary_string(size=len(object_name),
                                           base_text=object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        self.assertHeaders(resp, 'Object', 'PUT')

        # list container metadata
        resp_meta, _ = self.container_client.list_container_metadata(
            self.container_name)
        self.assertHeaders(resp_meta, 'Container', 'HEAD')

        self.assertIn('x-container-read', resp_meta)
        #Bug = 1417498
        #self.assertEqual(resp_meta['x-container-read'], '.r:*,.rlistings')
        self.assertEqual(resp_meta['x-container-read'], '.r:*')

        # trying to get object with empty headers as it is public readable
        self.object_client.auth_provider.set_alt_auth_data(
            request_part='headers',
            auth_data=None
        )
        resp, body = self.object_client.get_object(
            self.container_name, object_name)
        self.assertHeaders(resp, 'Object', 'GET')

        self.assertEqual(body, data)
예제 #32
0
    def test_copy_object_across_containers(self):
        # create a container to use as a source container
        src_container_name = data_utils.rand_name(name='TestSourceContainer')
        self.container_client.create_container(src_container_name)
        self.containers.append(src_container_name)
        # create a container to use as a destination container
        dst_container_name = data_utils.rand_name(
            name='TestDestinationContainer')
        self.container_client.create_container(dst_container_name)
        self.containers.append(dst_container_name)
        # create object in source container
        object_name = data_utils.rand_name(name='Object')
        data = data_utils.arbitrary_string(size=len(object_name) * 2,
                                           base_text=object_name)
        resp, _ = self.object_client.create_object(src_container_name,
                                                   object_name, data)
        # set object metadata
        meta_key = data_utils.rand_name(name='test')
        meta_value = data_utils.rand_name(name='MetaValue')
        orig_metadata = {meta_key: meta_value}
        resp, _ = self.object_client.update_object_metadata(src_container_name,
                                                            object_name,
                                                            orig_metadata)
        self.assertHeaders(resp, 'Object', 'POST')

        # copy object from source container to destination container
        resp, _ = self.object_client.copy_object_across_containers(
            src_container_name, object_name, dst_container_name,
            object_name)
        self.assertHeaders(resp, 'Object', 'PUT')

        # check if object is present in destination container
        resp, body = self.object_client.get_object(dst_container_name,
                                                   object_name)
        self.assertEqual(body, data)
        actual_meta_key = 'x-object-meta-' + meta_key
        self.assertIn(actual_meta_key, resp)
        self.assertEqual(resp[actual_meta_key], meta_value)
예제 #33
0
    def _create_manifest(self):
        # Create a manifest file for SLO uploading
        object_name = data_utils.rand_name(name='TestObject')
        object_name_base_1 = object_name + '_01'
        object_name_base_2 = object_name + '_02'
        data_size = MIN_SEGMENT_SIZE
        self.data = data_utils.arbitrary_string(data_size)
        self._create_object(self.container_name, object_name_base_1, self.data)
        self._create_object(self.container_name, object_name_base_2, self.data)

        path_object_1 = '/%s/%s' % (self.container_name, object_name_base_1)
        path_object_2 = '/%s/%s' % (self.container_name, object_name_base_2)
        data_manifest = [{
            'path': path_object_1,
            'etag': hashlib.md5(self.data).hexdigest(),
            'size_bytes': data_size
        }, {
            'path': path_object_2,
            'etag': hashlib.md5(self.data).hexdigest(),
            'size_bytes': data_size
        }]

        return json.dumps(data_manifest)
예제 #34
0
    def test_put_object_using_temp_url(self):
        new_data = data_utils.arbitrary_string(
            size=len(self.object_name),
            base_text=data_utils.rand_name(name="random"))

        expires = self._get_expiry_date()
        url = self._get_temp_url(self.container_name, self.object_name, "PUT",
                                 expires, self.key)

        # trying to put random data in the object using temp url
        resp, body = self.object_client.put(url, new_data, None)
        self.assertHeaders(resp, 'Object', 'PUT')

        # Testing a HEAD on this Temp URL
        resp, body = self.object_client.head(url)
        self.assertHeaders(resp, 'Object', 'HEAD')

        # Validate that the content of the object has been modified
        url = self._get_temp_url(self.container_name, self.object_name, "GET",
                                 expires, self.key)

        _, body = self.object_client.get(url)
        self.assertEqual(body, new_data)
    def test_update_object_metadata_with_x_remove_object_metakey(self):
        # update object metadata with a blank value of remove metadata
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        create_metadata = {'X-Object-Meta-test-meta': 'Meta'}
        self.object_client.create_object(self.container_name,
                                         object_name,
                                         data,
                                         metadata=create_metadata)

        update_metadata = {'X-Remove-Object-Meta-test-meta': ''}
        resp, _ = self.object_client.update_object_metadata(
            self.container_name,
            object_name,
            update_metadata,
            metadata_prefix='')
        self.assertIn(int(resp['status']), test.HTTP_SUCCESS)
        self.assertHeaders(resp, 'Object', 'POST')

        resp, _ = self.object_client.list_object_metadata(
            self.container_name,
            object_name)
        self.assertNotIn('x-object-meta-test-meta', resp)
예제 #36
0
    def test_object_metadata(self):
        # add metadata to storage object, test if metadata is retrievable

        # create Object
        object_name = rand_name(name='TestObject')
        data = arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        # set object metadata
        meta_key = rand_name(name='test-')
        meta_value = rand_name(name='MetaValue-')
        orig_metadata = {meta_key: meta_value}
        resp, _ = self.object_client.update_object_metadata(
            self.container_name, object_name, orig_metadata)
        self.assertIn(int(resp['status']), HTTP_SUCCESS)

        # get object metadata
        resp, resp_metadata = self.object_client.list_object_metadata(
            self.container_name, object_name)
        self.assertIn(int(resp['status']), HTTP_SUCCESS)
        actual_meta_key = 'x-object-meta-' + meta_key
        self.assertTrue(actual_meta_key in resp)
        self.assertEqual(resp[actual_meta_key], meta_value)
예제 #37
0
    def test_copy_object_to_itself(self):
        """Change the content type of an existing object"""

        # Create Object
        object_name = rand_name(name='TestObject')
        data = arbitrary_string()
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        # Get the old content type
        resp_tmp, _ = self.object_client.list_object_metadata(
            self.container_name, object_name)
        # Change the content type of the object
        metadata = {'content-type': 'text/plain; charset=UTF-8'}
        self.assertNotEqual(resp_tmp['content-type'], metadata['content-type'])
        resp, _ = self.object_client.copy_object(self.container_name,
                                                 object_name, object_name,
                                                 metadata)
        self.assertEqual(resp['status'], '201')

        # Check the content type
        resp, _ = self.object_client.list_object_metadata(
            self.container_name, object_name)
        self.assertEqual(resp['content-type'], metadata['content-type'])
예제 #38
0
    def test_copy_object_to_itself(self):
        # change the content type of an existing object

        # create object
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        self.object_client.create_object(self.container_name, object_name,
                                         data)
        # get the old content type
        resp_tmp, _ = self.object_client.list_object_metadata(
            self.container_name, object_name)
        # change the content type of the object
        metadata = {'content-type': 'text/plain; charset=UTF-8'}
        self.assertNotEqual(resp_tmp['content-type'], metadata['content-type'])
        resp, _ = self.object_client.copy_object_in_same_container(
            self.container_name, object_name, object_name, metadata)
        self.assertEqual(resp['status'], '201')
        self.assertHeaders(resp, 'Object', 'PUT')

        # check the content type
        resp, _ = self.object_client.list_object_metadata(
            self.container_name, object_name)
        self.assertEqual(resp['content-type'], metadata['content-type'])
예제 #39
0
    def test_access_public_object_with_another_user_creds(self):
        # make container public-readable and access an object in it using
        # another user's credentials
        cont_headers = {'X-Container-Read': '.r:*,.rlistings'}
        resp_meta, body = self.container_client.update_container_metadata(
            self.container_name, metadata=cont_headers, metadata_prefix='')
        self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
        self.assertHeaders(resp_meta, 'Container', 'POST')

        # create object
        object_name = data_utils.rand_name(name='Object')
        data = data_utils.arbitrary_string(size=len(object_name) * 1,
                                           base_text=object_name)
        resp, _ = self.object_client.create_object(self.container_name,
                                                   object_name, data)
        self.assertEqual(resp['status'], '201')
        self.assertHeaders(resp, 'Object', 'PUT')

        # list container metadata
        resp, _ = self.container_client.list_container_metadata(
            self.container_name)
        self.assertIn(int(resp['status']), HTTP_SUCCESS)
        self.assertHeaders(resp, 'Container', 'HEAD')

        self.assertIn('x-container-read', resp)
        self.assertEqual(resp['x-container-read'], '.r:*,.rlistings')

        # get auth token of alternative user
        alt_auth_data = self.identity_client_alt.auth_provider.auth_data
        self.custom_object_client.auth_provider.set_alt_auth_data(
            request_part='headers', auth_data=alt_auth_data)
        # access object using alternate user creds
        resp, body = self.custom_object_client.get_object(
            self.container_name, object_name)
        self.assertHeaders(resp, 'Object', 'GET')

        self.assertEqual(body, data)
예제 #40
0
    def test_create_object_with_expect_continue(self):
        # create object with expect_continue
        object_name = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        metadata = {'Expect': '100-continue'}
        resp = self.object_client.create_object_continue(
            self.container_name,
            object_name,
            data,
            metadata=metadata)

        self.assertIn('status', resp)
        self.assertEqual(resp['status'], '100')

        self.object_client.create_object_continue(
            self.container_name,
            object_name,
            data,
            metadata=None)

        # check uploaded content
        _, body = self.object_client.get_object(self.container_name,
                                                object_name)
        self.assertEqual(data, body)
예제 #41
0
    def test_get_object_using_temp_url(self):
        # access object using temporary URL within expiration time

        try:
            # update account metadata
            # flag to check if account metadata got updated
            flag = False
            key = 'Meta'
            metadata = {'Temp-URL-Key': key}
            resp, _ = self.account_client.create_account_metadata(
                metadata=metadata)
            self.assertIn(int(resp['status']), HTTP_SUCCESS)
            flag = True
            resp, _ = self.account_client.list_account_metadata()
            self.assertIn('x-account-meta-temp-url-key', resp)
            self.assertEqual(resp['x-account-meta-temp-url-key'], key)

            # create object
            object_name = rand_name(name='ObjectTemp')
            data = arbitrary_string(size=len(object_name),
                                    base_text=object_name)
            self.object_client.create_object(self.container_name,
                                             object_name, data)
            expires = int(time.time() + 10)

            # trying to get object using temp url with in expiry time
            _, body = self.object_client.get_object_using_temp_url(
                self.container_name, object_name,
                expires, key)
            self.assertEqual(body, data)
        finally:
            if flag:
                resp, _ = self.account_client.delete_account_metadata(
                    metadata=metadata)
                resp, _ = self.account_client.list_account_metadata()
                self.assertNotIn('x-account-meta-temp-url-key', resp)
예제 #42
0
    def test_access_public_object_with_another_user_creds(self):
        # make container public-readable and access an object in it using
        # another user's credentials
        try:
            cont_headers = {'X-Container-Read': '.r:*,.rlistings'}
            resp_meta, body = self.container_client.update_container_metadata(
                self.container_name, metadata=cont_headers,
                metadata_prefix='')
            self.assertIn(int(resp_meta['status']), HTTP_SUCCESS)
            # create object
            object_name = rand_name(name='Object')
            data = arbitrary_string(size=len(object_name) * 1,
                                    base_text=object_name)
            resp, _ = self.object_client.create_object(self.container_name,
                                                       object_name, data)
            self.assertEqual(resp['status'], '201')

            # list container metadata
            resp, _ = self.container_client.list_container_metadata(
                self.container_name)
            self.assertIn(int(resp['status']), HTTP_SUCCESS)
            self.assertIn('x-container-read', resp)
            self.assertEqual(resp['x-container-read'], '.r:*,.rlistings')

            # get auth token of alternative user
            token = self.identity_client_alt.get_auth()
            headers = {'X-Auth-Token': token}
            # access object using alternate user creds
            resp, body = self.custom_object_client.get_object(
                self.container_name, object_name,
                metadata=headers)
            self.assertEqual(body, data)

        except Exception as e:
            self.fail("Failed to get public readable object with another"
                      " user creds raised exception is %s" % e)
    def test_web_error(self):
        headers = {'web-listings': 'true',
                   'web-error': self.object_name}

        self.container_client.update_container_metadata(
            self.container_name, metadata=headers)

        # Create object to return when requested object not found
        object_name_404 = "404" + self.object_name
        object_data_404 = data_utils.arbitrary_string()
        self.object_client.create_object(self.container_name,
                                         object_name_404,
                                         object_data_404)

        # Do not set auth in HTTP headers for next request
        self.object_client.auth_provider.set_alt_auth_data(
            request_part='headers',
            auth_data=None
        )

        # Request non-existing object
        self.assertRaises(
            lib_exc.NotFound, self.object_client.get_object,
            self.container_name, "notexisting")
예제 #44
0
    def test_create_object_with_x_fresh_metadata(self):
        # create object with x_fresh_metadata
        object_name_base = data_utils.rand_name(name='TestObject')
        data = data_utils.arbitrary_string()
        metadata_1 = {'X-Object-Meta-test-meta': 'Meta'}
        self.object_client.create_object(self.container_name,
                                         object_name_base,
                                         data,
                                         metadata=metadata_1)
        object_name = data_utils.rand_name(name='TestObject')
        metadata_2 = {'X-Copy-From': '%s/%s' % (self.container_name,
                                                object_name_base),
                      'X-Fresh-Metadata': 'true'}
        resp, _ = self.object_client.create_object(
            self.container_name,
            object_name,
            '',
            metadata=metadata_2)
        self.assertHeaders(resp, 'Object', 'PUT')

        resp, body = self.object_client.get_object(self.container_name,
                                                   object_name)
        self.assertNotIn('x-object-meta-test-meta', resp)
        self.assertEqual(data, body)
예제 #45
0
 def test_upload_large_object(self):
     object_name = data_utils.rand_name(name="TestObject")
     data = data_utils.arbitrary_string(30)
     self.assertRaises(exceptions.OverLimit,
                       self.object_client.create_object,
                       self.container_name, object_name, data)