Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage]Fix a permission bug and add enable test for list blob with metadata #13260

Merged
merged 4 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ def get_blob_properties(self, **kwargs):
except StorageErrorException as error:
process_storage_error(error)
blob_props.name = self.blob_name
blob_props.snapshot = self.snapshot
blob_props.container = self.container_name
return blob_props # type: ignore

Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azure-storage-blob/azure/storage/blob/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ def from_string(cls, permission):
p_tag = 't' in permission
parsed = cls(read=p_read, write=p_write, delete=p_delete, list=p_list,
delete_previous_version=p_delete_previous_version, tag=p_tag)
parsed._str = permission # pylint: disable = protected-access

return parsed


Expand Down Expand Up @@ -996,7 +996,7 @@ def from_string(cls, permission):

parsed = cls(read=p_read, add=p_add, create=p_create, write=p_write, delete=p_delete,
delete_previous_version=p_delete_previous_version, tag=p_tag)
parsed._str = permission # pylint: disable = protected-access

return parsed


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def from_string(cls, permission):
parsed = cls(read=p_read, write=p_write, delete=p_delete, delete_previous_version=p_delete_previous_version,
list=p_list, add=p_add, create=p_create, update=p_update, process=p_process, tag=p_tag,
filter_by_tags=p_filter_by_tags)
parsed._str = permission # pylint: disable = protected-access

return parsed

