Skip to content

Commit dfe6dba

Browse files
authored
Fix concurrent issue when Connect-AzAccount (#393)
* Fix concurrent issue when Connect-AzAccount * Add empty GalleryEndpoint case to environment test * Address review comments
1 parent 210dd3d commit dfe6dba

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed

src/Authentication.Abstractions.Test/AzureEnvironmentTests.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ public void TestArmCloudMetadata20220901Init()
6262
Assert.Equal(3, armEnvironments.Count);
6363
foreach (var env in armEnvironments.Values)
6464
{
65-
if (env.Name == "AzureCloud")
65+
if (env.Name == EnvironmentName.AzureCloud)
6666
{
6767
Assert.Equal(AzureEnvironment.TypeDiscovered, env.Type);
68+
Assert.Null(env.GalleryUrl);
6869
}
6970
else
7071
{
7172
Assert.Equal(AzureEnvironment.TypeBuiltIn, env.Type);
73+
Assert.NotEmpty(env.GalleryUrl);
7274
}
7375
Assert.EndsWith("/", env.ServiceManagementUrl);
7476
Assert.StartsWith(".", env.SqlDatabaseDnsSuffix);
@@ -127,5 +129,20 @@ public void TestDisableArmCloudMetadataInit()
127129
Assert.Equal(AzureEnvironment.TypeBuiltIn, env.Type);
128130
}
129131
}
132+
133+
[Fact]
134+
public void TestArmResponseWithEmptyGalleryEndpoint()
135+
{
136+
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData\ArmResponseWithEmptyGallery.json");
137+
var armEnvironments = AzureEnvironment.InitializeBuiltInEnvironments(null, httpOperations: TestOperationsFactory.Create().GetHttpOperations());
138+
139+
Assert.Equal(3, armEnvironments.Count);
140+
Assert.Equal(AzureEnvironment.TypeDiscovered, armEnvironments[EnvironmentName.AzureCloud].Type);
141+
Assert.Equal(AzureEnvironment.TypeDiscovered, armEnvironments[EnvironmentName.AzureChinaCloud].Type);
142+
Assert.Equal(AzureEnvironment.TypeDiscovered, armEnvironments[EnvironmentName.AzureUSGovernment].Type);
143+
Assert.Null(armEnvironments[EnvironmentName.AzureCloud].GalleryUrl);
144+
Assert.Empty(armEnvironments[EnvironmentName.AzureChinaCloud].GalleryUrl);
145+
Assert.Empty(armEnvironments[EnvironmentName.AzureUSGovernment].GalleryUrl);
146+
}
130147
}
131148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[
2+
{
3+
"portal": "https://portal.azure.com",
4+
"authentication": {
5+
"loginEndpoint": "https://login.microsoftonline.com/",
6+
"audiences": [
7+
"https://management.core.windows.net/",
8+
"https://management.azure.com/"
9+
],
10+
"tenant": "common",
11+
"identityProvider": "AAD"
12+
},
13+
"media": "https://rest.media.azure.net",
14+
"graphAudience": "https://graph.windows.net/",
15+
"graph": "https://graph.windows.net/",
16+
"name": "AzureCloud",
17+
"suffixes": {
18+
"azureDataLakeStoreFileSystem": "azuredatalakestore.net",
19+
"acrLoginServer": "azurecr.io",
20+
"sqlServerHostname": "database.windows.net",
21+
"azureDataLakeAnalyticsCatalogAndJob": "azuredatalakeanalytics.net",
22+
"keyVaultDns": "vault.azure.net",
23+
"storage": "core.windows.net",
24+
"azureFrontDoorEndpointSuffix": "azurefd.net"
25+
},
26+
"batch": "https://batch.core.windows.net/",
27+
"resourceManager": "https://management.azure.com/",
28+
"vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json",
29+
"activeDirectoryDataLake": "https://datalake.azure.net/",
30+
"sqlManagement": "https://management.core.windows.net:8443/"
31+
},
32+
{
33+
"portal": "https://portal.azure.cn",
34+
"authentication": {
35+
"loginEndpoint": "https://login.chinacloudapi.cn",
36+
"audiences": [
37+
"https://management.core.chinacloudapi.cn",
38+
"https://management.chinacloudapi.cn"
39+
],
40+
"tenant": "common",
41+
"identityProvider": "AAD"
42+
},
43+
"media": "https://rest.media.chinacloudapi.cn",
44+
"graphAudience": "https://graph.chinacloudapi.cn",
45+
"graph": "https://graph.chinacloudapi.cn",
46+
"name": "AzureChinaCloud",
47+
"suffixes": {
48+
"acrLoginServer": "azurecr.cn",
49+
"sqlServerHostname": "database.chinacloudapi.cn",
50+
"keyVaultDns": "vault.azure.cn",
51+
"storage": "core.chinacloudapi.cn",
52+
"azureFrontDoorEndpointSuffix": ""
53+
},
54+
"batch": "https://batch.chinacloudapi.cn",
55+
"resourceManager": "https://management.chinacloudapi.cn",
56+
"vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json",
57+
"sqlManagement": "https://management.core.chinacloudapi.cn:8443",
58+
"gallery": ""
59+
},
60+
{
61+
"portal": "https://portal.azure.us",
62+
"authentication": {
63+
"loginEndpoint": "https://login.microsoftonline.us",
64+
"audiences": [
65+
"https://management.core.usgovcloudapi.net",
66+
"https://management.usgovcloudapi.net"
67+
],
68+
"tenant": "common",
69+
"identityProvider": "AAD"
70+
},
71+
"media": "https://rest.media.usgovcloudapi.net",
72+
"graphAudience": "https://graph.windows.net",
73+
"graph": "https://graph.windows.net",
74+
"name": "AzureUSGovernment",
75+
"suffixes": {
76+
"acrLoginServer": "azurecr.us",
77+
"sqlServerHostname": "database.usgovcloudapi.net",
78+
"keyVaultDns": "vault.usgovcloudapi.net",
79+
"storage": "core.usgovcloudapi.net",
80+
"azureFrontDoorEndpointSuffix": ""
81+
},
82+
"batch": "https://batch.core.usgovcloudapi.net",
83+
"resourceManager": "https://management.usgovcloudapi.net",
84+
"vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json",
85+
"sqlManagement": "https://management.core.usgovcloudapi.net:8443",
86+
"gallery": ""
87+
}
88+
]

src/Authentication.Abstractions/AzureEnvironment.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public AzureEnvironment(IAzureEnvironment other)
467467
/// <summary>
468468
/// Additional environment-specific metadata
469469
/// </summary>
470-
public IDictionary<string, string> ExtendedProperties { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
470+
public IDictionary<string, string> ExtendedProperties { get; } = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
471471

472472
public bool Equals(AzureEnvironment other)
473473
{

0 commit comments

Comments
 (0)