diff --git a/sdk/storage/Azure.Storage.Blobs/CHANGELOG.md b/sdk/storage/Azure.Storage.Blobs/CHANGELOG.md index 3364f4677dc7..497c0a84ac72 100644 --- a/sdk/storage/Azure.Storage.Blobs/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Blobs/CHANGELOG.md @@ -1,7 +1,7 @@ # Release History ## 12.8.0-beta.1 (Unreleased) - +- Fixed bug where BlobContainerClient.GetBlobClient(), BlobContainerClient.GetParentServiceClient(), BlobServiceClient.GetBlobContainerClient(), BlobBaseClient.WithClientSideEncryptionOptions(), BlobBaseClient.GetParentBlobContainerClient(), BlobBaseClient.WithSnapshot() and BlobBaseClient.WithVersion() created clients that could not generate a SAS from clients that could generate a SAS ## 12.7.0 (2020-11-10) - Includes all features from 12.7.0-preview.1 diff --git a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs index 528e85fd406a..3ba3ba256b9e 100644 --- a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs +++ b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs @@ -32,6 +32,7 @@ public BlobClient(System.Uri blobUri, Azure.Storage.StorageSharedKeyCredential c public virtual System.Threading.Tasks.Task> UploadAsync(string path, Azure.Storage.Blobs.Models.BlobUploadOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> UploadAsync(string path, bool overwrite = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> UploadAsync(string path, System.Threading.CancellationToken cancellationToken) { throw null; } + protected internal virtual Azure.Storage.Blobs.BlobClient WithClientSideEncryptionOptionsCore(Azure.Storage.ClientSideEncryptionOptions clientSideEncryptionOptions) { throw null; } public new Azure.Storage.Blobs.BlobClient WithSnapshot(string snapshot) { throw null; } public new Azure.Storage.Blobs.BlobClient WithVersion(string versionId) { throw null; } } @@ -93,6 +94,7 @@ public BlobContainerClient(System.Uri blobContainerUri, Azure.Storage.StorageSha public virtual Azure.Response GetAccessPolicy(Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetAccessPolicyAsync(Azure.Storage.Blobs.Models.BlobRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } protected internal virtual Azure.Storage.Blobs.Specialized.AppendBlobClient GetAppendBlobClientCore(string blobName) { throw null; } + protected internal virtual Azure.Storage.Blobs.Specialized.BlobBaseClient GetBlobBaseClientCore(string blobName) { throw null; } public virtual Azure.Storage.Blobs.BlobClient GetBlobClient(string blobName) { throw null; } protected internal virtual Azure.Storage.Blobs.Specialized.BlobLeaseClient GetBlobLeaseClientCore(string leaseId) { throw null; } public virtual Azure.Pageable GetBlobs(Azure.Storage.Blobs.Models.BlobTraits traits = Azure.Storage.Blobs.Models.BlobTraits.None, Azure.Storage.Blobs.Models.BlobStates states = Azure.Storage.Blobs.Models.BlobStates.None, string prefix = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs index 0685f40e531e..a75d4863f577 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/AppendBlobClient.cs @@ -189,12 +189,16 @@ public AppendBlobClient(Uri blobUri, TokenCredential credential, BlobClientOptio /// /// The version of the service to use when sending requests. /// + /// + /// The shared key credential used to sign requests. + /// /// Client diagnostics. /// Customer provided key. /// Encryption scope. internal AppendBlobClient( Uri blobUri, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, BlobClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey, @@ -202,6 +206,7 @@ internal AppendBlobClient( : base( blobUri, pipeline, + storageSharedKeyCredential, version, clientDiagnostics, customerProvidedKey, @@ -244,6 +249,7 @@ private static void AssertNoClientSideEncryption(BlobClientOptions options) return new AppendBlobClient( blobUriBuilder.ToUri(), Pipeline, + SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -272,6 +278,7 @@ private static void AssertNoClientSideEncryption(BlobClientOptions options) return new AppendBlobClient( blobUriBuilder.ToUri(), Pipeline, + SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs index 65c65e3ec72b..2cfb4af6e924 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs @@ -164,9 +164,14 @@ public virtual string Name } /// - /// The used to authenticate and generate SAS + /// The used to authenticate and generate SAS. /// - private StorageSharedKeyCredential _storageSharedKeyCredential; + private readonly StorageSharedKeyCredential _storageSharedKeyCredential; + + /// + /// Gets the The used to authenticate and generate SAS. + /// + internal virtual StorageSharedKeyCredential SharedKeyCredential => _storageSharedKeyCredential; /// /// Determines whether the client is able to generate a SAS. @@ -388,6 +393,9 @@ internal BlobBaseClient( /// /// The version of the service to use when sending requests. /// + /// + /// The shared key credential used to sign requests. + /// /// Client diagnostics. /// Customer provided key. /// Client-side encryption options. @@ -395,6 +403,7 @@ internal BlobBaseClient( internal BlobBaseClient( Uri blobUri, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, BlobClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey, @@ -402,7 +411,20 @@ internal BlobBaseClient( string encryptionScope) { _uri = blobUri; + if (!string.IsNullOrEmpty(blobUri.Query)) + { + UriQueryParamsCollection queryParamsCollection = new UriQueryParamsCollection(blobUri.Query); + if (queryParamsCollection.ContainsKey(Constants.SnapshotParameterName)) + { + _snapshot = System.Web.HttpUtility.ParseQueryString(blobUri.Query).Get(Constants.SnapshotParameterName); + } + if (queryParamsCollection.ContainsKey(Constants.VersionIdParameterName)) + { + _blobVersionId = System.Web.HttpUtility.ParseQueryString(blobUri.Query).Get(Constants.VersionIdParameterName); + } + } _pipeline = pipeline; + _storageSharedKeyCredential = storageSharedKeyCredential; _version = version; _clientDiagnostics = clientDiagnostics; _customerProvidedKey = customerProvidedKey; @@ -448,6 +470,7 @@ protected virtual BlobBaseClient WithSnapshotCore(string snapshot) return new BlobBaseClient( blobUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -487,6 +510,7 @@ private protected virtual BlobBaseClient WithVersionCore(string versionId) return new BlobBaseClient( blobUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -1363,7 +1387,7 @@ internal async Task StagedDownloadAsync( bool async = true, CancellationToken cancellationToken = default) { - var client = new BlobBaseClient(Uri, Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, ClientSideEncryption, EncryptionScope); + var client = new BlobBaseClient(Uri, Pipeline, SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, ClientSideEncryption, EncryptionScope); PartitionedDownloader downloader = new PartitionedDownloader(client, transferOptions); @@ -4273,6 +4297,7 @@ protected internal virtual BlobContainerClient GetParentBlobContainerClientCore( _parentBlobContainerClient = new BlobContainerClient( blobUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -4317,14 +4342,7 @@ public static BlobContainerClient GetParentBlobContainerClient(this BlobBaseClie public static BlobBaseClient GetBlobBaseClient( this BlobContainerClient client, string blobName) => - new BlobBaseClient( - client.Uri.AppendToPath(blobName), - client.Pipeline, - client.Version, - client.ClientDiagnostics, - client.CustomerProvidedKey, - client.ClientSideEncryption, - client.EncryptionScope); + client.GetBlobBaseClientCore(blobName); /// /// Creates a new instance of the class, maintaining all the same @@ -4334,13 +4352,6 @@ public static BlobBaseClient GetBlobBaseClient( /// New encryption options. Setting this to default will clear client-side encryption. /// New instance with provided options and same internals otherwise. public static BlobClient WithClientSideEncryptionOptions(this BlobClient client, ClientSideEncryptionOptions clientSideEncryptionOptions) - => new BlobClient( - client.Uri, - client.Pipeline, - client.Version, - client.ClientDiagnostics, - client.CustomerProvidedKey, - clientSideEncryptionOptions, - client.EncryptionScope); + => client.WithClientSideEncryptionOptionsCore(clientSideEncryptionOptions); } } diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs index 2a101ec841de..4e83b5ad338a 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs @@ -166,6 +166,9 @@ public BlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions opt /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// The version of the service to use when sending requests. /// @@ -176,12 +179,13 @@ public BlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions opt internal BlobClient( Uri blobUri, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, BlobClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey, ClientSideEncryptionOptions clientSideEncryption, string encryptionScope) - : base(blobUri, pipeline, version, clientDiagnostics, customerProvidedKey, clientSideEncryption, encryptionScope) + : base(blobUri, pipeline, storageSharedKeyCredential, version, clientDiagnostics, customerProvidedKey, clientSideEncryption, encryptionScope) { } #endregion ctors @@ -209,6 +213,7 @@ internal BlobClient( return new BlobClient( blobUriBuilder.ToUri(), Pipeline, + SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -238,6 +243,7 @@ internal BlobClient( return new BlobClient( blobUriBuilder.ToUri(), Pipeline, + SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -245,6 +251,25 @@ internal BlobClient( EncryptionScope); } + /// + /// Creates a new instance of the class, maintaining all the same + /// internals but specifying new . + /// + /// New encryption options. Setting this to default will clear client-side encryption. + /// New instance with provided options and same internals otherwise. + protected internal virtual BlobClient WithClientSideEncryptionOptionsCore(ClientSideEncryptionOptions clientSideEncryptionOptions) + { + return new BlobClient( + Uri, + Pipeline, + SharedKeyCredential, + Version, + ClientDiagnostics, + CustomerProvidedKey, + clientSideEncryptionOptions, + EncryptionScope); + } + #region Upload /// /// The operation creates a new block blob @@ -1231,7 +1256,7 @@ internal async Task> StagedUploadInternal( .ClientSideEncryptInternal(content, options.Metadata, async, cancellationToken).ConfigureAwait(false); } - var client = new BlockBlobClient(Uri, Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope); + var client = new BlockBlobClient(Uri, Pipeline, SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope); var uploader = GetPartitionedUploader( transferOptions: options?.TransferOptions ?? default, @@ -1316,7 +1341,7 @@ internal PartitionedUploader GetPartitionedU StorageTransferOptions transferOptions, ArrayPool arrayPool = null, string operationName = null) - => new BlockBlobClient(Uri, Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope) + => new BlockBlobClient(Uri, Pipeline, SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope) .GetPartitionedUploader(transferOptions, arrayPool, operationName); } } diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs index ca486f871fbd..c5ad098de46e 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobContainerClient.cs @@ -339,6 +339,9 @@ internal BlobContainerClient(Uri blobContainerUri, HttpPipelinePolicy authentica /// /// The version of the service to use when sending requests. /// + /// + /// The shared key credential used to sign requests. + /// /// /// Customer provided key. /// @@ -346,6 +349,7 @@ internal BlobContainerClient(Uri blobContainerUri, HttpPipelinePolicy authentica internal BlobContainerClient( Uri containerUri, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, BlobClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey, @@ -354,6 +358,7 @@ internal BlobContainerClient( { _uri = containerUri; _pipeline = pipeline; + _storageSharedKeyCredential = storageSharedKeyCredential; _version = version; _clientDiagnostics = clientDiagnostics; _customerProvidedKey = customerProvidedKey; @@ -388,6 +393,7 @@ protected static BlobContainerClient CreateClient(Uri containerUri, BlobClientOp return new BlobContainerClient( containerUri, pipeline, + null, options.Version, new ClientDiagnostics(options), customerProvidedKey: null, @@ -396,6 +402,32 @@ protected static BlobContainerClient CreateClient(Uri containerUri, BlobClientOp } #endregion ctor + /// + /// Create a new object by appending + /// to the end of . The + /// new uses the same request policy + /// pipeline as the . + /// + /// The name of the blob. + /// A new instance. + protected internal virtual BlobBaseClient GetBlobBaseClientCore(string blobName) + { + BlobUriBuilder blobUriBuilder = new BlobUriBuilder(Uri) + { + BlobName = blobName + }; + + return new BlobBaseClient( + blobUriBuilder.ToUri(), + _pipeline, + _storageSharedKeyCredential, + Version, + ClientDiagnostics, + CustomerProvidedKey, + ClientSideEncryption, + EncryptionScope); + } + /// /// Create a new object by appending /// to the end of . The @@ -414,6 +446,7 @@ public virtual BlobClient GetBlobClient(string blobName) return new BlobClient( blobUriBuilder.ToUri(), _pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -446,6 +479,7 @@ protected internal virtual BlockBlobClient GetBlockBlobClientCore(string blobNam return new BlockBlobClient( blobUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -477,6 +511,7 @@ protected internal virtual AppendBlobClient GetAppendBlobClientCore(string blobN return new AppendBlobClient( blobUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -508,6 +543,7 @@ protected internal virtual PageBlobClient GetPageBlobClientCore(string blobName) return new PageBlobClient( blobUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -3002,7 +3038,8 @@ protected internal virtual BlobServiceClient GetParentBlobServiceClientCore() CustomerProvidedKey, ClientSideEncryption, EncryptionScope, - Pipeline); + Pipeline, + _storageSharedKeyCredential); } return _parentBlobServiceClient; diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs index eac4119d65e7..fdabeb5b627f 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs @@ -330,7 +330,7 @@ internal BlobServiceClient( ClientSideEncryptionOptions clientSideEncryption, string encryptionScope, HttpPipeline pipeline, - StorageSharedKeyCredential storageSharedKeyCredential = default) + StorageSharedKeyCredential storageSharedKeyCredential) { _uri = serviceUri; _authenticationPolicy = authentication; @@ -384,7 +384,8 @@ protected static BlobServiceClient CreateClient( customerProvidedKey: null, clientSideEncryption: null, encryptionScope: null, - pipeline); + pipeline, + storageSharedKeyCredential: null); } #endregion ctors @@ -401,7 +402,15 @@ protected static BlobServiceClient CreateClient( /// A for the desired container. /// public virtual BlobContainerClient GetBlobContainerClient(string blobContainerName) => - new BlobContainerClient(Uri.AppendToPath(blobContainerName), Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, ClientSideEncryption, EncryptionScope); + new BlobContainerClient( + Uri.AppendToPath(blobContainerName), + Pipeline, + _storageSharedKeyCredential, + Version, + ClientDiagnostics, + CustomerProvidedKey, + ClientSideEncryption, + EncryptionScope); #region protected static accessors for Azure.Storage.Blobs.Batch /// diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs index b5d9b732fc1a..0c7fc755c97d 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs @@ -270,6 +270,9 @@ public BlockBlobClient(Uri blobUri, TokenCredential credential, BlobClientOption /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// The version of the service to use when sending requests. /// @@ -279,6 +282,7 @@ public BlockBlobClient(Uri blobUri, TokenCredential credential, BlobClientOption internal BlockBlobClient( Uri blobUri, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, BlobClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey, @@ -286,6 +290,7 @@ internal BlockBlobClient( : base( blobUri, pipeline, + storageSharedKeyCredential, version, clientDiagnostics, customerProvidedKey, @@ -316,7 +321,7 @@ internal BlockBlobClient( /// protected static BlockBlobClient CreateClient(Uri blobUri, BlobClientOptions options, HttpPipeline pipeline) { - return new BlockBlobClient(blobUri, pipeline, options.Version, new ClientDiagnostics(options), null, null); + return new BlockBlobClient(blobUri, pipeline, null, options.Version, new ClientDiagnostics(options), null, null); } private static void AssertNoClientSideEncryption(BlobClientOptions options) @@ -360,7 +365,7 @@ private static void AssertNoClientSideEncryption(BlobClientOptions options) public new BlockBlobClient WithVersion(string versionId) { var builder = new BlobUriBuilder(Uri) { VersionId = versionId }; - return new BlockBlobClient(builder.ToUri(), Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope); + return new BlockBlobClient(builder.ToUri(), Pipeline, SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope); } /// @@ -374,7 +379,7 @@ protected sealed override BlobBaseClient WithSnapshotCore(string snapshot) { var builder = new BlobUriBuilder(Uri) { Snapshot = snapshot }; - return new BlockBlobClient(builder.ToUri(), Pipeline, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope); + return new BlockBlobClient(builder.ToUri(), Pipeline, SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, EncryptionScope); } ///// diff --git a/sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs index 630e1390328b..5f1b50b68694 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/PageBlobClient.cs @@ -185,6 +185,9 @@ public PageBlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// The version of the service to use when sending requests. /// @@ -194,6 +197,7 @@ public PageBlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions internal PageBlobClient( Uri blobUri, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, BlobClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics, CustomerProvidedKey? customerProvidedKey, @@ -201,6 +205,7 @@ internal PageBlobClient( : base( blobUri, pipeline, + storageSharedKeyCredential, version, clientDiagnostics, customerProvidedKey, @@ -252,6 +257,7 @@ protected sealed override BlobBaseClient WithSnapshotCore(string snapshot) return new PageBlobClient( builder.ToUri(), Pipeline, + SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -272,7 +278,9 @@ protected sealed override BlobBaseClient WithSnapshotCore(string snapshot) }; return new PageBlobClient( - builder.ToUri(), Pipeline, + builder.ToUri(), + Pipeline, + SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, @@ -2578,6 +2586,7 @@ private async Task> StartCopyIncrementalInternal( PageBlobClient pageBlobUri = new PageBlobClient( sourceUri, Pipeline, + SharedKeyCredential, Version, ClientDiagnostics, CustomerProvidedKey, diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs index 2132e54edbe4..2775ed57aeb1 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs @@ -5770,6 +5770,150 @@ public void CanGenerateSas_ClientConstructors() Assert.IsFalse(blob5.CanGenerateSasUri); } + [Test] + public void CanGenerateSas_GetParentBlobContainerClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - BlobBaseClient(string connectionString, string blobContainerName, string blobName) + BlobBaseClient blob = new BlobBaseClient( + connectionString, + GetNewContainerName(), + GetNewBlobName()); + BlobContainerClient container = blob.GetParentBlobContainerClient(); + Assert.IsTrue(container.CanGenerateSasUri); + + // Act - BlobBaseClient(string connectionString, string blobContainerName, string blobName, BlobClientOptions options) + BlobBaseClient blob2 = new BlobBaseClient( + connectionString, + GetNewContainerName(), + GetNewBlobName(), + GetOptions()); + BlobContainerClient container2 = blob2.GetParentBlobContainerClient(); + Assert.IsTrue(container2.CanGenerateSasUri); + + // Act - BlobBaseClient(Uri blobContainerUri, BlobClientOptions options = default) + BlobBaseClient blob3 = new BlobBaseClient( + blobEndpoint, + GetOptions()); + BlobContainerClient container3 = blob3.GetParentBlobContainerClient(); + Assert.IsFalse(container3.CanGenerateSasUri); + + // Act - BlobBaseClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + BlobBaseClient blob4 = new BlobBaseClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + BlobContainerClient container4 = blob4.GetParentBlobContainerClient(); + Assert.IsTrue(container4.CanGenerateSasUri); + + // Act - BlobBaseClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + BlobBaseClient blob5 = new BlobBaseClient( + blobEndpoint, + tokenCredentials, + GetOptions()); + BlobContainerClient container5 = blob5.GetParentBlobContainerClient(); + Assert.IsFalse(container5.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_WithSnapshot_True() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Create blob + BlobBaseClient blob = new BlobBaseClient( + connectionString, + GetNewContainerName(), + GetNewBlobName()); + Assert.IsTrue(blob.CanGenerateSasUri); + + // Act + string snapshot = "2020-04-17T20:37:16.5129130Z"; + BlobBaseClient snapshotBlob = blob.WithSnapshot(snapshot); + + // Assert + Assert.IsTrue(snapshotBlob.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_WithSnapshot_False() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + + // Create blob + BlobBaseClient blob = new BlobBaseClient( + blobEndpoint, + GetOptions()); + Assert.IsFalse(blob.CanGenerateSasUri); + + // Act + string snapshot = "2020-04-17T20:37:16.5129130Z"; + BlobBaseClient snapshotBlob = blob.WithSnapshot(snapshot); + + // Assert + Assert.IsFalse(snapshotBlob.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_WithVersion_True() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Create blob + BlobBaseClient blob = new BlobBaseClient( + connectionString, + GetNewContainerName(), + GetNewBlobName()); + Assert.IsTrue(blob.CanGenerateSasUri); + + // Act + string version = "2020-04-17T21:55:48.6692074Z"; + BlobBaseClient versionBlob = blob.WithVersion(version); + + // Assert + Assert.IsTrue(versionBlob.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_WithVersion_False() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + + // Create blob + BlobBaseClient blob = new BlobBaseClient( + blobEndpoint, + GetOptions()); + Assert.IsFalse(blob.CanGenerateSasUri); + + // Act + string version = "2020-04-17T21:55:48.6692074Z"; + BlobBaseClient versionBlob = blob.WithVersion(version); + + // Assert + Assert.IsFalse(versionBlob.CanGenerateSasUri); + } + [Test] public void GenerateSas_RequiredParameters() { diff --git a/sdk/storage/Azure.Storage.Blobs/tests/BlobTestExtensions.cs b/sdk/storage/Azure.Storage.Blobs/tests/BlobTestExtensions.cs index b6e95cc8cb47..4df6517b7f1a 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/BlobTestExtensions.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/BlobTestExtensions.cs @@ -28,6 +28,7 @@ public static AppendBlobClient WithCustomerProvidedKey( new AppendBlobClient( ToHttps(blob.Uri), blob.Pipeline, + blob.SharedKeyCredential, blob.Version, blob.ClientDiagnostics, customerProvidedKey, @@ -40,6 +41,7 @@ public static AppendBlobClient WithEncryptionScope( new AppendBlobClient( ToHttps(blob.Uri), blob.Pipeline, + blob.SharedKeyCredential, blob.Version, blob.ClientDiagnostics, null, @@ -51,6 +53,7 @@ public static BlockBlobClient WithCustomerProvidedKey( new BlockBlobClient( ToHttps(blob.Uri), blob.Pipeline, + blob.SharedKeyCredential, blob.Version, blob.ClientDiagnostics, customerProvidedKey, @@ -63,6 +66,7 @@ public static BlockBlobClient WithEncryptionScope( new BlockBlobClient( ToHttps(blob.Uri), blob.Pipeline, + blob.SharedKeyCredential, blob.Version, blob.ClientDiagnostics, null, @@ -74,6 +78,7 @@ public static PageBlobClient WithCustomerProvidedKey( new PageBlobClient( ToHttps(blob.Uri), blob.Pipeline, + blob.SharedKeyCredential, blob.Version, blob.ClientDiagnostics, customerProvidedKey, @@ -86,6 +91,7 @@ public static PageBlobClient WithEncryptionScope( new PageBlobClient( ToHttps(blob.Uri), blob.Pipeline, + blob.SharedKeyCredential, blob.Version, blob.ClientDiagnostics, null, diff --git a/sdk/storage/Azure.Storage.Blobs/tests/ClientSideEncryptionTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/ClientSideEncryptionTests.cs index edf0caef60ea..dbcd4f996dd0 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/ClientSideEncryptionTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/ClientSideEncryptionTests.cs @@ -17,6 +17,7 @@ using Azure.Storage.Blobs.Tests; using Azure.Storage.Cryptography; using Azure.Storage.Cryptography.Models; +using Azure.Storage.Test; using Azure.Storage.Test.Shared; using Moq; using NUnit.Framework; @@ -721,5 +722,63 @@ await encryptedBlobClient.UploadAsync( Assert.AreNotEqual(firstDownloadEncryptionData, downloadResult.Value.Details.Metadata[Constants.ClientSideEncryption.EncryptionDataKey]); } } + + [Test] + public void CanGenerateSas_WithClientSideEncryptionOptions_True() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + var options = new ClientSideEncryptionOptions(ClientSideEncryptionVersion.V1_0) + { + KeyEncryptionKey = GetIKeyEncryptionKey().Object, + KeyResolver = GetIKeyEncryptionKeyResolver(default).Object, + KeyWrapAlgorithm = "bar" + }; + + // Create blob + BlobClient blob = new BlobClient( + connectionString, + GetNewContainerName(), + GetNewBlobName()); + Assert.IsTrue(blob.CanGenerateSasUri); + + // Act + BlobClient blobEncrypted = blob.WithClientSideEncryptionOptions(options); + + // Assert + Assert.IsTrue(blobEncrypted.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_WithClientSideEncryptionOptions_False() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + + var options = new ClientSideEncryptionOptions(ClientSideEncryptionVersion.V1_0) + { + KeyEncryptionKey = GetIKeyEncryptionKey().Object, + KeyResolver = GetIKeyEncryptionKeyResolver(default).Object, + KeyWrapAlgorithm = "bar" + }; + + // Create blob + BlobClient blob = new BlobClient( + blobEndpoint, + GetOptions()); + Assert.IsFalse(blob.CanGenerateSasUri); + + // Act + BlobClient blobEncrypted = blob.WithClientSideEncryptionOptions(options); + + // Assert + Assert.IsFalse(blobEncrypted.CanGenerateSasUri); + } } } diff --git a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs index 394b3a5104cf..4eccf61145ef 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/ContainerClientTests.cs @@ -2641,6 +2641,106 @@ public void CanGenerateSas_ClientConstructors() Assert.IsFalse(container5.CanGenerateSasUri); } + [Test] + public void CanGenerateSas_GetBlobClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - BlobContainerClient(string connectionString, string blobContainerName) + BlobContainerClient container = new BlobContainerClient( + connectionString, + GetNewContainerName()); + BlobBaseClient blob = container.GetBlobBaseClient(GetNewBlobName()); + Assert.IsTrue(blob.CanGenerateSasUri); + + // Act - BlobContainerClient(string connectionString, string blobContainerName, BlobClientOptions options) + BlobContainerClient container2 = new BlobContainerClient( + connectionString, + GetNewContainerName(), + GetOptions()); + BlobBaseClient blob2 = container2.GetBlobBaseClient(GetNewBlobName()); + Assert.IsTrue(blob2.CanGenerateSasUri); + + // Act - BlobContainerClient(Uri blobContainerUri, BlobClientOptions options = default) + BlobContainerClient container3 = new BlobContainerClient( + blobEndpoint, + GetOptions()); + BlobBaseClient blob3 = container3.GetBlobBaseClient(GetNewBlobName()); + Assert.IsFalse(blob3.CanGenerateSasUri); + + // Act - BlobContainerClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + BlobContainerClient container4 = new BlobContainerClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + BlobBaseClient blob4 = container4.GetBlobBaseClient(GetNewBlobName()); + Assert.IsTrue(blob4.CanGenerateSasUri); + + // Act - BlobContainerClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + BlobContainerClient container5 = new BlobContainerClient( + blobEndpoint, + tokenCredentials, + GetOptions()); + BlobBaseClient blob5 = container5.GetBlobBaseClient(GetNewBlobName()); + Assert.IsFalse(blob5.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_GetParentServiceClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - BlobContainerClient(string connectionString, string blobContainerName) + BlobContainerClient container = new BlobContainerClient( + connectionString, + GetNewContainerName()); + BlobServiceClient service = container.GetParentBlobServiceClient(); + Assert.IsTrue(service.CanGenerateAccountSasUri); + + // Act - BlobContainerClient(string connectionString, string blobContainerName, BlobClientOptions options) + BlobContainerClient container2 = new BlobContainerClient( + connectionString, + GetNewContainerName(), + GetOptions()); + BlobServiceClient service2 = container2.GetParentBlobServiceClient(); + Assert.IsTrue(service2.CanGenerateAccountSasUri); + + // Act - BlobContainerClient(Uri blobContainerUri, BlobClientOptions options = default) + BlobContainerClient container3 = new BlobContainerClient( + blobEndpoint, + GetOptions()); + BlobServiceClient service3 = container3.GetParentBlobServiceClient(); + Assert.IsFalse(service3.CanGenerateAccountSasUri); + + // Act - BlobContainerClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + BlobContainerClient container4 = new BlobContainerClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + BlobServiceClient service4 = container4.GetParentBlobServiceClient(); + Assert.IsTrue(service4.CanGenerateAccountSasUri); + + // Act - BlobContainerClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + BlobContainerClient container5 = new BlobContainerClient( + blobEndpoint, + tokenCredentials, + GetOptions()); + BlobServiceClient service5 = container5.GetParentBlobServiceClient(); + Assert.IsFalse(service5.CanGenerateAccountSasUri); + } + [Test] public void GenerateSas_RequiredParameters() { diff --git a/sdk/storage/Azure.Storage.Blobs/tests/ServiceClientTests.cs b/sdk/storage/Azure.Storage.Blobs/tests/ServiceClientTests.cs index fa5d6d24895e..1f7cef27e21d 100644 --- a/sdk/storage/Azure.Storage.Blobs/tests/ServiceClientTests.cs +++ b/sdk/storage/Azure.Storage.Blobs/tests/ServiceClientTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Azure.Core.TestFramework; using Azure.Identity; @@ -729,6 +728,55 @@ public void CanGenerateSas_ClientConstructors() Assert.IsFalse(container5.CanGenerateAccountSasUri); } + [Test] + public void CanGenerateSas_GetContainerClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Check if we're passing the SharedKeyCredential correctly to the containerClient + // Act - BlobServiceClient(string connectionString) + BlobServiceClient serviceClient = new BlobServiceClient( + connectionString); + BlobContainerClient containerClient = serviceClient.GetBlobContainerClient(GetNewContainerName()); + Assert.IsTrue(containerClient.CanGenerateSasUri); + + // Act - BlobServiceClient(string connectionString, string blobContainerName, BlobClientOptions options) + BlobServiceClient serviceClient2 = new BlobServiceClient( + connectionString, + GetOptions()); + BlobContainerClient containerClient2 = serviceClient2.GetBlobContainerClient(GetNewContainerName()); + Assert.IsTrue(containerClient2.CanGenerateSasUri); + + // Act - BlobServiceClient(Uri blobContainerUri, BlobClientOptions options = default) + BlobServiceClient serviceClient3 = new BlobServiceClient( + blobEndpoint, + GetOptions()); + BlobContainerClient containerClient3 = serviceClient3.GetBlobContainerClient(GetNewContainerName()); + Assert.IsFalse(containerClient3.CanGenerateSasUri); + + // Act - BlobServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + BlobServiceClient serviceClient4 = new BlobServiceClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + BlobContainerClient containerClient4 = serviceClient4.GetBlobContainerClient(GetNewContainerName()); + Assert.IsTrue(containerClient4.CanGenerateSasUri); + + // Act - BlobServiceClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + BlobServiceClient serviceClient5 = new BlobServiceClient( + blobEndpoint, + tokenCredentials, + GetOptions()); + BlobContainerClient containerClient5 = serviceClient5.GetBlobContainerClient(GetNewContainerName()); + Assert.IsFalse(containerClient5.CanGenerateSasUri); + } + [Test] public void GenerateAccountSas_RequiredParameters() { diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_GetParentBlobContainerClient.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_GetParentBlobContainerClient.json new file mode 100644 index 000000000000..9dbea34c6b6e --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_GetParentBlobContainerClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:05.7928538-08:00", + "RandomSeed": "715413478" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_GetParentBlobContainerClientAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_GetParentBlobContainerClientAsync.json new file mode 100644 index 000000000000..85149210ab3a --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_GetParentBlobContainerClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:24.1553069-08:00", + "RandomSeed": "1634359990" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_False.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_False.json new file mode 100644 index 000000000000..54e35002646e --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_False.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:05.8564071-08:00", + "RandomSeed": "1952525841" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_FalseAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_FalseAsync.json new file mode 100644 index 000000000000..1fdf4271993f --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_FalseAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:24.2239393-08:00", + "RandomSeed": "2136049969" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_True.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_True.json new file mode 100644 index 000000000000..ec80378c49e6 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_True.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:05.8592834-08:00", + "RandomSeed": "694572079" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_TrueAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_TrueAsync.json new file mode 100644 index 000000000000..bf05163fa115 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithSnapshot_TrueAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:24.2271101-08:00", + "RandomSeed": "141063331" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_False.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_False.json new file mode 100644 index 000000000000..0b9383d8084b --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_False.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:05.8618775-08:00", + "RandomSeed": "328222041" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_FalseAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_FalseAsync.json new file mode 100644 index 000000000000..a5311356aef7 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_FalseAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:24.2296495-08:00", + "RandomSeed": "726324327" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_True.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_True.json new file mode 100644 index 000000000000..242e14acef12 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_True.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:05.8643983-08:00", + "RandomSeed": "295604707" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_TrueAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_TrueAsync.json new file mode 100644 index 000000000000..4e6f3d54cda2 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/CanGenerateSas_WithVersion_TrueAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:24.2324148-08:00", + "RandomSeed": "1269038168" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_False.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_False.json new file mode 100644 index 000000000000..c727ba309795 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_False.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T10:36:14.6498420-08:00", + "RandomSeed": "1782943879" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_FalseAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_FalseAsync.json new file mode 100644 index 000000000000..5a7c4cdaade6 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_FalseAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T10:36:14.8585940-08:00", + "RandomSeed": "418547543" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_True.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_True.json new file mode 100644 index 000000000000..985eb6bcf93b --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_True.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T10:28:23.1409850-08:00", + "RandomSeed": "1909558580" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_TrueAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_TrueAsync.json new file mode 100644 index 000000000000..4d5a5a0fe73d --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_TrueAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T10:28:23.3511461-08:00", + "RandomSeed": "1828014544" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetBlobClient.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetBlobClient.json new file mode 100644 index 000000000000..ca7064b2dd8c --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetBlobClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:43.5834391-08:00", + "RandomSeed": "1043428533" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetBlobClientAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetBlobClientAsync.json new file mode 100644 index 000000000000..87c79462e635 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetBlobClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:57.8000306-08:00", + "RandomSeed": "278310243" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetParentServiceClient.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetParentServiceClient.json new file mode 100644 index 000000000000..39375e090e08 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetParentServiceClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:43.6459731-08:00", + "RandomSeed": "1312296080" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetParentServiceClientAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetParentServiceClientAsync.json new file mode 100644 index 000000000000..4b8921864ec2 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ContainerClientTests/CanGenerateSas_GetParentServiceClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:39:57.8729754-08:00", + "RandomSeed": "192293735" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetContainerClient.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetContainerClient.json new file mode 100644 index 000000000000..96f5a9c53f86 --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetContainerClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:40:16.6277538-08:00", + "RandomSeed": "2047033499" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetContainerClientAsync.json b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetContainerClientAsync.json new file mode 100644 index 000000000000..024616573cdd --- /dev/null +++ b/sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetContainerClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-24T13:40:30.8692227-08:00", + "RandomSeed": "225733080" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md b/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md index c56e4f1a4887..431fdcb97f3e 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Files.DataLake/CHANGELOG.md @@ -1,7 +1,7 @@ # Release History ## 12.6.0-beta.1 (Unreleased) - +- Fixed bug where DataLakeServiceClient.GetFileSystemClient(), DataLakeFileSystemClient.GetFileClient(), DataLakeFileSystemClient.GetDirectoryClient(), DataLakeDirectoryClient.GetSubDirectoryClient() and DataLakeFileClient.GetFileClient() created clients that could not generate a SAS from clients that could generate a SAS ## 12.5.0 (2020-11-10) - Includes all features from 12.5.0-preview.1 diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs index 022b89102319..21168df99785 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeDirectoryClient.cs @@ -206,12 +206,14 @@ internal DataLakeDirectoryClient( Uri fileSystemUri, string directoryPath, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, DataLakeClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics) : base( fileSystemUri, directoryPath, pipeline, + storageSharedKeyCredential, version, clientDiagnostics) { @@ -231,6 +233,7 @@ public virtual DataLakeFileClient GetFileClient(string fileName) Uri, $"{Path}/{fileName}", Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics); @@ -247,6 +250,7 @@ public virtual DataLakeDirectoryClient GetSubDirectoryClient(string subdirectory Uri, $"{Path}/{subdirectoryName}", Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics); diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs index b21e6337d65f..406311c9e7a9 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs @@ -223,12 +223,14 @@ internal DataLakeFileClient( Uri fileSystemUri, string filePath, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, DataLakeClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics) : base( fileSystemUri, filePath, pipeline, + storageSharedKeyCredential, version, clientDiagnostics) { diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileSystemClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileSystemClient.cs index 7048c1fe9abe..4f8ecad42434 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileSystemClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileSystemClient.cs @@ -298,6 +298,9 @@ internal DataLakeFileSystemClient( /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// The version of the service to use when sending requests. /// @@ -305,13 +308,19 @@ internal DataLakeFileSystemClient( /// The instance used to create /// diagnostic scopes every request. /// - internal DataLakeFileSystemClient(Uri fileSystemUri, HttpPipeline pipeline, DataLakeClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics) + internal DataLakeFileSystemClient( + Uri fileSystemUri, + HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, + DataLakeClientOptions.ServiceVersion version, + ClientDiagnostics clientDiagnostics) { DataLakeUriBuilder uriBuilder = new DataLakeUriBuilder(fileSystemUri); _uri = fileSystemUri; _blobUri = uriBuilder.ToBlobUri(); _dfsUri = uriBuilder.ToDfsUri(); _pipeline = pipeline; + _storageSharedKeyCredential = storageSharedKeyCredential; _version = version; _clientDiagnostics = clientDiagnostics; _containerClient = BlobContainerClientInternals.Create(_blobUri, pipeline, Version.AsBlobsVersion(), _clientDiagnostics); @@ -360,6 +369,7 @@ public virtual DataLakeDirectoryClient GetDirectoryClient(string directoryName) Uri, directoryName, Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics); } @@ -389,6 +399,7 @@ public virtual DataLakeFileClient GetFileClient(string fileName) Uri, fileName, Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics); diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakePathClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakePathClient.cs index a066e29faa42..2b4624257b80 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakePathClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakePathClient.cs @@ -373,12 +373,19 @@ internal DataLakePathClient( /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// Optional client options that define the transport pipeline /// policies for authentication, retries, etc., that are applied to /// every request. /// - internal DataLakePathClient(Uri pathUri, HttpPipeline pipeline, DataLakeClientOptions options = default) + internal DataLakePathClient( + Uri pathUri, + HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, + DataLakeClientOptions options = default) { options ??= new DataLakeClientOptions(); var uriBuilder = new DataLakeUriBuilder(pathUri); @@ -386,6 +393,7 @@ internal DataLakePathClient(Uri pathUri, HttpPipeline pipeline, DataLakeClientOp _blobUri = uriBuilder.ToBlobUri(); _dfsUri = uriBuilder.ToDfsUri(); _pipeline = pipeline; + _storageSharedKeyCredential = storageSharedKeyCredential; _version = options.Version; _clientDiagnostics = new ClientDiagnostics(options); _blockBlobClient = BlockBlobClientInternals.Create(_blobUri, _pipeline, Version.AsBlobsVersion(), _clientDiagnostics); @@ -394,6 +402,7 @@ internal DataLakePathClient(Uri pathUri, HttpPipeline pipeline, DataLakeClientOp _fileSystemClient = new DataLakeFileSystemClient( uriBuilder.ToDfsUri(), _pipeline, + storageSharedKeyCredential, Version, ClientDiagnostics); } @@ -440,6 +449,7 @@ internal DataLakePathClient( _fileSystemClient = new DataLakeFileSystemClient( uriBuilder.ToDfsUri(), pipeline, + null, version, clientDiagnostics); } @@ -448,6 +458,7 @@ internal DataLakePathClient( Uri fileSystemUri, string directoryOrFilePath, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, DataLakeClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics) { @@ -459,6 +470,7 @@ internal DataLakePathClient( _blobUri = uriBuilder.ToBlobUri(); _dfsUri = uriBuilder.ToDfsUri(); _pipeline = pipeline; + _storageSharedKeyCredential = storageSharedKeyCredential; _version = version; _clientDiagnostics = clientDiagnostics; _blockBlobClient = BlockBlobClientInternals.Create( @@ -471,6 +483,7 @@ internal DataLakePathClient( _fileSystemClient = new DataLakeFileSystemClient( uriBuilder.ToDfsUri(), pipeline, + storageSharedKeyCredential, version, clientDiagnostics); } @@ -1685,7 +1698,7 @@ private async Task> RenameInternal( } // Build destPathClient - DataLakePathClient destPathClient = new DataLakePathClient(destUriBuilder.ToUri(), Pipeline); + DataLakePathClient destPathClient = new DataLakePathClient(destUriBuilder.ToUri(), Pipeline, _storageSharedKeyCredential); Response response = await DataLakeRestClient.Path.CreateAsync( clientDiagnostics: _clientDiagnostics, diff --git a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeServiceClient.cs b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeServiceClient.cs index 3df9d6a636b3..17ff5416704f 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeServiceClient.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeServiceClient.cs @@ -324,7 +324,7 @@ public static BlobServiceClient Create( /// A for the desired share. /// public virtual DataLakeFileSystemClient GetFileSystemClient(string fileSystemName) - => new DataLakeFileSystemClient(Uri.AppendToPath(fileSystemName), Pipeline, Version, ClientDiagnostics); + => new DataLakeFileSystemClient(Uri.AppendToPath(fileSystemName), Pipeline, _storageSharedKeyCredential, Version, ClientDiagnostics); #region Get User Delegation Key /// diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs index 6a012410651f..c16f1f3381aa 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/DirectoryClientTests.cs @@ -4866,6 +4866,70 @@ public void CanGenerateSas_ClientConstructors() Assert.IsFalse(directory3.CanGenerateSasUri); } + [Test] + public void CanGenerateSas_GetFileClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + + // Act - DataLakeDirectoryClient(Uri blobContainerUri, fileClientOptions options = default) + DataLakeDirectoryClient directory = new DataLakeDirectoryClient( + blobEndpoint, + GetOptions()); + DataLakeFileClient file = directory.GetFileClient(GetNewFileName()); + Assert.IsFalse(file.CanGenerateSasUri); + + // Act - DataLakeDirectoryClient(Uri blobContainerUri, StorageSharedKeyCredential credential, fileClientOptions options = default) + DataLakeDirectoryClient directory2 = new DataLakeDirectoryClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + DataLakeFileClient file2 = directory2.GetFileClient(GetNewFileName()); + Assert.IsTrue(file2.CanGenerateSasUri); + + // Act - DataLakeDirectoryClient(Uri blobContainerUri, TokenCredential credential, fileClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + DataLakeDirectoryClient directory3 = new DataLakeDirectoryClient( + blobEndpoint, + tokenCredentials, + GetOptions()); + DataLakeFileClient file3 = directory3.GetFileClient(GetNewFileName()); + Assert.IsFalse(file3.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_GetSubDirectoryClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + + // Act - DataLakeDirectoryClient(Uri blobContainerUri, fileClientOptions options = default) + DataLakeDirectoryClient directory = new DataLakeDirectoryClient( + blobEndpoint, + GetOptions()); + DataLakeDirectoryClient subdirectory = directory.GetSubDirectoryClient(GetNewDirectoryName()); + Assert.IsFalse(subdirectory.CanGenerateSasUri); + + // Act - DataLakeDirectoryClient(Uri blobContainerUri, StorageSharedKeyCredential credential, fileClientOptions options = default) + DataLakeDirectoryClient directory2 = new DataLakeDirectoryClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + DataLakeDirectoryClient subdirectory2 = directory2.GetSubDirectoryClient(GetNewDirectoryName()); + Assert.IsTrue(subdirectory2.CanGenerateSasUri); + + // Act - DataLakeDirectoryClient(Uri blobContainerUri, TokenCredential credential, fileClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + DataLakeDirectoryClient directory3 = new DataLakeDirectoryClient( + blobEndpoint, + tokenCredentials, + GetOptions()); + DataLakeDirectoryClient subdirectory3 = directory3.GetSubDirectoryClient(GetNewDirectoryName()); + Assert.IsFalse(subdirectory3.CanGenerateSasUri); + } + [Test] public void GenerateSas_RequiredParameters() { diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs index e93c2da85f0b..a4902021eac7 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs @@ -1975,25 +1975,95 @@ public void CanGenerateSas_ClientConstructors() string connectionString = storageConnectionString.ToString(true); // Act - DataLakeFileSystemClient(Uri blobContainerUri, BlobClientOptions options = default) - DataLakeFileSystemClient container3 = new DataLakeFileSystemClient( + DataLakeFileSystemClient filesystem = new DataLakeFileSystemClient( blobEndpoint, GetOptions()); - Assert.IsFalse(container3.CanGenerateSasUri); + Assert.IsFalse(filesystem.CanGenerateSasUri); // Act - DataLakeFileSystemClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) - DataLakeFileSystemClient container4 = new DataLakeFileSystemClient( + DataLakeFileSystemClient filesystem2 = new DataLakeFileSystemClient( blobEndpoint, constants.Sas.SharedKeyCredential, GetOptions()); - Assert.IsTrue(container4.CanGenerateSasUri); + Assert.IsTrue(filesystem2.CanGenerateSasUri); // Act - DataLakeFileSystemClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) var tokenCredentials = new DefaultAzureCredential(); - DataLakeFileSystemClient container5 = new DataLakeFileSystemClient( + DataLakeFileSystemClient filesystem3 = new DataLakeFileSystemClient( blobEndpoint, tokenCredentials, GetOptions()); - Assert.IsFalse(container5.CanGenerateSasUri); + Assert.IsFalse(filesystem3.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_GetFileClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - DataLakeFileSystemClient(Uri blobContainerUri, BlobClientOptions options = default) + DataLakeFileSystemClient filesystem = new DataLakeFileSystemClient( + blobEndpoint, + GetOptions()); + DataLakeFileClient file = filesystem.GetFileClient(GetNewFileName()); + Assert.IsFalse(file.CanGenerateSasUri); + + // Act - DataLakeFileSystemClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + DataLakeFileSystemClient filesystem2 = new DataLakeFileSystemClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + DataLakeFileClient file2 = filesystem2.GetFileClient(GetNewFileName()); + Assert.IsTrue(file2.CanGenerateSasUri); + + // Act - DataLakeFileSystemClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + DataLakeFileSystemClient filesystem3 = new DataLakeFileSystemClient( + blobEndpoint, + tokenCredentials, + GetOptions()); + DataLakeFileClient file3 = filesystem3.GetFileClient(GetNewFileName()); + Assert.IsFalse(file3.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_GetDirectoryClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - DataLakeFileSystemClient(Uri blobContainerUri, BlobClientOptions options = default) + DataLakeFileSystemClient filesystem = new DataLakeFileSystemClient( + blobEndpoint, + GetOptions()); + DataLakeDirectoryClient directory = filesystem.GetDirectoryClient(GetNewDirectoryName()); + Assert.IsFalse(directory.CanGenerateSasUri); + + // Act - DataLakeFileSystemClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + DataLakeFileSystemClient filesystem2 = new DataLakeFileSystemClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + DataLakeDirectoryClient directory2 = filesystem2.GetDirectoryClient(GetNewDirectoryName()); + Assert.IsTrue(directory2.CanGenerateSasUri); + + // Act - DataLakeFileSystemClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + DataLakeFileSystemClient filesystem3 = new DataLakeFileSystemClient( + blobEndpoint, + tokenCredentials, + GetOptions()); + DataLakeDirectoryClient directory3 = filesystem3.GetDirectoryClient(GetNewDirectoryName()); + Assert.IsFalse(directory3.CanGenerateSasUri); } [Test] diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/ServiceClientTests.cs b/sdk/storage/Azure.Storage.Files.DataLake/tests/ServiceClientTests.cs index 25d775c0c3a2..5e3391bac3f4 100644 --- a/sdk/storage/Azure.Storage.Files.DataLake/tests/ServiceClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/ServiceClientTests.cs @@ -285,6 +285,40 @@ public void CanGenerateSas_ClientConstructors() Assert.IsFalse(serviceClient3.CanGenerateAccountSasUri); } + [Test] + public void CanGenerateSas_GetFileSystemClient() + { + // Arrange + var constants = new TestConstants(this); + var uriEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (uriEndpoint, blobSecondaryEndpoint)); + + // Act - DataLakeServiceClient(Uri blobContainerUri, BlobClientOptions options = default) + DataLakeServiceClient serviceClient = new DataLakeServiceClient( + uriEndpoint, + GetOptions()); + DataLakeFileSystemClient fileSystemClient = serviceClient.GetFileSystemClient(GetNewFileSystemName()); + Assert.IsFalse(fileSystemClient.CanGenerateSasUri); + + // Act - DataLakeServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + DataLakeServiceClient serviceClient2 = new DataLakeServiceClient( + uriEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + DataLakeFileSystemClient fileSystemClient2 = serviceClient2.GetFileSystemClient(GetNewFileSystemName()); + Assert.IsTrue(fileSystemClient2.CanGenerateSasUri); + + // Act - DataLakeServiceClient(Uri blobContainerUri, TokenCredential credential, BlobClientOptions options = default) + var tokenCredentials = new DefaultAzureCredential(); + DataLakeServiceClient serviceClient3 = new DataLakeServiceClient( + uriEndpoint, + tokenCredentials, + GetOptions()); + DataLakeFileSystemClient fileSystemClient3 = serviceClient3.GetFileSystemClient(GetNewFileSystemName()); + Assert.IsFalse(fileSystemClient3.CanGenerateSasUri); + } + [Test] public void GenerateSas_RequiredParameters() { diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClient.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClient.json new file mode 100644 index 000000000000..e6aefed73be3 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:49:04.6494434-08:00", + "RandomSeed": "209130536" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClientAsync.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClientAsync.json new file mode 100644 index 000000000000..6adbc7715a7f --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:49:18.7359509-08:00", + "RandomSeed": "2129166567" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubDirectoryClient.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubDirectoryClient.json new file mode 100644 index 000000000000..b39938817446 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubDirectoryClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:49:04.7090879-08:00", + "RandomSeed": "1015702674" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubDirectoryClientAsync.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubDirectoryClientAsync.json new file mode 100644 index 000000000000..0086bc95ec91 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubDirectoryClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:49:18.8030736-08:00", + "RandomSeed": "811451308" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetDirectoryClient.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetDirectoryClient.json new file mode 100644 index 000000000000..8b03f7294042 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetDirectoryClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:49:38.6110352-08:00", + "RandomSeed": "2144647754" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetDirectoryClientAsync.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetDirectoryClientAsync.json new file mode 100644 index 000000000000..1c0850e79bbf --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetDirectoryClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:49:49.5003040-08:00", + "RandomSeed": "1840895128" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetFileClient.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetFileClient.json new file mode 100644 index 000000000000..13ec6a105a0d --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetFileClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:49:38.6719793-08:00", + "RandomSeed": "710189255" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetFileClientAsync.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetFileClientAsync.json new file mode 100644 index 000000000000..736a03bb00da --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/CanGenerateSas_GetFileClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:49:49.5585743-08:00", + "RandomSeed": "712856573" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetFileSystemClient.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetFileSystemClient.json new file mode 100644 index 000000000000..0596603de1fa --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetFileSystemClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:50:00.3058191-08:00", + "RandomSeed": "386561537" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetFileSystemClientAsync.json b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetFileSystemClientAsync.json new file mode 100644 index 000000000000..8d3c8bb22710 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetFileSystemClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-25T10:50:00.3646133-08:00", + "RandomSeed": "989414557" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md b/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md index 8d21e49df4c8..801dd6be8f82 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md @@ -1,7 +1,7 @@ # Release History ## 12.6.0-beta.1 (Unreleased) - +- Fixed bug where ShareServiceClient.GetShareClient(), ShareClient.GetDirectoryClient(), ShareClient.GetRootDirectoryClient(), ShareClient.WithSnapshot(), ShareDirectoryClient.GetSubDirectoryClient() and ShareDirectoryClient.GetFileClient() created clients that could not generate a SAS from clients that could generate a SAS ## 12.5.0 (2020-11-10) - Includes all features from 12.5.0-preview.1 diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs index 18885f3e3dab..b2c4416b6a82 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs @@ -258,6 +258,9 @@ internal ShareClient( /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// The version of the service to use when sending requests. /// @@ -265,10 +268,16 @@ internal ShareClient( /// The instance used to create /// diagnostic scopes every request. /// - internal ShareClient(Uri shareUri, HttpPipeline pipeline, ShareClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics) + internal ShareClient( + Uri shareUri, + HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, + ShareClientOptions.ServiceVersion version, + ClientDiagnostics clientDiagnostics) { _uri = shareUri; _pipeline = pipeline; + _storageSharedKeyCredential = storageSharedKeyCredential; _version = version; _clientDiagnostics = clientDiagnostics; } @@ -295,7 +304,7 @@ internal ShareClient(Uri shareUri, HttpPipeline pipeline, ShareClientOptions.Ser public virtual ShareClient WithSnapshot(string snapshot) { var p = new ShareUriBuilder(Uri) { Snapshot = snapshot }; - return new ShareClient(p.ToUri(), Pipeline, Version, ClientDiagnostics); + return new ShareClient(p.ToUri(), Pipeline, _storageSharedKeyCredential, Version, ClientDiagnostics); } /// @@ -315,6 +324,7 @@ public virtual ShareDirectoryClient GetDirectoryClient(string directoryName) return new ShareDirectoryClient( shareUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics); } diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareDirectoryClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareDirectoryClient.cs index 5bf41f8afecb..dc0c0e4a5f74 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareDirectoryClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareDirectoryClient.cs @@ -302,6 +302,9 @@ internal ShareDirectoryClient( /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// The version of the service to use when sending requests. /// @@ -309,11 +312,17 @@ internal ShareDirectoryClient( /// The instance used to create /// diagnostic scopes every request. /// - internal ShareDirectoryClient(Uri directoryUri, HttpPipeline pipeline, ShareClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics) + internal ShareDirectoryClient( + Uri directoryUri, + HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, + ShareClientOptions.ServiceVersion version, + ClientDiagnostics clientDiagnostics) { _uri = directoryUri; _pipeline = pipeline; _version = version; + _storageSharedKeyCredential = storageSharedKeyCredential; _clientDiagnostics = clientDiagnostics; } #endregion ctors @@ -339,7 +348,12 @@ internal ShareDirectoryClient(Uri directoryUri, HttpPipeline pipeline, ShareClie public virtual ShareDirectoryClient WithSnapshot(string snapshot) { var p = new ShareUriBuilder(Uri) { Snapshot = snapshot }; - return new ShareDirectoryClient(p.ToUri(), Pipeline, Version, ClientDiagnostics); + return new ShareDirectoryClient( + p.ToUri(), + Pipeline, + _storageSharedKeyCredential, + Version, + ClientDiagnostics); } /// @@ -357,6 +371,7 @@ public virtual ShareFileClient GetFileClient(string fileName) return new ShareFileClient( shareUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics); } @@ -376,6 +391,7 @@ public virtual ShareDirectoryClient GetSubdirectoryClient(string subdirectoryNam return new ShareDirectoryClient( shareUriBuilder.ToUri(), Pipeline, + _storageSharedKeyCredential, Version, ClientDiagnostics); } diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs index f2ae75dbd1e7..fdec99fb207d 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareFileClient.cs @@ -312,6 +312,9 @@ internal ShareFileClient( /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// The version of the service to use when sending requests. /// @@ -319,10 +322,16 @@ internal ShareFileClient( /// The instance used to create /// diagnostic scopes every request. /// - internal ShareFileClient(Uri fileUri, HttpPipeline pipeline, ShareClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics) + internal ShareFileClient( + Uri fileUri, + HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, + ShareClientOptions.ServiceVersion version, + ClientDiagnostics clientDiagnostics) { _uri = fileUri; _pipeline = pipeline; + _storageSharedKeyCredential = storageSharedKeyCredential; _version = version; _clientDiagnostics = clientDiagnostics; } @@ -349,7 +358,7 @@ internal ShareFileClient(Uri fileUri, HttpPipeline pipeline, ShareClientOptions. public virtual ShareFileClient WithSnapshot(string shareSnapshot) { var builder = new ShareUriBuilder(Uri) { Snapshot = shareSnapshot }; - return new ShareFileClient(builder.ToUri(), Pipeline, Version, ClientDiagnostics); + return new ShareFileClient(builder.ToUri(), Pipeline, _storageSharedKeyCredential, Version, ClientDiagnostics); } /// diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/ShareServiceClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/ShareServiceClient.cs index 6ae387076c58..ccd7fd21fd48 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/ShareServiceClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/ShareServiceClient.cs @@ -235,7 +235,7 @@ internal ShareServiceClient( /// A for the desired share. /// public virtual ShareClient GetShareClient(string shareName) => - new ShareClient(Uri.AppendToPath(shareName), Pipeline, Version, ClientDiagnostics); + new ShareClient(Uri.AppendToPath(shareName), Pipeline, _storageSharedKeyCredential, Version, ClientDiagnostics); #region GetShares /// diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs index 362ae42c7a5f..bf57349478a3 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/DirectoryClientTests.cs @@ -9,12 +9,11 @@ using Azure.Core.TestFramework; using Azure.Identity; using Azure.Storage.Files.Shares.Models; -using Azure.Storage.Files.Shares.Tests; using Azure.Storage.Sas; using Azure.Storage.Test; using NUnit.Framework; -namespace Azure.Storage.Files.Shares.Test +namespace Azure.Storage.Files.Shares.Tests { public class DirectoryClientTests : FileTestBase { @@ -1156,6 +1155,92 @@ public void CanGenerateSas_ClientConstructors() Assert.IsTrue(directory4.CanGenerateSasUri); } + [Test] + public void CanGenerateSas_GetFileClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, fileStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - ShareDirectoryClient(string connectionString, string blobContainerName, string blobName) + ShareDirectoryClient directory = new ShareDirectoryClient( + connectionString, + GetNewShareName(), + GetNewDirectoryName()); + ShareFileClient file = directory.GetFileClient(GetNewFileName()); + Assert.IsTrue(file.CanGenerateSasUri); + + // Act - ShareDirectoryClient(string connectionString, string blobContainerName, string blobName, BlobClientOptions options) + ShareDirectoryClient directory2 = new ShareDirectoryClient( + connectionString, + GetNewShareName(), + GetNewDirectoryName(), + GetOptions()); + ShareFileClient file2 = directory2.GetFileClient(GetNewFileName()); + Assert.IsTrue(file2.CanGenerateSasUri); + + // Act - ShareDirectoryClient(Uri blobContainerUri, BlobClientOptions options = default) + ShareDirectoryClient directory3 = new ShareDirectoryClient( + blobEndpoint, + GetOptions()); + ShareFileClient file3 = directory3.GetFileClient(GetNewFileName()); + Assert.IsFalse(file3.CanGenerateSasUri); + + // Act - ShareDirectoryClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + ShareDirectoryClient directory4 = new ShareDirectoryClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + ShareFileClient file4 = directory4.GetFileClient(GetNewFileName()); + Assert.IsTrue(file4.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_GetSubdirectoryClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, fileStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - ShareDirectoryClient(string connectionString, string blobContainerName, string blobName) + ShareDirectoryClient directory = new ShareDirectoryClient( + connectionString, + GetNewShareName(), + GetNewDirectoryName()); + ShareDirectoryClient subdirectory = directory.GetSubdirectoryClient(GetNewFileName()); + Assert.IsTrue(subdirectory.CanGenerateSasUri); + + // Act - ShareDirectoryClient(string connectionString, string blobContainerName, string blobName, BlobClientOptions options) + ShareDirectoryClient directory2 = new ShareDirectoryClient( + connectionString, + GetNewShareName(), + GetNewDirectoryName(), + GetOptions()); + ShareDirectoryClient subdirectory2 = directory2.GetSubdirectoryClient(GetNewFileName()); + Assert.IsTrue(subdirectory2.CanGenerateSasUri); + + // Act - ShareDirectoryClient(Uri blobContainerUri, BlobClientOptions options = default) + ShareDirectoryClient directory3 = new ShareDirectoryClient( + blobEndpoint, + GetOptions()); + ShareDirectoryClient subdirectory3 = directory3.GetSubdirectoryClient(GetNewFileName()); + Assert.IsFalse(subdirectory3.CanGenerateSasUri); + + // Act - ShareDirectoryClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + ShareDirectoryClient directory4 = new ShareDirectoryClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + ShareDirectoryClient subdirectory4 = directory4.GetSubdirectoryClient(GetNewFileName()); + Assert.IsTrue(subdirectory4.CanGenerateSasUri); + } + [Test] public void GenerateSas_RequiredParameters() { diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/FileSasBuilderTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/FileSasBuilderTests.cs index 4e7218883f4c..f5388e282a59 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/FileSasBuilderTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/FileSasBuilderTests.cs @@ -3,13 +3,12 @@ using System; using System.Threading.Tasks; -using Azure.Storage.Files.Shares.Tests; using Azure.Storage.Sas; using Azure.Storage.Test; using NUnit.Framework; using TestConstants = Azure.Storage.Test.TestConstants; -namespace Azure.Storage.Files.Shares.Test +namespace Azure.Storage.Files.Shares.Tests { public class FileSasBuilderTests : FileTestBase { diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/FileUriBuilderTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/FileUriBuilderTests.cs index 8d8c0ee63902..b190940fbe2f 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/FileUriBuilderTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/FileUriBuilderTests.cs @@ -4,12 +4,11 @@ using System; using System.Net; using Azure.Core.TestFramework; -using Azure.Storage.Files.Shares.Tests; using Azure.Storage.Sas; using Azure.Storage.Test; using NUnit.Framework; -namespace Azure.Storage.Files.Shares.Test +namespace Azure.Storage.Files.Shares.Tests { public class FileUriBuilderTests : FileTestBase { diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/ServiceClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/ServiceClientTests.cs index c2841c88d353..2cf8e017f697 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/ServiceClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/ServiceClientTests.cs @@ -7,12 +7,11 @@ using System.Threading.Tasks; using Azure.Core.TestFramework; using Azure.Storage.Files.Shares.Models; -using Azure.Storage.Files.Shares.Tests; using Azure.Storage.Sas; using Azure.Storage.Test; using NUnit.Framework; -namespace Azure.Storage.Files.Shares.Test +namespace Azure.Storage.Files.Shares.Tests { public class ServiceClientTests : FileTestBase { @@ -413,6 +412,45 @@ public void CanGenerateSas_ClientConstructors() Assert.IsTrue(share4.CanGenerateAccountSasUri); } + [Test] + public void CanGenerateSas_GetShareClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, fileStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - ShareServiceClient(string connectionString) + ShareServiceClient service = new ShareServiceClient( + connectionString); + ShareClient share = service.GetShareClient(GetNewShareName()); + Assert.IsTrue(share.CanGenerateSasUri); + + // Act - ShareServiceClient(string connectionString, string blobContainerName, BlobClientOptions options) + ShareServiceClient service2 = new ShareServiceClient( + connectionString, + GetOptions()); + ShareClient share2 = service2.GetShareClient(GetNewShareName()); + Assert.IsTrue(share2.CanGenerateSasUri); + + // Act - ShareServiceClient(Uri blobContainerUri, BlobClientOptions options = default) + ShareServiceClient service3 = new ShareServiceClient( + blobEndpoint, + GetOptions()); + ShareClient share3 = service3.GetShareClient(GetNewShareName()); + Assert.IsFalse(share3.CanGenerateSasUri); + + // Act - ShareServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + ShareServiceClient service4 = new ShareServiceClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + ShareClient share4 = service4.GetShareClient(GetNewShareName()); + Assert.IsTrue(share4.CanGenerateSasUri); + } + [Test] public void GenerateAccountSas_RequiredParameters() { diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClient.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClient.json new file mode 100644 index 000000000000..b319b963a25c --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:18.6679085-08:00", + "RandomSeed": "70017518" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClientAsync.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClientAsync.json new file mode 100644 index 000000000000..112bf5612524 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetFileClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:18.7254882-08:00", + "RandomSeed": "1722183284" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubdirectoryClient.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubdirectoryClient.json new file mode 100644 index 000000000000..4ee143ca7c52 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubdirectoryClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:18.7186152-08:00", + "RandomSeed": "1221506342" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubdirectoryClientAsync.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubdirectoryClientAsync.json new file mode 100644 index 000000000000..a96d06fffa67 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/DirectoryClientTests/CanGenerateSas_GetSubdirectoryClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:18.7277641-08:00", + "RandomSeed": "142652003" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetShareClient.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetShareClient.json new file mode 100644 index 000000000000..d1ee5689b209 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetShareClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:34.5755757-08:00", + "RandomSeed": "1751476515" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetShareClientAsync.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetShareClientAsync.json new file mode 100644 index 000000000000..0d73281e9f9f --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetShareClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:34.6334943-08:00", + "RandomSeed": "1857881418" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetDirectoryClient.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetDirectoryClient.json new file mode 100644 index 000000000000..ab0a4518e3e5 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetDirectoryClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:44.6016307-08:00", + "RandomSeed": "1496766426" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetDirectoryClientAsync.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetDirectoryClientAsync.json new file mode 100644 index 000000000000..aa9a754b3f09 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetDirectoryClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:44.6690119-08:00", + "RandomSeed": "2065789603" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetRootDirectoryClient.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetRootDirectoryClient.json new file mode 100644 index 000000000000..b88a56226d81 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetRootDirectoryClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:44.6605518-08:00", + "RandomSeed": "2045322264" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetRootDirectoryClientAsync.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetRootDirectoryClientAsync.json new file mode 100644 index 000000000000..75da2b02e7ef --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_GetRootDirectoryClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:21:44.6719737-08:00", + "RandomSeed": "5206209" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_False.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_False.json new file mode 100644 index 000000000000..9846156a4400 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_False.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T17:01:24.3329824-08:00", + "RandomSeed": "2051206815" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_FalseAsync.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_FalseAsync.json new file mode 100644 index 000000000000..5c566000e19f --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_FalseAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T17:01:24.6131587-08:00", + "RandomSeed": "599376017" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_True.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_True.json new file mode 100644 index 000000000000..4e15a142e022 --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_True.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T17:03:10.4173222-08:00", + "RandomSeed": "853145177" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_TrueAsync.json b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_TrueAsync.json new file mode 100644 index 000000000000..c3a46143c56f --- /dev/null +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/SessionRecords/ShareClientTests/CanGenerateSas_WithSnapshot_TrueAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T17:03:10.5514063-08:00", + "RandomSeed": "127229778" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs index c67fa385e01f..96a25e4cf18f 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/ShareClientTests.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Azure.Core.TestFramework; using Azure.Storage.Files.Shares.Models; -using Azure.Storage.Files.Shares.Tests; using Azure.Storage.Files.Shares.Specialized; using Azure.Storage.Sas; using Azure.Storage.Test; @@ -17,7 +16,7 @@ using System.Threading; using Azure.Identity; -namespace Azure.Storage.Files.Shares.Test +namespace Azure.Storage.Files.Shares.Tests { public class ShareClientTests : FileTestBase { @@ -2014,6 +2013,133 @@ public void CanGenerateSas_ClientConstructors() Assert.IsTrue(container4.CanGenerateSasUri); } + [Test] + public void CanGenerateSas_GetRootDirectoryClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, fileStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - ShareClient(string connectionString, string blobContainerName) + ShareClient share = new ShareClient( + connectionString, + GetNewShareName()); + ShareDirectoryClient directory = share.GetRootDirectoryClient(); + Assert.IsTrue(directory.CanGenerateSasUri); + + // Act - ShareClient(string connectionString, string blobContainerName, BlobClientOptions options) + ShareClient share2 = new ShareClient( + connectionString, + GetNewShareName(), + GetOptions()); + ShareDirectoryClient directory2 = share.GetRootDirectoryClient(); + Assert.IsTrue(directory2.CanGenerateSasUri); + + // Act - ShareClient(Uri blobContainerUri, BlobClientOptions options = default) + ShareClient share3 = new ShareClient( + blobEndpoint, + GetOptions()); + ShareDirectoryClient directory3 = share3.GetRootDirectoryClient(); + Assert.IsFalse(directory3.CanGenerateSasUri); + + // Act - ShareClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + ShareClient share4 = new ShareClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + ShareDirectoryClient directory4 = share4.GetRootDirectoryClient(); + Assert.IsTrue(directory4.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_GetDirectoryClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, fileStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - ShareClient(string connectionString, string blobContainerName) + ShareClient share = new ShareClient( + connectionString, + GetNewShareName()); + ShareDirectoryClient directory = share.GetDirectoryClient(GetNewDirectoryName()); + Assert.IsTrue(directory.CanGenerateSasUri); + + // Act - ShareClient(string connectionString, string blobContainerName, BlobClientOptions options) + ShareClient share2 = new ShareClient( + connectionString, + GetNewShareName(), + GetOptions()); + ShareDirectoryClient directory2 = share.GetDirectoryClient(GetNewDirectoryName()); + Assert.IsTrue(directory2.CanGenerateSasUri); + + // Act - ShareClient(Uri blobContainerUri, BlobClientOptions options = default) + ShareClient share3 = new ShareClient( + blobEndpoint, + GetOptions()); + ShareDirectoryClient directory3 = share3.GetDirectoryClient(GetNewDirectoryName()); + Assert.IsFalse(directory3.CanGenerateSasUri); + + // Act - ShareClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + ShareClient share4 = new ShareClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + ShareDirectoryClient directory4 = share4.GetDirectoryClient(GetNewDirectoryName()); + Assert.IsTrue(directory4.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_WithSnapshot_False() + { + // Arrange + var constants = new TestConstants(this); + var shareEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + + // Create blob + ShareClient share = new ShareClient( + shareEndpoint, + GetOptions()); + Assert.IsFalse(share.CanGenerateSasUri); + + // Act + string snapshot = "2020-04-17T20:37:16.5129130Z"; + ShareClient snapshotShare = share.WithSnapshot(snapshot); + + // Assert + Assert.IsFalse(snapshotShare.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_WithSnapshot_True() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Create blob + ShareClient share = new ShareClient( + connectionString, + GetNewShareName()); + Assert.IsTrue(share.CanGenerateSasUri); + + // Act + string snapshot = "2020-04-17T20:37:16.5129130Z"; + ShareClient snapshotShare = share.WithSnapshot(snapshot); + + // Assert + Assert.IsTrue(snapshotShare.CanGenerateSasUri); + } + [Test] public void GenerateSas_RequiredParameters() { diff --git a/sdk/storage/Azure.Storage.Files.Shares/tests/UnitTests.cs b/sdk/storage/Azure.Storage.Files.Shares/tests/UnitTests.cs index 6aa3fb01503e..c93f8684f5e5 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/tests/UnitTests.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/tests/UnitTests.cs @@ -5,7 +5,7 @@ using Azure.Storage.Files.Shares.Models; using NUnit.Framework; -namespace Azure.Storage.Files.Shares.Test +namespace Azure.Storage.Files.Shares.Tests { public class UnitTests { diff --git a/sdk/storage/Azure.Storage.Queues/CHANGELOG.md b/sdk/storage/Azure.Storage.Queues/CHANGELOG.md index 87dff14f900b..1c491e656078 100644 --- a/sdk/storage/Azure.Storage.Queues/CHANGELOG.md +++ b/sdk/storage/Azure.Storage.Queues/CHANGELOG.md @@ -1,7 +1,7 @@ # Release History ## 12.6.0-beta.1 (Unreleased) - +- Fixed bug where QueueServiceClient.GetQueueClient() and QueueClient.WithClientSideEncryptionOptions() created clients that could not generate a SAS from clients that could generate a SAS ## 12.5.0 (2020-11-10) - Includes all features from 12.5.0-preview.1 diff --git a/sdk/storage/Azure.Storage.Queues/api/Azure.Storage.Queues.netstandard2.0.cs b/sdk/storage/Azure.Storage.Queues/api/Azure.Storage.Queues.netstandard2.0.cs index 7f31f9d62fb8..894aa995bd78 100644 --- a/sdk/storage/Azure.Storage.Queues/api/Azure.Storage.Queues.netstandard2.0.cs +++ b/sdk/storage/Azure.Storage.Queues/api/Azure.Storage.Queues.netstandard2.0.cs @@ -63,6 +63,7 @@ public QueueClient(System.Uri queueUri, Azure.Storage.StorageSharedKeyCredential public virtual Azure.Response UpdateMessage(string messageId, string popReceipt, string messageText = null, System.TimeSpan visibilityTimeout = default(System.TimeSpan), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> UpdateMessageAsync(string messageId, string popReceipt, System.BinaryData message, System.TimeSpan visibilityTimeout = default(System.TimeSpan), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> UpdateMessageAsync(string messageId, string popReceipt, string messageText = null, System.TimeSpan visibilityTimeout = default(System.TimeSpan), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + protected internal virtual Azure.Storage.Queues.QueueClient WithClientSideEncryptionOptionsCore(Azure.Storage.ClientSideEncryptionOptions clientSideEncryptionOptions) { throw null; } } public partial class QueueClientOptions : Azure.Core.ClientOptions { diff --git a/sdk/storage/Azure.Storage.Queues/src/QueueClient.cs b/sdk/storage/Azure.Storage.Queues/src/QueueClient.cs index 66d229ccf5a8..730b3f9d2155 100644 --- a/sdk/storage/Azure.Storage.Queues/src/QueueClient.cs +++ b/sdk/storage/Azure.Storage.Queues/src/QueueClient.cs @@ -333,6 +333,9 @@ internal QueueClient( /// /// The transport pipeline used to send every request. /// + /// + /// The shared key credential used to sign requests. + /// /// /// The version of the service to use when sending requests. /// @@ -349,6 +352,7 @@ internal QueueClient( internal QueueClient( Uri queueUri, HttpPipeline pipeline, + StorageSharedKeyCredential storageSharedKeyCredential, QueueClientOptions.ServiceVersion version, ClientDiagnostics clientDiagnostics, ClientSideEncryptionOptions encryptionOptions, @@ -357,6 +361,7 @@ internal QueueClient( _uri = queueUri; _messagesUri = queueUri.AppendToPath(Constants.Queue.MessagesUri); _pipeline = pipeline; + _storageSharedKeyCredential = storageSharedKeyCredential; _version = version; _clientDiagnostics = clientDiagnostics; _clientSideEncryption = QueueClientSideEncryptionOptions.CloneFrom(encryptionOptions); @@ -378,6 +383,24 @@ private void SetNameFieldsIfNull() } } + /// + /// Creates a new instance of the class, maintaining all the same + /// internals but specifying new . + /// + /// New encryption options. Setting this to default will clear client-side encryption. + /// New instance with provided options and same internals otherwise. + protected internal virtual QueueClient WithClientSideEncryptionOptionsCore(ClientSideEncryptionOptions clientSideEncryptionOptions) + { + return new QueueClient( + Uri, + Pipeline, + _storageSharedKeyCredential, + Version, + ClientDiagnostics, + clientSideEncryptionOptions, + MessageEncoding); + } + #region Create /// /// Creates a queue. @@ -2718,12 +2741,6 @@ public static partial class SpecializedQueueExtensions /// New encryption options. Setting this to default will clear client-side encryption. /// New instance with provided options and same internals otherwise. public static QueueClient WithClientSideEncryptionOptions(this QueueClient client, ClientSideEncryptionOptions clientSideEncryptionOptions) - => new QueueClient( - client.Uri, - client.Pipeline, - client.Version, - client.ClientDiagnostics, - clientSideEncryptionOptions, - client.MessageEncoding); + => client.WithClientSideEncryptionOptionsCore(clientSideEncryptionOptions); } } diff --git a/sdk/storage/Azure.Storage.Queues/src/QueueServiceClient.cs b/sdk/storage/Azure.Storage.Queues/src/QueueServiceClient.cs index dd3efc0b7c9d..9329db1b8a63 100644 --- a/sdk/storage/Azure.Storage.Queues/src/QueueServiceClient.cs +++ b/sdk/storage/Azure.Storage.Queues/src/QueueServiceClient.cs @@ -275,7 +275,7 @@ internal QueueServiceClient( /// A for the desired queue. /// public virtual QueueClient GetQueueClient(string queueName) - => new QueueClient(Uri.AppendToPath(queueName), Pipeline, Version, ClientDiagnostics, ClientSideEncryption, MessageEncoding); + => new QueueClient(Uri.AppendToPath(queueName), Pipeline, _storageSharedKeyCredential, Version, ClientDiagnostics, ClientSideEncryption, MessageEncoding); #region GetQueues /// diff --git a/sdk/storage/Azure.Storage.Queues/tests/ClientSideEncryptionTests.cs b/sdk/storage/Azure.Storage.Queues/tests/ClientSideEncryptionTests.cs index e52dc1c66080..d1ab1a798529 100644 --- a/sdk/storage/Azure.Storage.Queues/tests/ClientSideEncryptionTests.cs +++ b/sdk/storage/Azure.Storage.Queues/tests/ClientSideEncryptionTests.cs @@ -18,6 +18,7 @@ using Azure.Storage.Queues.Specialized; using Azure.Storage.Queues.Specialized.Models; using Azure.Storage.Queues.Tests; +using Azure.Storage.Test; using Moq; using NUnit.Framework; using static Moq.It; @@ -733,5 +734,62 @@ public async Task CannotFindKeyAsync(bool useListener, bool resolverThrows, bool } } } + + [Test] + public void CanGenerateSas_WithClientSideEncryptionOptions_True() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, blobStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + var options = new ClientSideEncryptionOptions(ClientSideEncryptionVersion.V1_0) + { + KeyEncryptionKey = GetIKeyEncryptionKey().Object, + KeyResolver = GetIKeyEncryptionKeyResolver(default).Object, + KeyWrapAlgorithm = "bar" + }; + + // Create blob + QueueClient queue = new QueueClient( + connectionString, + GetNewQueueName()); + Assert.IsTrue(queue.CanGenerateSasUri); + + // Act + QueueClient queueEncrypted = queue.WithClientSideEncryptionOptions(options); + + // Assert + Assert.IsTrue(queueEncrypted.CanGenerateSasUri); + } + + [Test] + public void CanGenerateSas_WithClientSideEncryptionOptions_False() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + + var options = new ClientSideEncryptionOptions(ClientSideEncryptionVersion.V1_0) + { + KeyEncryptionKey = GetIKeyEncryptionKey().Object, + KeyResolver = GetIKeyEncryptionKeyResolver(default).Object, + KeyWrapAlgorithm = "bar" + }; + + // Create blob + QueueClient queue = new QueueClient( + blobEndpoint, + GetOptions()); + Assert.IsFalse(queue.CanGenerateSasUri); + + // Act + QueueClient queueEncrypted = queue.WithClientSideEncryptionOptions(options); + + // Assert + Assert.IsFalse(queueEncrypted.CanGenerateSasUri); + } } } diff --git a/sdk/storage/Azure.Storage.Queues/tests/ServiceClientTests.cs b/sdk/storage/Azure.Storage.Queues/tests/ServiceClientTests.cs index 90042cfcc4f2..cd39b3962978 100644 --- a/sdk/storage/Azure.Storage.Queues/tests/ServiceClientTests.cs +++ b/sdk/storage/Azure.Storage.Queues/tests/ServiceClientTests.cs @@ -341,28 +341,67 @@ public void CanGenerateSas_ClientConstructors() string connectionString = storageConnectionString.ToString(true); // Act - QueueServiceClient(string connectionString) - QueueServiceClient share = new QueueServiceClient( + QueueServiceClient serviceClient = new QueueServiceClient( connectionString); - Assert.IsTrue(share.CanGenerateAccountSasUri); + Assert.IsTrue(serviceClient.CanGenerateAccountSasUri); // Act - QueueServiceClient(string connectionString, string blobContainerName, BlobClientOptions options) - QueueServiceClient share2 = new QueueServiceClient( + QueueServiceClient serviceClient2 = new QueueServiceClient( connectionString, GetOptions()); - Assert.IsTrue(share2.CanGenerateAccountSasUri); + Assert.IsTrue(serviceClient2.CanGenerateAccountSasUri); // Act - QueueServiceClient(Uri blobContainerUri, BlobClientOptions options = default) - QueueServiceClient share3 = new QueueServiceClient( + QueueServiceClient serviceClient3 = new QueueServiceClient( blobEndpoint, GetOptions()); - Assert.IsFalse(share3.CanGenerateAccountSasUri); + Assert.IsFalse(serviceClient3.CanGenerateAccountSasUri); // Act - QueueServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) - QueueServiceClient share4 = new QueueServiceClient( + QueueServiceClient serviceClient4 = new QueueServiceClient( blobEndpoint, constants.Sas.SharedKeyCredential, GetOptions()); - Assert.IsTrue(share4.CanGenerateAccountSasUri); + Assert.IsTrue(serviceClient4.CanGenerateAccountSasUri); + } + + [Test] + public void CanGenerateSas_GetQueueClient() + { + // Arrange + var constants = new TestConstants(this); + var blobEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account); + var blobSecondaryEndpoint = new Uri("https://127.0.0.1/" + constants.Sas.Account + "-secondary"); + var storageConnectionString = new StorageConnectionString(constants.Sas.SharedKeyCredential, queueStorageUri: (blobEndpoint, blobSecondaryEndpoint)); + string connectionString = storageConnectionString.ToString(true); + + // Act - QueueServiceClient(string connectionString) + QueueServiceClient serviceClient = new QueueServiceClient( + connectionString); + QueueClient queueClient = serviceClient.GetQueueClient(GetNewQueueName()); + Assert.IsTrue(queueClient.CanGenerateSasUri); + + // Act - QueueServiceClient(string connectionString, string blobContainerName, BlobClientOptions options) + QueueServiceClient serviceClient2 = new QueueServiceClient( + connectionString, + GetOptions()); + QueueClient queueClient2 = serviceClient2.GetQueueClient(GetNewQueueName()); + Assert.IsTrue(queueClient2.CanGenerateSasUri); + + // Act - QueueServiceClient(Uri blobContainerUri, BlobClientOptions options = default) + QueueServiceClient serviceClient3 = new QueueServiceClient( + blobEndpoint, + GetOptions()); + QueueClient queueClient3 = serviceClient3.GetQueueClient(GetNewQueueName()); + Assert.IsFalse(queueClient3.CanGenerateSasUri); + + // Act - QueueServiceClient(Uri blobContainerUri, StorageSharedKeyCredential credential, BlobClientOptions options = default) + QueueServiceClient serviceClient4 = new QueueServiceClient( + blobEndpoint, + constants.Sas.SharedKeyCredential, + GetOptions()); + QueueClient queueClient4 = serviceClient4.GetQueueClient(GetNewQueueName()); + Assert.IsTrue(queueClient4.CanGenerateSasUri); } [Test] diff --git a/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_False.json b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_False.json new file mode 100644 index 000000000000..2ecb7528d219 --- /dev/null +++ b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_False.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-12-01T09:26:06.1626380-08:00", + "RandomSeed": "2050111808" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_FalseAsync.json b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_FalseAsync.json new file mode 100644 index 000000000000..ed6ea065f839 --- /dev/null +++ b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_FalseAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T10:39:11.5143802-08:00", + "RandomSeed": "1638354842" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_True.json b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_True.json new file mode 100644 index 000000000000..8f8e891d9ad1 --- /dev/null +++ b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_True.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-12-01T09:26:06.3382030-08:00", + "RandomSeed": "2033659194" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_TrueAsync.json b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_TrueAsync.json new file mode 100644 index 000000000000..f68e39875f44 --- /dev/null +++ b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ClientSideEncryptionTests/CanGenerateSas_WithClientSideEncryptionOptions_TrueAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T10:39:11.6990506-08:00", + "RandomSeed": "125925766" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetQueueClient.json b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetQueueClient.json new file mode 100644 index 000000000000..e35846c52aeb --- /dev/null +++ b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetQueueClient.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:40:21.9445475-08:00", + "RandomSeed": "755353916" + } +} \ No newline at end of file diff --git a/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetQueueClientAsync.json b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetQueueClientAsync.json new file mode 100644 index 000000000000..5bd7b99d19c9 --- /dev/null +++ b/sdk/storage/Azure.Storage.Queues/tests/SessionRecords/ServiceClientTests/CanGenerateSas_GetQueueClientAsync.json @@ -0,0 +1,7 @@ +{ + "Entries": [], + "Variables": { + "DateTimeOffsetNow": "2020-11-30T09:40:21.9965148-08:00", + "RandomSeed": "2024139133" + } +} \ No newline at end of file