def test_sas_signed_identifier(self): # SAS URL is calculated from storage key, so this test runs live only if TestMode.need_recording_file(self.test_mode): return # Arrange blob_name = self._create_block_blob() access_policy = AccessPolicy() access_policy.start = '2011-10-11' access_policy.expiry = '2018-10-12' access_policy.permission = BlobPermissions.READ identifiers = {'testid': access_policy} resp = self.bs.set_container_acl(self.container_name, identifiers) token = self.bs.generate_blob_shared_access_signature( self.container_name, blob_name, id='testid') # Act service = BlockBlobService( self.settings.STORAGE_ACCOUNT_NAME, sas_token=token, request_session=requests.Session(), ) self._set_test_proxy(service, self.settings) result = service.get_blob_to_bytes(self.container_name, blob_name) # Assert self.assertEqual(self.byte_data, result.content)
def test_sas_signed_identifier(self): # SAS URL is calculated from storage key, so this test runs live only if TestMode.need_recording_file(self.test_mode): return # Arrange blob_name = self._create_block_blob() access_policy = AccessPolicy() access_policy.start = '2011-10-11' access_policy.expiry = '2018-10-12' access_policy.permission = BlobPermissions.READ identifiers = {'testid': access_policy} resp = self.bs.set_container_acl(self.container_name, identifiers) token = self.bs.generate_blob_shared_access_signature( self.container_name, blob_name, id='testid' ) # Act service = BlockBlobService( self.settings.STORAGE_ACCOUNT_NAME, sas_token=token, request_session=requests.Session(), ) self._set_test_proxy(service, self.settings) result = service.get_blob_to_bytes(self.container_name, blob_name) # Assert self.assertEqual(self.byte_data, result.content)
def test_sas_signed_identifier(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 = self._create_file() access_policy = AccessPolicy() access_policy.start = datetime.utcnow() - timedelta(hours=1) access_policy.expiry = datetime.utcnow() + timedelta(hours=1) access_policy.permission = FilePermissions.READ identifiers = {'testid': access_policy} resp = self.fs.set_share_acl(self.share_name, identifiers) token = self.fs.generate_file_shared_access_signature(self.share_name, None, file_name, id='testid') # Act service = FileService( self.settings.STORAGE_ACCOUNT_NAME, sas_token=token, request_session=requests.Session(), ) self._set_test_proxy(service, self.settings) result = service.get_file_to_bytes(self.share_name, None, file_name) # Assert self.assertEqual(self.short_byte_data, result.content)
def test_sas_signed_identifier(self): # SAS URL is calculated from storage key, so this test runs live only if TestMode.need_recording_file(self.test_mode): return # Arrange entity = self._insert_random_entity() access_policy = AccessPolicy() access_policy.start = '2011-10-11' access_policy.expiry = '2018-10-12' access_policy.permission = TablePermissions.QUERY identifiers = {'testid': access_policy} entities = self.ts.set_table_acl(self.table_name, identifiers) token = self.ts.generate_table_shared_access_signature( self.table_name, id='testid', ) # Act service = TableService( account_name=self.settings.STORAGE_ACCOUNT_NAME, sas_token=token, ) self._set_test_proxy(service, self.settings) entities = list( self.ts.query_entities(self.table_name, filter="PartitionKey eq '{}'".format( entity.PartitionKey))) # Assert self.assertEqual(len(entities), 1) self._assert_default_entity(entities[0])
def test_sas_signed_identifier(self): # SAS URL is calculated from storage key, so this test runs live only if TestMode.need_recording_file(self.test_mode): return # Arrange access_policy = AccessPolicy() access_policy.start = '2011-10-11' access_policy.expiry = '2018-10-12' access_policy.permission = QueuePermissions.READ identifiers = {'testid': access_policy} queue_name = self._create_queue() resp = self.qs.set_queue_acl(queue_name, identifiers) self.qs.put_message(queue_name, u'message1') token = self.qs.generate_queue_shared_access_signature( queue_name, id='testid' ) # Act service = QueueService( account_name=self.settings.STORAGE_ACCOUNT_NAME, sas_token=token, ) self._set_test_proxy(service, self.settings) result = service.peek_messages(queue_name) # Assert self.assertIsNotNone(result) self.assertEqual(1, len(result)) message = result[0] self.assertIsNotNone(message) self.assertNotEqual('', message.id) self.assertEqual(u'message1', message.content)