def test_uploadFile_with_metadata(self):
     client_type, uploadClient, downloadClient = self.get_client()
     object_name = "test_uploadFile_with_metadata"
     conftest.gen_random_file(object_name, 1024)
     metadata = {
         "content_type": "text/plain",
         "expires": 1,
         "meta_key1": "value1",
         "meta_key-2": "value-2"
     }
     upload_result = uploadClient.uploadFile(test_config["bucketName"],
                                             object_name,
                                             test_config["path_prefix"] +
                                             object_name,
                                             metadata=metadata,
                                             checkSum=True,
                                             taskNum=10)
     assert upload_result.status == 200
     object_metadata = uploadClient.getObjectMetadata(
         test_config["bucketName"], object_name)
     meta_dict = dict(object_metadata.header)
     assert meta_dict["content_type"] == "text/plain"
     assert meta_dict["expires"] == '1'
     assert meta_dict["meta_key1"] == "value1"
     assert meta_dict["meta_key-2"] == "value-2"
 def test_uploadFile_with_storage_type(self):
     client_type, uploadClient, downloadClient = self.get_client()
     object_name = "test_uploadFile_with_storage_type"
     conftest.gen_random_file(object_name, 1024)
     for i in ["WARM", "COLD"]:
         upload_header = UploadFileHeader()
         upload_header.storageClass = i
         upload_result = uploadClient.uploadFile(
             test_config["bucketName"],
             object_name,
             test_config["path_prefix"] + object_name,
             headers=upload_header,
             checkSum=True,
             taskNum=10)
         assert upload_result.status == 200
         object_metadata = uploadClient.getObjectMetadata(
             test_config["bucketName"], object_name)
         if i == "WARM":
             assert dict(
                 object_metadata.header)["storage-class"] in (i,
                                                              "STANDARD_IA")
         else:
             assert dict(
                 object_metadata.header)["storage-class"] in (i, "GLACIER")
         uploadClient.deleteObject(test_config["bucketName"], object_name)
     os.remove(test_config["path_prefix"] + object_name)
    def test_downloadFile_part_num_more_than_10000(self):
        conftest.gen_random_file("test_downloadFile_part_num_more_than_10000",
                                 1024 * 1024)
        client_type, uploadClient, downloadClient = self.get_client()
        object_name = "test_downloadFile_part_num_more_than_10000"
        upload_result = uploadClient.uploadFile(test_config["bucketName"],
                                                object_name,
                                                test_config["path_prefix"] +
                                                object_name,
                                                taskNum=50)
        assert upload_result.status == 200

        download_result = downloadClient.downloadFile(
            test_config["bucketName"],
            object_name,
            test_config["path_prefix"] +
            "test_downloadFile_part_num_more_than_10000_download",
            taskNum=50)
        assert download_result.status == 200
        assert conftest.compare_sha256(
            test_config["path_prefix"] + object_name,
            test_config["path_prefix"] +
            "test_downloadFile_part_num_more_than_10000_download")
        uploadClient.deleteObject(test_config["bucketName"], object_name)
        os.remove(test_config["path_prefix"] + object_name)
        os.remove(test_config["path_prefix"] +
                  "test_downloadFile_part_num_more_than_10000_download")
 def test_uploadFile_with_checksum(self):
     conftest.gen_random_file("test_uploadFile_with_checksum", 1024 * 1024)
     client_type, uploadClient, downloadClient = self.get_client()
     object_name = "test_uploadFile_with_checksum"
     upload_result = uploadClient.uploadFile(test_config["bucketName"],
                                             object_name,
                                             test_config["path_prefix"] +
                                             object_name,
                                             checkSum=True,
                                             taskNum=50,
                                             partSize=1024 * 1024)
     assert upload_result.status == 200
     object_metadata = uploadClient.getObjectMetadata(
         test_config["bucketName"], object_name)
     assert dict(object_metadata.header)["etag"].endswith("-1024\"")
     uploadClient.deleteObject(test_config["bucketName"], object_name)
     os.remove(test_config["path_prefix"] + object_name)
