Skip to content

Commit adf401e

Browse files
authored
Fix endpoint suffix (Azure China) not being used (#10112)
1 parent 5a08b79 commit adf401e

2 files changed

Lines changed: 43 additions & 24 deletions

File tree

src/Ng/CommandHelpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ private static CatalogStorageFactory CreateStorageFactoryImpl(
214214
var storageAccountName = arguments.GetOrThrow<string>(argumentNameMap[Arguments.StorageAccountName]);
215215
var storageContainer = arguments.GetOrThrow<string>(argumentNameMap[Arguments.StorageContainer]);
216216
var storagePath = arguments.GetOrDefault<string>(argumentNameMap[Arguments.StoragePath]);
217-
var storageSuffix = arguments.GetOrDefault<string>(argumentNameMap[Arguments.StorageSuffix]);
217+
var storageSuffix = arguments.GetOrDefault(argumentNameMap[Arguments.StorageSuffix], "core.windows.net");
218218
var storageOperationMaxExecutionTime = MaxExecutionTime(arguments.GetOrDefault<int>(argumentNameMap[Arguments.StorageOperationMaxExecutionTimeInSeconds]));
219219
var storageServerTimeout = MaxExecutionTime(arguments.GetOrDefault<int>(argumentNameMap[Arguments.StorageServerTimeoutInSeconds]));
220220
var storageUseServerSideCopy = arguments.GetOrDefault<bool>(argumentNameMap[Arguments.StorageUseServerSideCopy]);
221-
var storageInitializeContainer = arguments.GetOrDefault<bool>(argumentNameMap[Arguments.StorageInitializeContainer], defaultValue: true);
221+
var storageInitializeContainer = arguments.GetOrDefault(argumentNameMap[Arguments.StorageInitializeContainer], defaultValue: true);
222222

223223
BlobServiceClient account = GetBlobServiceClient(storageAccountName, storageSuffix, arguments, argumentNameMap);
224224

@@ -382,7 +382,7 @@ private static BlobServiceClient GetBlobServiceClient(string storageAccountName,
382382
storageSasValue = storageSasValue.Substring(1);
383383
}
384384

385-
connectionString = $"BlobEndpoint=https://{storageAccountName}.blob.core.windows.net/;SharedAccessSignature={storageSasValue}";
385+
connectionString = $"BlobEndpoint=https://{storageAccountName}.blob.{endpointSuffix}/;SharedAccessSignature={storageSasValue}";
386386
}
387387
else
388388
{
@@ -401,7 +401,7 @@ private static QueueServiceClient GetQueueServiceClient(string storageAccountNam
401401
if (string.IsNullOrEmpty(storageKeyValue))
402402
{
403403
var storageSasValue = arguments.GetOrThrow<string>(argumentNameMap[Arguments.StorageSasValue]);
404-
connectionString = $"BlobEndpoint=https://{storageAccountName}.blob.core.windows.net/;SharedAccessSignature={storageSasValue}";
404+
connectionString = $"BlobEndpoint=https://{storageAccountName}.blob.{endpointSuffix}/;SharedAccessSignature={storageSasValue}";
405405
}
406406
else
407407
{
Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
@@ -11,33 +11,52 @@ namespace NgTests
1111
{
1212
public class StorageFactoryTests
1313
{
14-
[Theory]
15-
[Description("The regular azure factory should not compress the content if.")]
16-
[InlineData("http://localhost/reg", "testAccount", "DummyDUMMYpZxLeDumMyyN52gJj+ZlGE0ipRi9PaTcn9AU4epwvsngE5rLSMk9TwpazxUtzeyBnFeWFAdummyw==", "testContainer", "testStoragePath", "azure", "core.windows.net")]
17-
public void AzureFactory(string storageBaseAddress,
18-
string storageAccountName,
19-
string storageKeyValue,
20-
string storageContainer,
21-
string storagePath,
22-
string storageType,
23-
string storageSuffix)
14+
private const string DummyKey = "DummyDUMMYpZxLeDumMyyN52gJj+ZlGE0ipRi9PaTcn9AU4epwvsngE5rLSMk9TwpazxUtzeyBnFeWFAdummyw==";
15+
16+
[Fact]
17+
public void AzureFactory_DefaultsToAzurePublicWithNoCompression()
2418
{
19+
// Arrange
2520
Dictionary<string, string> arguments = new Dictionary<string, string>()
2621
{
27-
{ Arguments.StorageBaseAddress, storageBaseAddress },
28-
{ Arguments.StorageAccountName, storageAccountName },
29-
{ Arguments.StorageKeyValue, storageKeyValue },
30-
{ Arguments.StorageContainer, storageContainer },
31-
{ Arguments.StoragePath, storagePath },
32-
{ Arguments.StorageType, storageType},
33-
{ Arguments.StorageSuffix, storageSuffix} // Without BlobServiceClient couldn't create new instance.
22+
{ Arguments.StorageBaseAddress, "http://localhost/reg" },
23+
{ Arguments.StorageAccountName, "testAccount" },
24+
{ Arguments.StorageKeyValue, DummyKey },
25+
{ Arguments.StorageContainer, "testContainer" },
26+
{ Arguments.StoragePath, "testStoragePath" },
27+
{ Arguments.StorageType, "azure" },
3428
};
3529

30+
// Act
3631
StorageFactory factory = CommandHelpers.CreateStorageFactory(arguments, true);
37-
AzureStorageFactory azureFactory = factory as AzureStorageFactory;
32+
3833
// Assert
39-
Assert.True(azureFactory != null, "The CreateCompressedStorageFactory should return an AzureStorageFactory type.");
34+
var azureFactory = Assert.IsType<AzureStorageFactory>(factory);
4035
Assert.False(azureFactory.CompressContent, "The azure storage factory should not compress the content.");
36+
Assert.Equal("https://testaccount.blob.core.windows.net/testContainer/testStoragePath/", azureFactory.DestinationAddress.AbsoluteUri);
37+
}
38+
39+
[Fact]
40+
public void AzureFactory_AllowsCustomStorageSuffix()
41+
{
42+
// Arrange
43+
Dictionary<string, string> arguments = new Dictionary<string, string>()
44+
{
45+
{ Arguments.StorageBaseAddress, "http://localhost/reg" },
46+
{ Arguments.StorageAccountName, "testAccount" },
47+
{ Arguments.StorageKeyValue, DummyKey },
48+
{ Arguments.StorageContainer, "testContainer" },
49+
{ Arguments.StoragePath, "testStoragePath" },
50+
{ Arguments.StorageType, "azure" },
51+
{ Arguments.StorageSuffix, "core.chinacloudapi.cn" },
52+
};
53+
54+
// Act
55+
StorageFactory factory = CommandHelpers.CreateStorageFactory(arguments, true);
56+
57+
// Assert
58+
var azureFactory = Assert.IsType<AzureStorageFactory>(factory);
59+
Assert.Equal("https://testaccount.blob.core.chinacloudapi.cn/testContainer/testStoragePath/", azureFactory.DestinationAddress.AbsoluteUri);
4160
}
4261
}
4362
}

0 commit comments

Comments
 (0)