From d8d99f4a1be2bb4b14d6bd950845443adae69a4a Mon Sep 17 00:00:00 2001 From: Emma Zhu Date: Fri, 21 May 2021 16:12:14 +0800 Subject: [PATCH 1/2] Refine behavior of BlobClient.Exists to return true when server returns error message of 'BlobUsesCustomerSpecifiedEncryption'. --- ...sts_rethrows_error_from_getproperties.json | 116 ++++++------ ...b_uploaded_with_customer_provided_key.json | 136 ++++++++++++++ ...xists_rethrows_error_from_getproperties.js | 96 +++++----- ...lob_uploaded_with_customer_provided_key.js | 168 ++++++++++++++++++ sdk/storage/storage-blob/src/Clients.ts | 11 ++ .../storage-blob/src/utils/constants.ts | 2 + .../storage-blob/test/blobclient.spec.ts | 34 +++- 7 files changed, 463 insertions(+), 100 deletions(-) create mode 100644 sdk/storage/storage-blob/recordings/browsers/blobclient/recording_exists_works_against_blob_uploaded_with_customer_provided_key.json create mode 100644 sdk/storage/storage-blob/recordings/node/blobclient/recording_exists_works_against_blob_uploaded_with_customer_provided_key.js diff --git a/sdk/storage/storage-blob/recordings/browsers/blobclient/recording_exists_rethrows_error_from_getproperties.json b/sdk/storage/storage-blob/recordings/browsers/blobclient/recording_exists_rethrows_error_from_getproperties.json index 74f464da0eb7..c74fcf2b0837 100644 --- a/sdk/storage/storage-blob/recordings/browsers/blobclient/recording_exists_rethrows_error_from_getproperties.json +++ b/sdk/storage/storage-blob/recordings/browsers/blobclient/recording_exists_rethrows_error_from_getproperties.json @@ -2,7 +2,7 @@ "recordings": [ { "method": "PUT", - "url": "https://fakestorageaccount.blob.core.windows.net/container156996521765907278", + "url": "https://fakestorageaccount.blob.core.windows.net/container162158370539004944", "query": { "restype": "container" }, @@ -10,62 +10,64 @@ "status": 201, "response": "", "responseHeaders": { - "date": "Tue, 01 Oct 2019 21:26:57 GMT", - "last-modified": "Tue, 01 Oct 2019 21:26:57 GMT", + "content-length": "0", + "date": "Fri, 21 May 2021 07:55:05 GMT", + "etag": "\"0x8D91C2DBF6B8B9B\"", + "last-modified": "Fri, 21 May 2021 07:55:06 GMT", "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", - "etag": "\"0x8D746B616A39231\"", - "x-ms-request-id": "89cc9a60-201e-0065-099e-78812b000000", - "x-ms-version": "2019-02-02", - "x-ms-client-request-id": "47ed4f1c-a923-4142-9555-d29fdf9f6b93", - "content-length": "0" + "x-ms-client-request-id": "ab930ad7-93cd-4dfa-b3fd-ce5f0786a917", + "x-ms-request-id": "84cdc950-d01e-00ad-6616-4ead21000000", + "x-ms-version": "2020-08-04" } }, { "method": "PUT", - "url": "https://fakestorageaccount.blob.core.windows.net/container156996521765907278/blob156996521772905931", + "url": "https://fakestorageaccount.blob.core.windows.net/container162158370539004944/blob162158370593907536", "query": {}, "requestBody": "Hello World", "status": 201, "response": "", "responseHeaders": { - "x-ms-content-crc64": "YeJLfssylmU=", - "date": "Tue, 01 Oct 2019 21:26:57 GMT", - "last-modified": "Tue, 01 Oct 2019 21:26:57 GMT", - "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "content-length": "0", "content-md5": "sQqNsWTgdUEFt6mb5y4/5Q==", - "etag": "\"0x8D746B616AF1102\"", - "x-ms-request-id": "89cc9a74-201e-0065-189e-78812b000000", - "x-ms-version": "2019-02-02", - "x-ms-client-request-id": "b52d8c81-abb6-42fa-b174-8fa358c22a49", + "date": "Fri, 21 May 2021 07:55:05 GMT", + "etag": "\"0x8D91C2DBF8C46CE\"", + "last-modified": "Fri, 21 May 2021 07:55:06 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "2c239826-1e88-4426-bfab-05f5db332509", + "x-ms-content-crc64": "YeJLfssylmU=", + "x-ms-request-id": "84cdca16-d01e-00ad-1b16-4ead21000000", "x-ms-request-server-encrypted": "true", - "content-length": "0" + "x-ms-version": "2020-08-04", + "x-ms-version-id": "2021-05-21T07:55:06.2383310Z" } }, { "method": "PUT", - "url": "https://fakestorageaccount.blob.core.windows.net/container156996521765907278/blobCPK156996521780308522", + "url": "https://fakestorageaccount.blob.core.windows.net/container162158370539004944/blobCPK162158370615105097", "query": {}, "requestBody": "Hello World", "status": 201, "response": "", "responseHeaders": { + "content-length": "0", + "content-md5": "sQqNsWTgdUEFt6mb5y4/5Q==", + "date": "Fri, 21 May 2021 07:55:06 GMT", + "etag": "\"0x8D91C2DBFAEF05E\"", + "last-modified": "Fri, 21 May 2021 07:55:06 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "2952f4bc-688c-4037-a0cc-7a78ce85f1b9", "x-ms-content-crc64": "YeJLfssylmU=", - "date": "Tue, 01 Oct 2019 21:26:57 GMT", "x-ms-encryption-key-sha256": "3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=", - "last-modified": "Tue, 01 Oct 2019 21:26:57 GMT", - "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", - "content-md5": "sQqNsWTgdUEFt6mb5y4/5Q==", + "x-ms-request-id": "84cdcacb-d01e-00ad-4116-4ead21000000", "x-ms-request-server-encrypted": "true", - "x-ms-request-id": "89cc9a8f-201e-0065-309e-78812b000000", - "x-ms-version": "2019-02-02", - "x-ms-client-request-id": "0a06bd1a-3a46-4716-b410-6325b054dfc6", - "content-length": "0", - "etag": "\"0x8D746B616BAACA9\"" + "x-ms-version": "2020-08-04", + "x-ms-version-id": "2021-05-21T07:55:06.4654942Z" } }, { "method": "PUT", - "url": "https://fakestorageaccount.blob.core.windows.net/container156996521765907278/blobCPK156996521780308522", + "url": "https://fakestorageaccount.blob.core.windows.net/container162158370539004944/blobCPK162158370615105097", "query": { "comp": "metadata" }, @@ -73,38 +75,40 @@ "status": 200, "response": "", "responseHeaders": { - "date": "Tue, 01 Oct 2019 21:26:57 GMT", - "x-ms-encryption-key-sha256": "3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=", - "last-modified": "Tue, 01 Oct 2019 21:26:57 GMT", + "content-length": "0", + "date": "Fri, 21 May 2021 07:55:06 GMT", + "etag": "\"0x8D91C2DBFCE16CD\"", + "last-modified": "Fri, 21 May 2021 07:55:06 GMT", "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", - "etag": "\"0x8D746B616C5ABE0\"", - "x-ms-request-id": "89cc9aa6-201e-0065-429e-78812b000000", - "x-ms-version": "2019-02-02", - "x-ms-client-request-id": "6afe822e-a49e-4119-92d8-7d2581849068", + "x-ms-client-request-id": "0ebc565a-528f-4cde-ad27-30c8d7d8951b", + "x-ms-encryption-key-sha256": "3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=", + "x-ms-request-id": "84cdcba9-d01e-00ad-0616-4ead21000000", "x-ms-request-server-encrypted": "true", - "content-length": "0" + "x-ms-version": "2020-08-04", + "x-ms-version-id": "2021-05-21T07:55:06.6706397Z" } }, { "method": "HEAD", - "url": "https://fakestorageaccount.blob.core.windows.net/container156996521765907278/blobCPK156996521780308522", + "url": "https://fakestorageaccount.blob.core.windows.net/container162158370539004944/blobCPK162158370615105097", "query": {}, "requestBody": null, - "status": 409, + "status": 401, "response": "", "responseHeaders": { - "date": "Tue, 01 Oct 2019 21:26:57 GMT", + "date": "Fri, 21 May 2021 07:55:06 GMT", "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", - "x-ms-error-code": "BlobUsesCustomerSpecifiedEncryption", "transfer-encoding": "chunked", - "x-ms-request-id": "89cc9ac3-201e-0065-599e-78812b000000", - "x-ms-version": "2019-02-02", - "x-ms-client-request-id": "82f15833-63bf-4491-8b7a-446274ddd8a6" + "www-authenticate": "Bearer authorization_uri=https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/authorize resource_id=https://storage.azure.com", + "x-ms-client-request-id": "4e0da465-2bbd-4b0a-9d1a-4ff1c345ded6", + "x-ms-error-code": "NoAuthenticationInformation", + "x-ms-request-id": "84cdcc65-d01e-00ad-3016-4ead21000000", + "x-ms-version": "2020-08-04" } }, { "method": "DELETE", - "url": "https://fakestorageaccount.blob.core.windows.net/container156996521765907278", + "url": "https://fakestorageaccount.blob.core.windows.net/container162158370539004944", "query": { "restype": "container" }, @@ -112,18 +116,22 @@ "status": 202, "response": "", "responseHeaders": { - "date": "Tue, 01 Oct 2019 21:26:57 GMT", + "content-length": "0", + "date": "Fri, 21 May 2021 07:55:06 GMT", "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", - "x-ms-request-id": "89cc9adb-201e-0065-6d9e-78812b000000", - "x-ms-version": "2019-02-02", - "x-ms-client-request-id": "d24a3364-279b-4a0f-850b-274e70c8a72c", - "content-length": "0" + "x-ms-client-request-id": "6631e327-2236-4700-9430-baa86a5ddac7", + "x-ms-request-id": "84cdcd11-d01e-00ad-4a16-4ead21000000", + "x-ms-version": "2020-08-04" } } ], "uniqueTestInfo": { - "container": "container156996521765907278", - "blob": "blob156996521772905931", - "blobCPK": "blobCPK156996521780308522" - } + "uniqueName": { + "container": "container162158370539004944", + "blob": "blob162158370593907536", + "blobCPK": "blobCPK162158370615105097" + }, + "newDate": {} + }, + "hash": "b2bcfa0bb65ecbf7e480c9da72357f9a" } \ No newline at end of file diff --git a/sdk/storage/storage-blob/recordings/browsers/blobclient/recording_exists_works_against_blob_uploaded_with_customer_provided_key.json b/sdk/storage/storage-blob/recordings/browsers/blobclient/recording_exists_works_against_blob_uploaded_with_customer_provided_key.json new file mode 100644 index 000000000000..6bb653af6b52 --- /dev/null +++ b/sdk/storage/storage-blob/recordings/browsers/blobclient/recording_exists_works_against_blob_uploaded_with_customer_provided_key.json @@ -0,0 +1,136 @@ +{ + "recordings": [ + { + "method": "PUT", + "url": "https://fakestorageaccount.blob.core.windows.net/container162157809072502135", + "query": { + "restype": "container" + }, + "requestBody": null, + "status": 201, + "response": "", + "responseHeaders": { + "content-length": "0", + "date": "Fri, 21 May 2021 06:21:30 GMT", + "etag": "\"0x8D91C20ACD1A8BE\"", + "last-modified": "Fri, 21 May 2021 06:21:31 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "8293cd1a-b091-487d-b3ba-253bbdec1cba", + "x-ms-request-id": "95961389-001e-002c-2509-4e0f76000000", + "x-ms-version": "2020-08-04" + } + }, + { + "method": "PUT", + "url": "https://fakestorageaccount.blob.core.windows.net/container162157809072502135/blob162157809127203895", + "query": {}, + "requestBody": "Hello World", + "status": 201, + "response": "", + "responseHeaders": { + "content-length": "0", + "content-md5": "sQqNsWTgdUEFt6mb5y4/5Q==", + "date": "Fri, 21 May 2021 06:21:30 GMT", + "etag": "\"0x8D91C20ACF21DB9\"", + "last-modified": "Fri, 21 May 2021 06:21:31 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "54c2f328-298f-4953-9b99-f9c5f22495f7", + "x-ms-content-crc64": "YeJLfssylmU=", + "x-ms-request-id": "959613ae-001e-002c-3f09-4e0f76000000", + "x-ms-request-server-encrypted": "true", + "x-ms-version": "2020-08-04", + "x-ms-version-id": "2021-05-21T06:21:31.5715513Z" + } + }, + { + "method": "PUT", + "url": "https://fakestorageaccount.blob.core.windows.net/container162157809072502135/blobCPK162157809148303225", + "query": {}, + "requestBody": "Hello World", + "status": 201, + "response": "", + "responseHeaders": { + "content-length": "0", + "content-md5": "sQqNsWTgdUEFt6mb5y4/5Q==", + "date": "Fri, 21 May 2021 06:21:31 GMT", + "etag": "\"0x8D91C20AD13B59D\"", + "last-modified": "Fri, 21 May 2021 06:21:31 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "9e819cc8-4b35-4d73-841e-5424c2339edb", + "x-ms-content-crc64": "YeJLfssylmU=", + "x-ms-encryption-key-sha256": "3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=", + "x-ms-request-id": "959613d5-001e-002c-5f09-4e0f76000000", + "x-ms-request-server-encrypted": "true", + "x-ms-version": "2020-08-04", + "x-ms-version-id": "2021-05-21T06:21:31.7917085Z" + } + }, + { + "method": "PUT", + "url": "https://fakestorageaccount.blob.core.windows.net/container162157809072502135/blobCPK162157809148303225", + "query": { + "comp": "metadata" + }, + "requestBody": null, + "status": 200, + "response": "", + "responseHeaders": { + "content-length": "0", + "date": "Fri, 21 May 2021 06:21:31 GMT", + "etag": "\"0x8D91C20AD33C69F\"", + "last-modified": "Fri, 21 May 2021 06:21:32 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "eb00791e-51e4-4997-8193-ee71ed727894", + "x-ms-encryption-key-sha256": "3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=", + "x-ms-request-id": "959613fb-001e-002c-7e09-4e0f76000000", + "x-ms-request-server-encrypted": "true", + "x-ms-version": "2020-08-04", + "x-ms-version-id": "2021-05-21T06:21:32.0028591Z" + } + }, + { + "method": "HEAD", + "url": "https://fakestorageaccount.blob.core.windows.net/container162157809072502135/blobCPK162157809148303225", + "query": {}, + "requestBody": null, + "status": 409, + "response": "", + "responseHeaders": { + "date": "Fri, 21 May 2021 06:21:31 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "transfer-encoding": "chunked", + "x-ms-client-request-id": "1c6ab1f9-a746-4885-9faf-70e23214dec8", + "x-ms-error-code": "BlobUsesCustomerSpecifiedEncryption", + "x-ms-request-id": "9596143a-001e-002c-2f09-4e0f76000000", + "x-ms-version": "2020-08-04" + } + }, + { + "method": "DELETE", + "url": "https://fakestorageaccount.blob.core.windows.net/container162157809072502135", + "query": { + "restype": "container" + }, + "requestBody": null, + "status": 202, + "response": "", + "responseHeaders": { + "content-length": "0", + "date": "Fri, 21 May 2021 06:21:31 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "c2cb6f6b-b664-40ae-a707-af299bfac2e8", + "x-ms-request-id": "95961458-001e-002c-4709-4e0f76000000", + "x-ms-version": "2020-08-04" + } + } + ], + "uniqueTestInfo": { + "uniqueName": { + "container": "container162157809072502135", + "blob": "blob162157809127203895", + "blobCPK": "blobCPK162157809148303225" + }, + "newDate": {} + }, + "hash": "4c650744a22d5e8da9889652bcf1a83b" +} \ No newline at end of file diff --git a/sdk/storage/storage-blob/recordings/node/blobclient/recording_exists_rethrows_error_from_getproperties.js b/sdk/storage/storage-blob/recordings/node/blobclient/recording_exists_rethrows_error_from_getproperties.js index cf23f0424dac..393fb688d613 100644 --- a/sdk/storage/storage-blob/recordings/node/blobclient/recording_exists_rethrows_error_from_getproperties.js +++ b/sdk/storage/storage-blob/recordings/node/blobclient/recording_exists_rethrows_error_from_getproperties.js @@ -1,79 +1,79 @@ let nock = require('nock'); -module.exports.hash = "835d31cda6bfe41de09ef1049424b6d4"; +module.exports.hash = "e719418e15a55c8c9608d6d45be16d22"; -module.exports.testInfo = {"uniqueName":{"container":"container159210827468503310","blob":"blob159210827470105842","blobCPK":"blobCPK159210827471709619"},"newDate":{}} +module.exports.testInfo = {"uniqueName":{"container":"container162158369932703522","blob":"blob162158370011806935","blobCPK":"blobCPK162158370022905289"},"newDate":{}} nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) - .put('/container159210827468503310') + .put('/container162158369932703522') .query(true) .reply(201, "", [ 'Content-Length', '0', 'Last-Modified', - 'Sun, 14 Jun 2020 04:17:54 GMT', + 'Fri, 21 May 2021 07:55:00 GMT', 'ETag', - '"0x8D81019E949407F"', + '"0x8D91C2DBBF22C4F"', 'Server', 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', 'x-ms-request-id', - 'c1309217-201e-003e-2802-42dadf000000', + '9bd79ca5-b01e-00b6-7016-4e83b3000000', 'x-ms-client-request-id', - '5c20b3a2-b483-407d-8df8-d1bb5955bf35', + 'd66f8a65-7d02-4574-a59b-4a5b9fa9889c', 'x-ms-version', - '2019-12-12', + '2020-08-04', 'Date', - 'Sun, 14 Jun 2020 04:17:53 GMT' + 'Fri, 21 May 2021 07:54:59 GMT' ]); nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) - .put('/container159210827468503310/blob159210827470105842', "Hello World") + .put('/container162158369932703522/blob162158370011806935', "Hello World") .reply(201, "", [ 'Content-Length', '0', 'Content-MD5', 'sQqNsWTgdUEFt6mb5y4/5Q==', 'Last-Modified', - 'Sun, 14 Jun 2020 04:17:54 GMT', + 'Fri, 21 May 2021 07:55:00 GMT', 'ETag', - '"0x8D81019E94BCEC3"', + '"0x8D91C2DBC0560D3"', 'Server', 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', 'x-ms-request-id', - 'c130921f-201e-003e-2f02-42dadf000000', + '9bd79d26-b01e-00b6-5616-4e83b3000000', 'x-ms-client-request-id', - '03357150-c3f5-4b1d-b685-460db07269f0', + 'ea94f07e-9f13-453c-bad3-3cecfa155ff8', 'x-ms-version', - '2019-12-12', + '2020-08-04', 'x-ms-content-crc64', 'YeJLfssylmU=', 'x-ms-request-server-encrypted', 'true', 'x-ms-version-id', - '2020-06-14T04:17:54.7211459Z', + '2021-05-21T07:55:00.3210963Z', 'Date', - 'Sun, 14 Jun 2020 04:17:53 GMT' + 'Fri, 21 May 2021 07:54:59 GMT' ]); nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) - .put('/container159210827468503310/blobCPK159210827471709619', "Hello World") + .put('/container162158369932703522/blobCPK162158370022905289', "Hello World") .reply(201, "", [ 'Content-Length', '0', 'Content-MD5', 'sQqNsWTgdUEFt6mb5y4/5Q==', 'Last-Modified', - 'Sun, 14 Jun 2020 04:17:54 GMT', + 'Fri, 21 May 2021 07:55:00 GMT', 'ETag', - '"0x8D81019E94E191D"', + '"0x8D91C2DBC17B3AF"', 'Server', 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', 'x-ms-request-id', - 'c1309226-201e-003e-3602-42dadf000000', + '9bd79d5d-b01e-00b6-0316-4e83b3000000', 'x-ms-client-request-id', - '2baaf38b-a972-44df-8873-9cb724754d14', + '0de08d61-2a08-4506-afcf-1c3104ddda80', 'x-ms-version', - '2019-12-12', + '2020-08-04', 'x-ms-content-crc64', 'YeJLfssylmU=', 'x-ms-request-server-encrypted', @@ -81,60 +81,66 @@ nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParam 'x-ms-encryption-key-sha256', '3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=', 'x-ms-version-id', - '2020-06-14T04:17:54.7361565Z', + '2021-05-21T07:55:00.4411823Z', 'Date', - 'Sun, 14 Jun 2020 04:17:53 GMT' + 'Fri, 21 May 2021 07:54:59 GMT' ]); nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) - .put('/container159210827468503310/blobCPK159210827471709619') + .put('/container162158369932703522/blobCPK162158370022905289') .query(true) .reply(200, "", [ 'Content-Length', '0', 'Last-Modified', - 'Sun, 14 Jun 2020 04:17:54 GMT', + 'Fri, 21 May 2021 07:55:00 GMT', 'ETag', - '"0x8D81019E9506377"', + '"0x8D91C2DBC280A63"', 'Server', 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', 'x-ms-request-id', - 'c130922c-201e-003e-3c02-42dadf000000', + '9bd79d91-b01e-00b6-2f16-4e83b3000000', 'x-ms-client-request-id', - '4c8d8ae3-51eb-43a0-bc5e-d29aa9b2bec3', + 'dba7a54f-d7a3-41ee-92f5-5eb9a38cf899', 'x-ms-version', - '2019-12-12', + '2020-08-04', 'x-ms-version-id', - '2020-06-14T04:17:54.7521671Z', + '2021-05-21T07:55:00.5502602Z', 'x-ms-request-server-encrypted', 'true', 'x-ms-encryption-key-sha256', '3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=', 'Date', - 'Sun, 14 Jun 2020 04:17:53 GMT' + 'Fri, 21 May 2021 07:54:59 GMT' ]); nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) - .head('/container159210827468503310/blobCPK159210827471709619') - .reply(409, "", [ + .head('/container162158369932703522/blobCPK162158370022905289') + .reply(401, "", [ 'Transfer-Encoding', 'chunked', 'Server', 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', 'x-ms-request-id', - 'c1309232-201e-003e-4202-42dadf000000', + '9bd79dc6-b01e-00b6-5816-4e83b3000000', 'x-ms-client-request-id', - 'f47476cb-2a13-421c-a666-4730439e68e1', + '14593036-ca8d-4bb7-8bec-464c24039306', 'x-ms-version', - '2019-12-12', + '2020-08-04', 'x-ms-error-code', - 'BlobUsesCustomerSpecifiedEncryption', + 'NoAuthenticationInformation', + 'Access-Control-Expose-Headers', + 'x-ms-request-id,x-ms-client-request-id,Server,x-ms-version,WWW-Authenticate,x-ms-error-code,Content-Length,Date,Transfer-Encoding', + 'Access-Control-Allow-Origin', + '*', + 'WWW-Authenticate', + 'Bearer authorization_uri=https://login.microsoftonline.com/aaaaa/oauth2/authorize resource_id=https://storage.azure.com', 'Date', - 'Sun, 14 Jun 2020 04:17:53 GMT' + 'Fri, 21 May 2021 07:55:00 GMT' ]); nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) - .delete('/container159210827468503310') + .delete('/container162158369932703522') .query(true) .reply(202, "", [ 'Content-Length', @@ -142,11 +148,11 @@ nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParam 'Server', 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', 'x-ms-request-id', - 'c1309236-201e-003e-4602-42dadf000000', + '9bd79dfa-b01e-00b6-8016-4e83b3000000', 'x-ms-client-request-id', - '455f9bb1-9866-406d-a54e-b2f8d56cc27a', + 'ffb9e4ce-7d95-47c8-8283-e4c7f33915eb', 'x-ms-version', - '2019-12-12', + '2020-08-04', 'Date', - 'Sun, 14 Jun 2020 04:17:53 GMT' + 'Fri, 21 May 2021 07:55:00 GMT' ]); diff --git a/sdk/storage/storage-blob/recordings/node/blobclient/recording_exists_works_against_blob_uploaded_with_customer_provided_key.js b/sdk/storage/storage-blob/recordings/node/blobclient/recording_exists_works_against_blob_uploaded_with_customer_provided_key.js new file mode 100644 index 000000000000..68076aed6b8b --- /dev/null +++ b/sdk/storage/storage-blob/recordings/node/blobclient/recording_exists_works_against_blob_uploaded_with_customer_provided_key.js @@ -0,0 +1,168 @@ +let nock = require('nock'); + +module.exports.hash = "88bfafcf0e05a231e5131a07c34ce87a"; + +module.exports.testInfo = {"uniqueName":{"container":"container162157807586803149","blob":"blob162157807640405030","blobCPK":"blobCPK162157807682208407"},"newDate":{}} + +nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) + .put('/container162157807586803149') + .query(true) + .reply(201, "", [ + 'Content-Length', + '0', + 'Last-Modified', + 'Fri, 21 May 2021 06:21:16 GMT', + 'ETag', + '"0x8D91C20A3F450D7"', + 'Server', + 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + '5a47a539-201e-003b-1b09-4ecf15000000', + 'x-ms-client-request-id', + '4c8d622e-eaa6-4ea9-b9c7-f62bf8a65813', + 'x-ms-version', + '2020-08-04', + 'Date', + 'Fri, 21 May 2021 06:21:15 GMT', + 'Connection', + 'close' +]); + +nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) + .put('/container162157807586803149/blob162157807640405030', "Hello World") + .reply(201, "", [ + 'Content-Length', + '0', + 'Content-MD5', + 'sQqNsWTgdUEFt6mb5y4/5Q==', + 'Last-Modified', + 'Fri, 21 May 2021 06:21:16 GMT', + 'ETag', + '"0x8D91C20A4351AB1"', + 'Server', + 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + '14c46381-701e-00ab-7709-4e5a59000000', + 'x-ms-client-request-id', + 'b8053f1b-db3a-4e36-94cc-03f7ea652166', + 'x-ms-version', + '2020-08-04', + 'x-ms-content-crc64', + 'YeJLfssylmU=', + 'x-ms-request-server-encrypted', + 'true', + 'x-ms-version-id', + '2021-05-21T06:21:16.9110705Z', + 'Date', + 'Fri, 21 May 2021 06:21:16 GMT', + 'Connection', + 'close' +]); + +nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) + .put('/container162157807586803149/blobCPK162157807682208407', "Hello World") + .reply(201, "", [ + 'Content-Length', + '0', + 'Content-MD5', + 'sQqNsWTgdUEFt6mb5y4/5Q==', + 'Last-Modified', + 'Fri, 21 May 2021 06:21:17 GMT', + 'ETag', + '"0x8D91C20A4758ADB"', + 'Server', + 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + 'b0e0dd02-401e-0002-1409-4e8fb1000000', + 'x-ms-client-request-id', + 'b2c8eeeb-6580-4603-9c42-8e4375162719', + 'x-ms-version', + '2020-08-04', + 'x-ms-content-crc64', + 'YeJLfssylmU=', + 'x-ms-request-server-encrypted', + 'true', + 'x-ms-encryption-key-sha256', + '3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=', + 'x-ms-version-id', + '2021-05-21T06:21:17.3343735Z', + 'Date', + 'Fri, 21 May 2021 06:21:16 GMT', + 'Connection', + 'close' +]); + +nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) + .put('/container162157807586803149/blobCPK162157807682208407') + .query(true) + .reply(200, "", [ + 'Content-Length', + '0', + 'Last-Modified', + 'Fri, 21 May 2021 06:21:17 GMT', + 'ETag', + '"0x8D91C20A4B733C7"', + 'Server', + 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + '55c7dfd8-c01e-00b9-2409-4e6e45000000', + 'x-ms-client-request-id', + '8ab36f40-5316-48b1-b203-a5519d37b9f6', + 'x-ms-version', + '2020-08-04', + 'x-ms-version-id', + '2021-05-21T06:21:17.7656823Z', + 'x-ms-request-server-encrypted', + 'true', + 'x-ms-encryption-key-sha256', + '3QFFFpRA5+XANHqwwbT4yXDmrT/2JaLt/FKHjzhOdoE=', + 'Date', + 'Fri, 21 May 2021 06:21:17 GMT', + 'Connection', + 'close' +]); + +nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) + .head('/container162157807586803149/blobCPK162157807682208407') + .reply(409, "", [ + 'Transfer-Encoding', + 'chunked', + 'Server', + 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + '1faf615a-501e-001d-4909-4e54a1000000', + 'x-ms-client-request-id', + '12f6e4c6-b779-40dd-ac2d-eb13634df110', + 'x-ms-version', + '2020-08-04', + 'x-ms-error-code', + 'BlobUsesCustomerSpecifiedEncryption', + 'Access-Control-Expose-Headers', + 'x-ms-request-id,x-ms-client-request-id,Server,x-ms-version,x-ms-error-code,Content-Length,Date,Transfer-Encoding', + 'Access-Control-Allow-Origin', + '*', + 'Date', + 'Fri, 21 May 2021 06:21:18 GMT', + 'Connection', + 'close' +]); + +nock('https://fakestorageaccount.blob.core.windows.net:443', {"encodedQueryParams":true}) + .delete('/container162157807586803149') + .query(true) + .reply(202, "", [ + 'Content-Length', + '0', + 'Server', + 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', + 'x-ms-request-id', + '81df6807-401e-0009-0c09-4e97c5000000', + 'x-ms-client-request-id', + '36eb5db0-6aa2-47f1-988e-ccf847ab7359', + 'x-ms-version', + '2020-08-04', + 'Date', + 'Fri, 21 May 2021 06:21:18 GMT', + 'Connection', + 'close' +]); diff --git a/sdk/storage/storage-blob/src/Clients.ts b/sdk/storage/storage-blob/src/Clients.ts index c1c1e2e26a6a..905315e8ee4b 100644 --- a/sdk/storage/storage-blob/src/Clients.ts +++ b/sdk/storage/storage-blob/src/Clients.ts @@ -98,6 +98,7 @@ import { CommonOptions, StorageClient } from "./StorageClient"; import { Batch } from "./utils/Batch"; import { BufferScheduler } from "../../storage-common/src"; import { + BlobUsesCustomerSpecifiedEncryptionMsg, BLOCK_BLOB_MAX_BLOCKS, BLOCK_BLOB_MAX_STAGE_BLOCK_BYTES, BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES, @@ -1280,7 +1281,17 @@ export class BlobClient extends StorageClient { message: "Expected exception when checking blob existence", }); return false; + } else if ( + e.statusCode === 409 && + e.details.errorCode === BlobUsesCustomerSpecifiedEncryptionMsg + ) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: "Expected exception when checking blob existence", + }); + return true; } + span.setStatus({ code: SpanStatusCode.ERROR, message: e.message, diff --git a/sdk/storage/storage-blob/src/utils/constants.ts b/sdk/storage/storage-blob/src/utils/constants.ts index b565c6037d20..bf86611766ae 100644 --- a/sdk/storage/storage-blob/src/utils/constants.ts +++ b/sdk/storage/storage-blob/src/utils/constants.ts @@ -204,3 +204,5 @@ export const StorageBlobLoggingAllowedQueryParameters = [ "skv", "snapshot", ]; + +export const BlobUsesCustomerSpecifiedEncryptionMsg = "BlobUsesCustomerSpecifiedEncryption"; diff --git a/sdk/storage/storage-blob/test/blobclient.spec.ts b/sdk/storage/storage-blob/test/blobclient.spec.ts index 8a15790c7975..0bc31bac51d4 100644 --- a/sdk/storage/storage-blob/test/blobclient.spec.ts +++ b/sdk/storage/storage-blob/test/blobclient.spec.ts @@ -13,6 +13,7 @@ import { recorderEnvSetup, getGenericBSU, getImmutableContainerName, + isBrowser, } from "./utils"; import { record, delay, isLiveMode, Recorder } from "@azure-tools/test-recorder"; import { @@ -782,6 +783,24 @@ describe("BlobClient", () => { assert.ok(result, "exists() should return true"); }); + it("exists works against blob uploaded with customer provided key", async () => { + blobName = recorder.getUniqueName("blobCPK"); + blobClient = containerClient.getBlobClient(blobName); + blockBlobClient = blobClient.getBlockBlobClient(); + await blockBlobClient.upload(content, content.length, { + customerProvidedKey: Test_CPK_INFO, + }); + + const metadata = { a: "a" }; + const smResp = await blobClient.setMetadata(metadata, { + customerProvidedKey: Test_CPK_INFO, + }); + assert.equal(smResp.encryptionKeySha256, Test_CPK_INFO.encryptionKeySha256); + + const result = await blobClient.exists(); + assert.ok(result, "exists() should return true"); + }); + it("exists re-throws error from getProperties", async () => { blobName = recorder.getUniqueName("blobCPK"); blobClient = containerClient.getBlobClient(blobName); @@ -797,8 +816,21 @@ describe("BlobClient", () => { assert.equal(smResp.encryptionKeySha256, Test_CPK_INFO.encryptionKeySha256); let exceptionCaught = false; + let anonymousBlobClient; + + if (isBrowser()) { + const anonymousBlobServiceClient = new BlobServiceClient( + `https://${blobServiceClient.accountName}.blob.core.windows.net/` + ); + anonymousBlobClient = anonymousBlobServiceClient + .getContainerClient(containerName) + .getBlobClient(blobName); + } else { + anonymousBlobClient = new BlobClient(blobClient.url); + } + try { - await blobClient.exists(); + await anonymousBlobClient.exists(); } catch (err) { exceptionCaught = true; } From 887906e91b9411a14b8ad1078636162f3f8d063e Mon Sep 17 00:00:00 2001 From: Emma Zhu Date: Fri, 11 Feb 2022 17:59:48 +0800 Subject: [PATCH 2/2] Resolve comments --- sdk/storage/storage-blob/src/Clients.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sdk/storage/storage-blob/src/Clients.ts b/sdk/storage/storage-blob/src/Clients.ts index 905315e8ee4b..04b6a0996ae3 100644 --- a/sdk/storage/storage-blob/src/Clients.ts +++ b/sdk/storage/storage-blob/src/Clients.ts @@ -1276,19 +1276,13 @@ export class BlobClient extends StorageClient { return true; } catch (e) { if (e.statusCode === 404) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: "Expected exception when checking blob existence", - }); + // Expected exception when checking blob existence return false; } else if ( e.statusCode === 409 && e.details.errorCode === BlobUsesCustomerSpecifiedEncryptionMsg ) { - span.setStatus({ - code: SpanStatusCode.ERROR, - message: "Expected exception when checking blob existence", - }); + // Expected exception when checking blob existence return true; }