class Services(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ async def get_blob_properties(self, **kwargs):
except StorageErrorException as error:
process_storage_error(error)
blob_props.name = self.blob_name
blob_props.snapshot = self.snapshot
blob_props.container = self.container_name
return blob_props # type: ignore

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '0'
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Fri, 21 Aug 2020 08:34:52 GMT
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/container3851155b?restype=container
response:
body:
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>ContainerAlreadyExists</Code><Message>The
specified container already exists.\nRequestId:4d6b1fbe-501e-0079-7c95-77b184000000\nTime:2020-08-21T08:34:52.7820585Z</Message></Error>"
headers:
content-length:
- '230'
content-type:
- application/xml
date:
- Fri, 21 Aug 2020 08:34:52 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-error-code:
- ContainerAlreadyExists
x-ms-version:
- '2019-12-12'
status:
code: 409
message: The specified container already exists.
- request:
body: hello world
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '11'
Content-Type:
- application/octet-stream
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-blob-content-disposition:
- inline
x-ms-blob-content-language:
- spanish
x-ms-blob-type:
- BlockBlob
x-ms-date:
- Fri, 21 Aug 2020 08:34:52 GMT
x-ms-meta-name:
- bob
x-ms-meta-number:
- '1'
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/container3851155b/blob1
response:
body:
string: ''
headers:
content-length:
- '0'
content-md5:
- XrY7u+Ae7tCTyyK7j1rNww==
date:
- Fri, 21 Aug 2020 08:34:52 GMT
etag:
- '"0x8D845AD135C55E0"'
last-modified:
- Fri, 21 Aug 2020 08:34:52 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-content-crc64:
- vo7q9sPVKY0=
x-ms-request-server-encrypted:
- 'true'
x-ms-version:
- '2019-12-12'
x-ms-version-id:
- '2020-08-21T08:34:52.9412336Z'
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '0'
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Fri, 21 Aug 2020 08:34:53 GMT
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/container3851155b/blob1?comp=snapshot
response:
body:
string: ''
headers:
content-length:
- '0'
date:
- Fri, 21 Aug 2020 08:34:52 GMT
etag:
- '"0x8D845AD135C55E0"'
last-modified:
- Fri, 21 Aug 2020 08:34:52 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-server-encrypted:
- 'false'
x-ms-snapshot:
- '2020-08-21T08:34:53.0423049Z'
x-ms-version:
- '2019-12-12'
x-ms-version-id:
- '2020-08-21T08:34:53.0433049Z'
status:
code: 201
message: Created
- request:
body: hello world
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '11'
Content-Type:
- application/octet-stream
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-blob-content-disposition:
- inline
x-ms-blob-content-language:
- spanish
x-ms-blob-type:
- BlockBlob
x-ms-date:
- Fri, 21 Aug 2020 08:34:53 GMT
x-ms-meta-name:
- car
x-ms-meta-number:
- '2'
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/container3851155b/blob2
response:
body:
string: ''
headers:
content-length:
- '0'
content-md5:
- XrY7u+Ae7tCTyyK7j1rNww==
date:
- Fri, 21 Aug 2020 08:34:52 GMT
etag:
- '"0x8D845AD137CDC23"'
last-modified:
- Fri, 21 Aug 2020 08:34:53 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-content-crc64:
- vo7q9sPVKY0=
x-ms-request-server-encrypted:
- 'true'
x-ms-version:
- '2019-12-12'
x-ms-version-id:
- '2020-08-21T08:34:53.1543859Z'
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- application/xml
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- azsdk-python-storage-blob/12.4.0 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Fri, 21 Aug 2020 08:34:53 GMT
x-ms-version:
- '2019-12-12'
method: GET
uri: https://storagename.blob.core.windows.net/container3851155b?include=metadata&restype=container&comp=list
response:
body:
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><EnumerationResults
ServiceEndpoint=\"https://storagename.blob.core.windows.net/\" ContainerName=\"container3851155b\"><Blobs><Blob><Name>blob1</Name><VersionId>2020-08-21T08:34:53.0433049Z</VersionId><IsCurrentVersion>true</IsCurrentVersion><Properties><Creation-Time>Fri,
21 Aug 2020 08:34:52 GMT</Creation-Time><Last-Modified>Fri, 21 Aug 2020 08:34:52
GMT</Last-Modified><Etag>0x8D845AD135C55E0</Etag><Content-Length>11</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding
/><Content-Language>spanish</Content-Language><Content-CRC64 /><Content-MD5>XrY7u+Ae7tCTyyK7j1rNww==</Content-MD5><Cache-Control
/><Content-Disposition>inline</Content-Disposition><BlobType>BlockBlob</BlobType><AccessTier>Hot</AccessTier><AccessTierInferred>true</AccessTierInferred><LeaseStatus>unlocked</LeaseStatus><LeaseState>available</LeaseState><ServerEncrypted>true</ServerEncrypted></Properties><Metadata><number>1</number><name>bob</name></Metadata><OrMetadata
/></Blob><Blob><Name>blob2</Name><VersionId>2020-08-21T08:34:53.1543859Z</VersionId><IsCurrentVersion>true</IsCurrentVersion><Properties><Creation-Time>Fri,
21 Aug 2020 08:34:53 GMT</Creation-Time><Last-Modified>Fri, 21 Aug 2020 08:34:53
GMT</Last-Modified><Etag>0x8D845AD137CDC23</Etag><Content-Length>11</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding
/><Content-Language>spanish</Content-Language><Content-CRC64 /><Content-MD5>XrY7u+Ae7tCTyyK7j1rNww==</Content-MD5><Cache-Control
/><Content-Disposition>inline</Content-Disposition><BlobType>BlockBlob</BlobType><AccessTier>Hot</AccessTier><AccessTierInferred>true</AccessTierInferred><LeaseStatus>unlocked</LeaseStatus><LeaseState>available</LeaseState><ServerEncrypted>true</ServerEncrypted></Properties><Metadata><number>2</number><name>car</name></Metadata><OrMetadata
/></Blob></Blobs><NextMarker /></EnumerationResults>"
headers:
content-type:
- application/xml
date:
- Fri, 21 Aug 2020 08:34:52 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
- chunked
x-ms-version:
- '2019-12-12'
status:
code: 200
message: OK
version: 1
7 changes: 4 additions & 3 deletions sdk/storage/azure-storage-blob/tests/test_common_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ def test_blob_snapshot_exists(self, resource_group, location, storage_account, s

# Act
blob = self.bsc.get_blob_client(self.container_name, blob_name, snapshot=snapshot)
exists = blob.get_blob_properties()
prop = blob.get_blob_properties()

# Assert
self.assertTrue(exists)
self.assertTrue(prop)
self.assertEqual(snapshot['snapshot'], prop.snapshot)


@GlobalStorageAccountPreparer()
Expand Down Expand Up @@ -2307,7 +2308,7 @@ def test_set_blob_permission(self):
self.assertEqual(permission.read, True)
self.assertEqual(permission.delete, True)
self.assertEqual(permission.write, True)
self.assertEqual(permission._str, 'wrdx')
self.assertEqual(permission._str, 'rwdx')

@GlobalStorageAccountPreparer()
def test_transport_closed_only_once(self, resource_group, location, storage_account, storage_account_key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ async def test_blob_snapshot_exists(self, resource_group, location, storage_acco

# Act
blob = self.bsc.get_blob_client(self.container_name, blob_name, snapshot=snapshot)
exists = await blob.get_blob_properties()
prop = await blob.get_blob_properties()

# Assert
self.assertTrue(exists)
self.assertTrue(prop)
self.assertEqual(snapshot['snapshot'], prop.snapshot)


@GlobalStorageAccountPreparer()
Expand Down
16 changes: 11 additions & 5 deletions sdk/storage/azure-storage-blob/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
PremiumPageBlobTier,
generate_container_sas,
PartialBatchErrorException,
generate_account_sas, ResourceTypes, AccountSasPermissions, ContainerClient)
generate_account_sas, ResourceTypes, AccountSasPermissions, ContainerClient, ContentSettings)

#------------------------------------------------------------------------------
TEST_CONTAINER_PREFIX = 'container'
Expand Down Expand Up @@ -974,13 +974,17 @@ def test_list_blobs_with_include_snapshots(self, resource_group, location, stora
@GlobalStorageAccountPreparer()
def test_list_blobs_with_include_metadata(self, resource_group, location, storage_account, storage_account_key):
bsc = BlobServiceClient(self.account_url(storage_account, "blob"), storage_account_key)
pytest.skip("Waiting on metadata XML fix in msrest")
# pytest.skip("Waiting on metadata XML fix in msrest")
container = self._create_container(bsc)
data = b'hello world'
content_settings = ContentSettings(
content_language='spanish',
content_disposition='inline')
blob1 = container.get_blob_client('blob1')
blob1.upload_blob(data, metadata={'number': '1', 'name': 'bob'})
blob1.upload_blob(data, overwrite=True, content_settings=content_settings, metadata={'number': '1', 'name': 'bob'})
blob1.create_snapshot()
container.get_blob_client('blob2').upload_blob(data, metadata={'number': '2', 'name': 'car'})

container.get_blob_client('blob2').upload_blob(data, overwrite=True, content_settings=content_settings, metadata={'number': '2', 'name': 'car'})

# Act
blobs =list(container.list_blobs(include="metadata"))
Expand All @@ -993,6 +997,8 @@ def test_list_blobs_with_include_metadata(self, resource_group, location, storag
self.assertEqual(blobs[1].name, 'blob2')
self.assertEqual(blobs[1].metadata['number'], '2')
self.assertEqual(blobs[1].metadata['name'], 'car')
self.assertEqual(blobs[1].content_settings.content_language, 'spanish')
self.assertEqual(blobs[1].content_settings.content_disposition, 'inline')

@GlobalStorageAccountPreparer()
def test_list_blobs_with_include_uncommittedblobs(self, resource_group, location, storage_account, storage_account_key):
Expand Down Expand Up @@ -1700,7 +1706,7 @@ def test_set_container_permission(self):
self.assertEqual(permission.read, True)
self.assertEqual(permission.list, True)
self.assertEqual(permission.write, True)
self.assertEqual(permission._str, 'wrlx')
self.assertEqual(permission._str, 'rwxl')

@GlobalStorageAccountPreparer()
def test_download_blob(self, resource_group, location, storage_account, storage_account_key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def from_string(cls, permission):
parsed = cls(read=p_read, write=p_write, delete=p_delete, delete_previous_version=p_delete_previous_version,
list=p_list, add=p_add, create=p_create, update=p_update, process=p_process, tag=p_tag,
filter_by_tags=p_filter_by_tags)
parsed._str = permission # pylint: disable = protected-access

return parsed


Expand Down
Loading