示例#5
0
    def test_putFile_has_sha256(self):
        client_type, uploadClient, downloadClient = self.get_client()
        object_key = "test_putFile_has_sha256"
        gen_random_file(object_key, 10240)
        upload_result = uploadClient.putFile(
            test_config["bucketName"], object_key,
            test_config["path_prefix"] + object_key)
        assert upload_result.status == 200
        sha256 = hashlib.sha256()
        with open(test_config["path_prefix"] + object_key) as f:
            while True:
                chunk = f.read(65536)
                if not chunk:
                    break
                sha256.update(chunk)

        metadata = uploadClient.getObjectMetadata(test_config["bucketName"],
                                                  object_key)
        assert metadata.status == 200
        metadata_dict = dict(metadata.header)
        assert metadata_dict["plaintext-sha256"] == sha256.hexdigest()
        assert "encrypted-start" in metadata_dict
        uploadClient.deleteObject(test_config["bucketName"], object_key)
        os.remove(test_config["path_prefix"] + object_key)
示例#6
0
    def test_initiateEncryptedMultipartUpload_and_uploadEncryptedPart(self):
        client_type, uploadClient, downloadClient = self.get_client()
        object_name = client_type + "test_initiateEncryptedMultipartUpload"
        test_bytes = io.BytesIO(b"test_initiateEncryptedMultipartUpload")
        cipher = uploadClient.cipher_generator.new(test_bytes)
        init_result = uploadClient.initiateEncryptedMultipartUpload(
            test_config["bucketName"], object_name, cipher)
        assert init_result.status == 200
        assert "uploadId" in init_result.body
        gen_random_file(object_name, 10240)
        uploaded_parts = []
        upload_result = uploadClient.uploadEncryptedPart(
            test_config["bucketName"],
            object_name,
            1,
            init_result.body["uploadId"],
            crypto_cipher=cipher,
            object=test_config["path_prefix"] + object_name,
            isFile=True)
        assert upload_result.status == 200
        uploaded_parts.append(
            CompletePart(partNum=1,
                         etag=dict(upload_result.header).get('etag')))
        upload_result = uploadClient.uploadEncryptedPart(
            test_config["bucketName"],
            object_name,
            2,
            init_result.body["uploadId"],
            crypto_cipher=cipher,
            object=open(test_config["path_prefix"] + object_name, "rb"))
        assert upload_result.status == 200

        uploaded_parts.append(
            CompletePart(partNum=2,
                         etag=dict(upload_result.header).get('etag')))
        upload_result = uploadClient.uploadEncryptedPart(
            test_config["bucketName"],
            object_name,
            3,
            init_result.body["uploadId"],
            crypto_cipher=cipher,
            object="test obs")
        assert upload_result.status == 200

        uploaded_parts.append(
            CompletePart(partNum=3,
                         etag=dict(upload_result.header).get('etag')))
        complete_result = uploadClient.completeMultipartUpload(
            test_config["bucketName"], object_name,
            init_result.body["uploadId"],
            CompleteMultipartUploadRequest(uploaded_parts))
        assert complete_result.status == 200

        download_result = downloadClient.getObject(test_config["bucketName"],
                                                   object_name,
                                                   loadStreamInMemory=True)
        assert download_result.status == 200
        download_sha256 = hashlib.sha256()
        download_sha256.update(download_result.body.buffer)
        local_sha256 = hashlib.sha256()
        with open(test_config["path_prefix"] + object_name, "rb") as f:
            local_sha256.update(f.read())
            f.seek(0)
            local_sha256.update(f.read())
        local_sha256.update("test obs".encode("UTF-8"))
        assert local_sha256.hexdigest() == download_sha256.hexdigest()

        uploadClient.deleteObject(test_config["bucketName"], object_name)
        os.remove(test_config["path_prefix"] + object_name)