Ejemplo n.º 1
0
    async def _test_shared_access_share_async(self):
        # SAS URL is calculated from storage key, so this test runs live only
        if TestMode.need_recording_file(self.test_mode):
            return

        # Arrange
        file_name = 'file1'
        dir_name = 'dir1'
        data = b'hello world'

        share = await self._create_share()
        dir1 = await share.create_directory(dir_name)
        await dir1.upload_file(file_name, data)

        token = generate_share_sas(
            share.account_name,
            share.share_name,
            share.credential.account_key,
            expiry=datetime.utcnow() + timedelta(hours=1),
            permission=ShareSasPermissions(read=True),
        )
        sas_client = ShareFileClient(
            self.get_file_url(),
            share_name=share.share_name,
            file_path=dir_name + '/' + file_name,
            credential=token,
        )

        # Act
        response = requests.get(sas_client.url)

        # Assert
        self.assertTrue(response.ok)
        self.assertEqual(data, response.content)
    def test_rename_directory_share_sas(self, storage_account_name,
                                        storage_account_key):
        self._setup(storage_account_name, storage_account_key)
        share_client = self.fsc.get_share_client(self.share_name)

        token = generate_share_sas(share_client.account_name,
                                   share_client.share_name,
                                   share_client.credential.account_key,
                                   expiry=datetime.utcnow() +
                                   timedelta(hours=1),
                                   permission=ShareSasPermissions(read=True,
                                                                  write=True))

        source_directory = ShareDirectoryClient(self.account_url(
            storage_account_name, 'file'),
                                                share_client.share_name,
                                                'dir1',
                                                credential=token)
        source_directory.create_directory()

        # Act
        new_directory = source_directory.rename_directory('dir2' + '?' + token)

        # Assert
        props = new_directory.get_directory_properties()
        self.assertIsNotNone(props)
    async def test_shared_access_share_async(self, resource_group, location, storage_account, storage_account_key):
        # SAS URL is calculated from storage key, so this test runs live only
        if not self.is_live:
            return

        self._setup(storage_account, storage_account_key)
        file_name = 'file1'
        dir_name = 'dir1'
        data = b'hello world'

        share = await self._create_share()
        dir1 = await share.create_directory(dir_name)
        await dir1.upload_file(file_name, data)

        token = generate_share_sas(
            share.account_name,
            share.share_name,
            share.credential.account_key,
            expiry=datetime.utcnow() + timedelta(hours=1),
            permission=ShareSasPermissions(read=True),
        )
        sas_client = ShareFileClient(
            self.get_file_url(storage_account.name),
            share_name=share.share_name,
            file_path=dir_name + '/' + file_name,
            credential=token,
        )

        # Act
        response = requests.get(sas_client.url)

        # Assert
        self.assertTrue(response.ok)
        self.assertEqual(data, response.content)
        await self._delete_shares(share.share_name)