From 00c4e9862df5653d7f72f9e77f6708bbc590ea05 Mon Sep 17 00:00:00 2001 From: Kamil Sobol <61715331+kasobol-msft@users.noreply.github.com> Date: Wed, 16 Jun 2021 10:23:09 -0700 Subject: [PATCH] [Storage] Deprecated SAS version fix. (#22321) * fix live tests. * remember about blobs. --- .../sas/BlobServiceSasSignatureValues.java | 2 +- .../azure/storage/blob/SasClientTests.groovy | 18 +++++++ ...sRememberAboutStringToSignDeprecation.json | 50 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 sdk/storage/azure-storage-blob/src/test/resources/session-records/SasClientTestsRememberAboutStringToSignDeprecation.json diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/sas/BlobServiceSasSignatureValues.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/sas/BlobServiceSasSignatureValues.java index 4cddfc4fce60..291742542ed4 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/sas/BlobServiceSasSignatureValues.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/sas/BlobServiceSasSignatureValues.java @@ -707,7 +707,7 @@ private String stringToSign(String canonicalName) { this.identifier == null ? "" : this.identifier, this.sasIpRange == null ? "" : this.sasIpRange.toString(), this.protocol == null ? "" : this.protocol.toString(), - VERSION_DEPRECATED_STRING_TO_SIGN, /* Pin down to version so old string to sign works. */ + VERSION, /* Pin down to version so old string to sign works. */ resource, this.snapshotId == null ? "" : this.snapshotId, this.cacheControl == null ? "" : this.cacheControl, diff --git a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/SasClientTests.groovy b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/SasClientTests.groovy index 5c4df447e538..ef9b293ee332 100644 --- a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/SasClientTests.groovy +++ b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/SasClientTests.groovy @@ -1047,4 +1047,22 @@ class SasClientTests extends APISpec { null | null | SasProtocol.HTTPS_ONLY || "%s" + "\nr\nb\no\n\n" + Constants.ISO_8601_UTC_DATE_FORMATTER.format(OffsetDateTime.of(2017, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC)) + "\n\n" + SasProtocol.HTTPS_ONLY + "\n" + Constants.SAS_SERVICE_VERSION + "\n" } + /** + * If this test fails it means that non-deprecated string to sign has new components. + * In that case we should hardcode version used for deprecated string to sign like we did for user delegation sas. + */ + def "Remember about string to sign deprecation"() { + setup: + def client = sasClient + def values = new BlobServiceSasSignatureValues(namer.getUtcNow(), new BlobSasPermission()) + values.setContainerName(sasClient.containerName) + values.setBlobName(sasClient.blobName) + + when: + def deprecatedStringToSign = values.generateSasQueryParameters(env.primaryAccount.credential).encode() + def stringToSign = client.generateSas(values) + + then: + deprecatedStringToSign == stringToSign + } } diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/SasClientTestsRememberAboutStringToSignDeprecation.json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/SasClientTestsRememberAboutStringToSignDeprecation.json new file mode 100644 index 000000000000..cb5cb1e911d4 --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/SasClientTestsRememberAboutStringToSignDeprecation.json @@ -0,0 +1,50 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/b42ece0b0b42ece0b9ee39361ac816bd27b5a41c888b?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11; Windows 10; 10.0)", + "x-ms-client-request-id" : "1b262853-8df9-4b1c-bc1b-008f06123c87" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D930DC6D95B38C", + "Last-Modified" : "Wed, 16 Jun 2021 15:35:53 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "b56ba961-b01e-005c-3ec5-629fe9000000", + "x-ms-client-request-id" : "1b262853-8df9-4b1c-bc1b-008f06123c87", + "Date" : "Wed, 16 Jun 2021 15:35:53 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/b42ece0b0b42ece0b9ee39361ac816bd27b5a41c888b/b42ece0b1b42ece0b9ee4800196aa4fe2648d4fbc958", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11; Windows 10; 10.0)", + "x-ms-client-request-id" : "046df0da-f10e-4a49-b96a-758f1fa1f561", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Wed, 16 Jun 2021 15:35:54 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Wed, 16 Jun 2021 15:35:53 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D930DC6DC49B79", + "x-ms-request-id" : "b56baaeb-b01e-005c-27c5-629fe9000000", + "x-ms-client-request-id" : "046df0da-f10e-4a49-b96a-758f1fa1f561" + }, + "Exception" : null + } ], + "variables" : [ "b42ece0b0b42ece0b9ee39361ac816bd27b5a41c888b", "b42ece0b1b42ece0b9ee4800196aa4fe2648d4fbc958", "2021-06-16T15:35:54.361036200Z" ] +} \ No newline at end of file