|
11 | 11 | using System.Threading; |
12 | 12 | using System.Threading.Tasks; |
13 | 13 | using Azure.Core; |
| 14 | +using Azure.Core.Pipeline; |
14 | 15 | using Azure.Core.TestFramework; |
15 | 16 | using Azure.Identity; |
16 | 17 | using Azure.Storage.Blobs.Models; |
17 | 18 | using Azure.Storage.Blobs.Specialized; |
18 | 19 | using Azure.Storage.Blobs.Tests; |
| 20 | +using Azure.Storage.Common; |
19 | 21 | using Azure.Storage.Sas; |
20 | 22 | using Azure.Storage.Shared; |
21 | 23 | using Azure.Storage.Test; |
22 | 24 | using Azure.Storage.Test.Shared; |
| 25 | +using Azure.Storage.Tests; |
23 | 26 | using Moq; |
24 | 27 | using Moq.Protected; |
25 | 28 | using NUnit.Framework; |
@@ -441,6 +444,67 @@ public void ctor_BlobContainerClient_clientSideEncryptionOptions() |
441 | 444 | Assert.NotNull(client.ClientSideEncryption); |
442 | 445 | } |
443 | 446 |
|
| 447 | + [Test] |
| 448 | + public void Ctor_FromConfig( |
| 449 | + [Values( |
| 450 | + StorageAuthType.None, |
| 451 | + StorageAuthType.StorageSharedKey, |
| 452 | + StorageAuthType.Token, |
| 453 | + StorageAuthType.Sas)] StorageAuthType authType) |
| 454 | + { |
| 455 | + StorageSharedKeyCredential sharedKeyCred = |
| 456 | + authType == StorageAuthType.StorageSharedKey ? new("", "") : null; |
| 457 | + TokenCredential tokenCred = |
| 458 | + authType == StorageAuthType.Token ? new DefaultAzureCredential() : null; |
| 459 | + AzureSasCredential sasCred = |
| 460 | + authType == StorageAuthType.Sas ? new("?foo=bar") : null; |
| 461 | + |
| 462 | + BlobClientOptions options = new(); |
| 463 | + BlobContainerClient container = new( |
| 464 | + new Uri("https://example.blob.core.windows.net"), |
| 465 | + new BlobClientConfiguration( |
| 466 | + options.Build(authType switch |
| 467 | + { |
| 468 | + StorageAuthType.StorageSharedKey => sharedKeyCred, |
| 469 | + StorageAuthType.Token => tokenCred, |
| 470 | + StorageAuthType.Sas => sasCred, |
| 471 | + _ => null, |
| 472 | + }), |
| 473 | + sharedKeyCred, |
| 474 | + tokenCred, |
| 475 | + sasCred, |
| 476 | + new ClientDiagnostics(options), |
| 477 | + _serviceVersion, |
| 478 | + customerProvidedKey: default, |
| 479 | + transferValidation: null, |
| 480 | + encryptionScope: null, |
| 481 | + trimBlobNameSlashes: default), |
| 482 | + null); |
| 483 | + |
| 484 | + Assert.That(container.ClientConfiguration.SharedKeyCredential, |
| 485 | + authType == StorageAuthType.StorageSharedKey ? Is.EqualTo(sharedKeyCred) : Is.Null); |
| 486 | + Assert.That(container.ClientConfiguration.TokenCredential, |
| 487 | + authType == StorageAuthType.Token ? Is.EqualTo(tokenCred) : Is.Null); |
| 488 | + Assert.That(container.ClientConfiguration.SasCredential, |
| 489 | + authType == StorageAuthType.Sas ? Is.EqualTo(sasCred) : Is.Null); |
| 490 | + |
| 491 | + switch (authType) |
| 492 | + { |
| 493 | + case StorageAuthType.None: |
| 494 | + Assert.That(container.AuthenticationPolicy, Is.Null); |
| 495 | + break; |
| 496 | + case StorageAuthType.StorageSharedKey: |
| 497 | + Assert.That(container.AuthenticationPolicy, Is.TypeOf<StorageSharedKeyPipelinePolicy>()); |
| 498 | + break; |
| 499 | + case StorageAuthType.Token: |
| 500 | + Assert.That(container.AuthenticationPolicy, Is.TypeOf<StorageBearerTokenChallengeAuthorizationPolicy>()); |
| 501 | + break; |
| 502 | + case StorageAuthType.Sas: |
| 503 | + Assert.That(container.AuthenticationPolicy, Is.TypeOf<AzureSasCredentialSynchronousPolicy>()); |
| 504 | + break; |
| 505 | + } |
| 506 | + } |
| 507 | + |
444 | 508 | [RecordedTest] |
445 | 509 | public async Task CreateAsync_WithSharedKey() |
446 | 510 | { |
|
0 commit comments