async def test_full_backup_and_restore(self, container_uri, sas_token):
        # backup the vault
        backup_client = KeyVaultBackupClient(self.managed_hsm["url"],
                                             self.credential)
        backup_poller = await backup_client.begin_backup(
            container_uri, sas_token)

        # check backup status and result
        job_id = backup_poller.polling_method().resource().job_id
        backup_status = await backup_client.get_backup_status(job_id)
        assert_in_progress_operation(backup_status)
        backup_operation = await backup_poller.result()
        assert_successful_operation(backup_operation)
        backup_status = await backup_client.get_backup_status(job_id)
        assert_successful_operation(backup_status)

        # restore the backup
        restore_poller = await backup_client.begin_restore(
            backup_status.folder_url, sas_token)

        # check restore status and result
        job_id = restore_poller.polling_method().resource().job_id
        restore_status = await backup_client.get_restore_status(job_id)
        assert_in_progress_operation(restore_status)
        restore_operation = await restore_poller.result()
        assert_successful_operation(restore_operation)
        restore_status = await backup_client.get_restore_status(job_id)
        assert_successful_operation(restore_status)
Exemplo n.º 2
0
    async def test_full_backup_and_restore(self, container_uri, sas_token):
        # backup the vault
        backup_client = KeyVaultBackupClient(self.managed_hsm["url"],
                                             self.credential)
        backup_poller = await backup_client.begin_full_backup(
            container_uri, sas_token)
        backup_operation = await backup_poller.result()
        assert_successful_operation(backup_operation)

        # restore the backup
        folder_name = backup_operation.azure_storage_blob_container_uri.split(
            "/")[-1]
        restore_poller = await backup_client.begin_full_restore(
            container_uri, sas_token, folder_name)
        restore_operation = await restore_poller.result()
        assert_successful_operation(restore_operation)
Exemplo n.º 3
0
    async def test_selective_key_restore(self, container_uri, sas_token):
        # create a key to selectively restore
        key_client = KeyClient(self.managed_hsm["url"], self.credential)
        key_name = self.get_resource_name("selective-restore-test-key")
        await key_client.create_rsa_key(key_name)

        # backup the vault
        backup_client = KeyVaultBackupClient(self.managed_hsm["url"],
                                             self.credential)
        backup_poller = await backup_client.begin_full_backup(
            container_uri, sas_token)
        backup_operation = await backup_poller.result()
        assert_successful_operation(backup_operation)

        # restore the key
        folder_name = backup_operation.azure_storage_blob_container_uri.split(
            "/")[-1]
        restore_poller = await backup_client.begin_selective_restore(
            container_uri, sas_token, folder_name, key_name)
        restore_operation = await restore_poller.result()
        assert_successful_operation(restore_operation)

        await key_client.delete_key(key_name)
        await key_client.purge_deleted_key(key_name)
    async def test_selective_key_restore(self, container_uri, sas_token):
        # create a key to selectively restore
        key_client = KeyClient(self.managed_hsm["url"], self.credential)
        key_name = self.get_resource_name("selective-restore-test-key")
        await key_client.create_rsa_key(key_name)

        # backup the vault
        backup_client = KeyVaultBackupClient(self.managed_hsm["url"],
                                             self.credential)
        backup_poller = await backup_client.begin_full_backup(
            container_uri, sas_token)

        # check backup status and result
        job_id = backup_poller.polling_method().resource().id
        backup_status = await backup_client.get_backup_status(job_id)
        assert_in_progress_operation(backup_status)
        backup_operation = await backup_poller.result()
        assert_successful_operation(backup_operation)
        backup_status = await backup_client.get_backup_status(job_id)
        assert_successful_operation(backup_status)

        # restore the key
        folder_name = backup_operation.azure_storage_blob_container_uri.split(
            "/")[-1]
        restore_poller = await backup_client.begin_selective_restore(
            container_uri, sas_token, folder_name, key_name)

        # check restore status and result
        job_id = restore_poller.polling_method().resource().id
        restore_status = await backup_client.get_restore_status(job_id)
        assert_in_progress_operation(restore_status)
        restore_operation = await restore_poller.result()
        assert_successful_operation(restore_operation)
        restore_status = await backup_client.get_restore_status(job_id)
        assert_successful_operation(restore_status)

        # delete the key
        await self._poll_until_no_exception(
            key_client.delete_key,
            key_name,
            expected_exception=ResourceExistsError)
        await key_client.purge_deleted_key(key_name)