From afec008295ddd08bf0eb96588212602ed0d248ed Mon Sep 17 00:00:00 2001 From: Isabelle Date: Wed, 10 Apr 2024 13:08:55 -0700 Subject: [PATCH 1/2] tests and recordings --- .../azure-storage-file-share/assets.json | 2 +- .../implementation/models/StorageError.java | 26 +++++++++++++++++++ .../storage/file/share/ShareApiTests.java | 21 +++++++++++++++ .../file/share/ShareAsyncApiTests.java | 19 ++++++++++++++ .../swagger/README.md | 2 +- 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/assets.json b/sdk/storage/azure-storage-file-share/assets.json index 43d28c1fc7d57..b6148d2b7230c 100644 --- a/sdk/storage/azure-storage-file-share/assets.json +++ b/sdk/storage/azure-storage-file-share/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/storage/azure-storage-file-share", - "Tag": "java/storage/azure-storage-file-share_011cc52a61" + "Tag": "java/storage/azure-storage-file-share_5a1b3f763c" } diff --git a/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/implementation/models/StorageError.java b/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/implementation/models/StorageError.java index a4a620cca7e7a..964157d1ce5b7 100644 --- a/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/implementation/models/StorageError.java +++ b/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/implementation/models/StorageError.java @@ -18,6 +18,12 @@ public final class StorageError { @JsonProperty(value = "Message") private String message; + /* + * The AuthenticationErrorDetail property. + */ + @JsonProperty(value = "AuthenticationErrorDetail") + private String authenticationErrorDetail; + /** Creates an instance of StorageError class. */ public StorageError() {} @@ -40,4 +46,24 @@ public StorageError setMessage(String message) { this.message = message; return this; } + + /** + * Get the authenticationErrorDetail property: The AuthenticationErrorDetail property. + * + * @return the authenticationErrorDetail value. + */ + public String getAuthenticationErrorDetail() { + return this.authenticationErrorDetail; + } + + /** + * Set the authenticationErrorDetail property: The AuthenticationErrorDetail property. + * + * @param authenticationErrorDetail the authenticationErrorDetail value to set. + * @return the StorageError object itself. + */ + public StorageError setAuthenticationErrorDetail(String authenticationErrorDetail) { + this.authenticationErrorDetail = authenticationErrorDetail; + return this; + } } diff --git a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java index eee1cc9767e39..b04e09a3ade37 100644 --- a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java +++ b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java @@ -8,6 +8,10 @@ import com.azure.core.http.rest.Response; import com.azure.storage.common.StorageSharedKeyCredential; import com.azure.storage.common.implementation.Constants; +import com.azure.storage.common.sas.AccountSasPermission; +import com.azure.storage.common.sas.AccountSasResourceType; +import com.azure.storage.common.sas.AccountSasService; +import com.azure.storage.common.sas.AccountSasSignatureValues; import com.azure.storage.common.test.shared.extensions.PlaybackOnly; import com.azure.storage.common.test.shared.extensions.RequiredServiceVersion; import com.azure.storage.file.share.implementation.util.ModelHelper; @@ -40,6 +44,9 @@ import com.azure.storage.file.share.options.ShareSetAccessPolicyOptions; import com.azure.storage.file.share.options.ShareSetMetadataOptions; import com.azure.storage.file.share.options.ShareSetPropertiesOptions; +import com.azure.storage.file.share.sas.ShareFileSasPermission; +import com.azure.storage.file.share.sas.ShareSasPermission; +import com.azure.storage.file.share.sas.ShareServiceSasSignatureValues; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -154,6 +161,20 @@ public void createShare() { 201); } + @RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2024-08-04") + @Test + public void createShareSasError() { + ShareServiceClient unauthorizedServiceClient = fileServiceBuilderHelper() + .sasToken("sig=dummyToken") + .buildClient(); + + ShareClient share = unauthorizedServiceClient.getShareClient(generateShareName()); + + ShareStorageException e = assertThrows(ShareStorageException.class, share::create); + assertEquals(ShareErrorCode.AUTHENTICATION_FAILED, e.getErrorCode()); + assertTrue(e.getServiceMessage().contains("AuthenticationErrorDetail")); + } + @RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2019-12-12") @ParameterizedTest @MethodSource("createShareWithArgsSupplier") diff --git a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java index d12878e9615dc..cff7aa2d355be 100644 --- a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java +++ b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java @@ -6,6 +6,7 @@ import com.azure.core.http.rest.Response; import com.azure.storage.common.StorageSharedKeyCredential; import com.azure.storage.common.test.shared.extensions.PlaybackOnly; +import com.azure.storage.common.test.shared.extensions.RequiredServiceVersion; import com.azure.storage.file.share.implementation.util.ModelHelper; import com.azure.storage.file.share.models.NtfsFileAttributes; import com.azure.storage.file.share.models.ShareAudience; @@ -43,6 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; public class ShareAsyncApiTests extends FileShareTestBase { @@ -88,6 +90,23 @@ public void createShare() { .assertNext(it -> FileShareTestHelper.assertResponseStatusCode(it, 201)).verifyComplete(); } + @RequiredServiceVersion(clazz = ShareServiceVersion.class, min = "2024-08-04") + @Test + public void createShareSasError() { + ShareServiceAsyncClient unauthorizedServiceClient = fileServiceBuilderHelper() + .sasToken("sig=dummyToken") + .buildAsyncClient(); + + ShareAsyncClient share = unauthorizedServiceClient.getShareAsyncClient(generateShareName()); + + StepVerifier.create(share.create()) + .verifyErrorSatisfies(r -> { + ShareStorageException e = assertInstanceOf(ShareStorageException.class, r); + assertEquals(ShareErrorCode.AUTHENTICATION_FAILED, e.getErrorCode()); + assertTrue(e.getServiceMessage().contains("AuthenticationErrorDetail")); + }); + } + @ParameterizedTest @MethodSource("createShareWithArgsSupplier") public void createShareWithArgs(Map metadata, Integer quota) { diff --git a/sdk/storage/azure-storage-file-share/swagger/README.md b/sdk/storage/azure-storage-file-share/swagger/README.md index 83f93756a3963..57de2ba899b66 100644 --- a/sdk/storage/azure-storage-file-share/swagger/README.md +++ b/sdk/storage/azure-storage-file-share/swagger/README.md @@ -16,7 +16,7 @@ autorest ### Code generation settings ``` yaml use: '@autorest/java@4.1.16' -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/3f9cca0301ffbb8856826d196c567d821ae190d7/specification/storage/data-plane/Microsoft.FileStorage/preview/2024-05-04/file.json +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/12e0ceead6d4611abdd617d2bbc5c9068e4c772a/specification/storage/data-plane/Microsoft.FileStorage/stable/2024-08-04/file.json java: true output-folder: ../ namespace: com.azure.storage.file.share From 77e2a0576883e47e9357d95bcd97cedf80a1dcc5 Mon Sep 17 00:00:00 2001 From: Isabelle Date: Wed, 10 Apr 2024 13:24:43 -0700 Subject: [PATCH 2/2] style --- .../java/com/azure/storage/file/share/ShareApiTests.java | 7 ------- .../com/azure/storage/file/share/ShareAsyncApiTests.java | 1 - 2 files changed, 8 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java index b04e09a3ade37..fb61238922eb1 100644 --- a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java +++ b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareApiTests.java @@ -8,10 +8,6 @@ import com.azure.core.http.rest.Response; import com.azure.storage.common.StorageSharedKeyCredential; import com.azure.storage.common.implementation.Constants; -import com.azure.storage.common.sas.AccountSasPermission; -import com.azure.storage.common.sas.AccountSasResourceType; -import com.azure.storage.common.sas.AccountSasService; -import com.azure.storage.common.sas.AccountSasSignatureValues; import com.azure.storage.common.test.shared.extensions.PlaybackOnly; import com.azure.storage.common.test.shared.extensions.RequiredServiceVersion; import com.azure.storage.file.share.implementation.util.ModelHelper; @@ -44,9 +40,6 @@ import com.azure.storage.file.share.options.ShareSetAccessPolicyOptions; import com.azure.storage.file.share.options.ShareSetMetadataOptions; import com.azure.storage.file.share.options.ShareSetPropertiesOptions; -import com.azure.storage.file.share.sas.ShareFileSasPermission; -import com.azure.storage.file.share.sas.ShareSasPermission; -import com.azure.storage.file.share.sas.ShareServiceSasSignatureValues; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java index cff7aa2d355be..66722521a7b42 100644 --- a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java +++ b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/ShareAsyncApiTests.java @@ -44,7 +44,6 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; public class ShareAsyncApiTests extends FileShareTestBase {