Skip to content

Commit 5f1d614

Browse files
authored
Add the Test Case to Verify All Environment Endpoints after Initialization (#21516)
* Add the Test Case to Verify All Environment Endpoints after Initialization * Upgrade common library versions
1 parent 13f1bb3 commit 5f1d614

File tree

4 files changed

+280
-17
lines changed

4 files changed

+280
-17
lines changed

src/Accounts/Accounts.Test/EnvironmentCmdletTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,39 @@ public void GetsAzureEnvironment()
546546
Assert.Single(environments);
547547
}
548548

549+
[Fact]
550+
[Trait(Category.AcceptanceType, Category.CheckIn)]
551+
public void GetsAllAzureEnvironments()
552+
{
553+
List<PSAzureEnvironment> environments = null;
554+
Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
555+
commandRuntimeMock.Setup(c => c.WriteObject(It.IsAny<object>(), It.IsAny<bool>()))
556+
.Callback<object, bool>((e, _) => environments = (List<PSAzureEnvironment>)e);
557+
558+
var cmdlet = new GetAzureRMEnvironmentCommand()
559+
{
560+
CommandRuntime = commandRuntimeMock.Object
561+
};
562+
563+
cmdlet.InvokeBeginProcessing();
564+
cmdlet.ExecuteCmdlet();
565+
cmdlet.InvokeEndProcessing();
566+
567+
Assert.Equal(3, environments.Count);
568+
569+
var publicEnvironmentRef = EnvironmentCmdletTestsExtension.GetAzureCloudEndpoints();
570+
var publicEnvironment = environments.Where(x => 0 == string.Compare(x.Name, "AzureCloud")).First();
571+
Assert.True(publicEnvironment.IsAbsolutelyEqual(publicEnvironmentRef));
572+
573+
var chinaEnvironmentRef = EnvironmentCmdletTestsExtension.GetAzureChinaCloudEndpoints();
574+
var chinaEnvironment = environments.Where(x => 0 == string.Compare(x.Name, "AzureChinaCloud")).First();
575+
Assert.True(chinaEnvironment.IsAbsolutelyEqual(chinaEnvironmentRef));
576+
577+
var usEnvironmentRef = EnvironmentCmdletTestsExtension.GetAzureUSGovernmentEndpoints();
578+
var usEnvironment = environments.Where(x => 0 == string.Compare(x.Name, "AzureUSGovernment")).First();
579+
Assert.True(usEnvironment.IsAbsolutelyEqual(usEnvironmentRef));
580+
}
581+
549582
[Fact]
550583
[Trait(Category.AcceptanceType, Category.CheckIn)]
551584
public void ThrowsWhenSettingPublicEnvironment()
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
16+
using Microsoft.Azure.Commands.Profile.Models;
17+
18+
namespace Microsoft.Azure.Commands.Profile.Test
19+
{
20+
public static class EnvironmentCmdletTestsExtension
21+
{
22+
public static PSAzureEnvironment GetAzureCloudEndpoints()
23+
{
24+
// AdTenant: Common --> common
25+
// GalleryUrl: "https://gallery.azure.com/" --> null
26+
// ManagementPortalUrl: "https://portal.azure.com/" --> "https://portal.azure.com"
27+
// ActiveDirectoryAuthority: "https://login.microsoftonline.com/" --> "https://login.microsoftonline.com"
28+
var env = new PSAzureEnvironment
29+
{
30+
Name = "AzureCloud",
31+
Type = "Discovered",
32+
EnableAdfsAuthentication = false,
33+
OnPremise = false,
34+
ActiveDirectoryServiceEndpointResourceId = "https://management.core.windows.net/",
35+
AdTenant = "common",
36+
GalleryUrl = null,
37+
ManagementPortalUrl = "https://portal.azure.com",
38+
ServiceManagementUrl = "https://management.core.windows.net/",
39+
PublishSettingsFileUrl = "https://go.microsoft.com/fwlink/?LinkID=301775",
40+
ResourceManagerUrl = "https://management.azure.com/",
41+
SqlDatabaseDnsSuffix = ".database.windows.net",
42+
StorageEndpointSuffix = "core.windows.net",
43+
ActiveDirectoryAuthority = "https://login.microsoftonline.com",
44+
GraphUrl = "https://graph.windows.net/",
45+
GraphEndpointResourceId = "https://graph.windows.net/",
46+
TrafficManagerDnsSuffix = "trafficmanager.net",
47+
AzureKeyVaultDnsSuffix = "vault.azure.net",
48+
DataLakeEndpointResourceId = "https://datalake.azure.net/",
49+
AzureDataLakeStoreFileSystemEndpointSuffix = "azuredatalakestore.net",
50+
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = "azuredatalakeanalytics.net",
51+
AzureKeyVaultServiceEndpointResourceId = "https://vault.azure.net",
52+
ContainerRegistryEndpointSuffix = "azurecr.io",
53+
AzureOperationalInsightsEndpointResourceId = "https://api.loganalytics.io",
54+
AzureOperationalInsightsEndpoint = "https://api.loganalytics.io/v1",
55+
AzureAnalysisServicesEndpointSuffix = "asazure.windows.net",
56+
AnalysisServicesEndpointResourceId = "https://region.asazure.windows.net",
57+
AzureAttestationServiceEndpointSuffix = "attest.azure.net",
58+
AzureAttestationServiceEndpointResourceId = "https://attest.azure.net",
59+
AzureSynapseAnalyticsEndpointSuffix = "dev.azuresynapse.net",
60+
AzureSynapseAnalyticsEndpointResourceId = "https://dev.azuresynapse.net",
61+
VersionProfiles = {},
62+
63+
BatchEndpointResourceId = "https://batch.core.windows.net/",
64+
};
65+
env.SetProperty("OperationalInsightsEndpoint", "https://api.loganalytics.io/v1");
66+
env.SetProperty("OperationalInsightsEndpointResourceId", "https://api.loganalytics.io");
67+
env.SetProperty("AzureAnalysisServicesEndpointSuffix", "asazure.windows.net");
68+
env.SetProperty("AnalysisServicesEndpointResourceId", "https://region.asazure.windows.net");
69+
env.SetProperty("AzureAttestationServiceEndpointSuffix", "attest.azure.net");
70+
env.SetProperty("AzureAttestationServiceEndpointResourceId", "https://attest.azure.net");
71+
env.SetProperty("AzureSynapseAnalyticsEndpointSuffix", "dev.azuresynapse.net");
72+
env.SetProperty("AzureSynapseAnalyticsEndpointResourceId", "https://dev.azuresynapse.net");
73+
env.SetProperty("ManagedHsmServiceEndpointResourceId", "https://managedhsm.azure.net");
74+
env.SetProperty("ManagedHsmServiceEndpointSuffix", "managedhsm.azure.net");
75+
env.SetProperty("MicrosoftGraphEndpointResourceId", "https://graph.microsoft.com/");
76+
env.SetProperty("MicrosoftGraphUrl", "https://graph.microsoft.com");
77+
env.SetProperty("AzurePurviewEndpointSuffix", "purview.azure.net");
78+
env.SetProperty("AzurePurviewEndpointResourceId", "https://purview.azure.net");
79+
env.SetProperty("AzureAppConfigurationEndpointSuffix", "azconfig.io");
80+
env.SetProperty("AzureAppConfigurationEndpointResourceId", "https://azconfig.io");
81+
env.SetProperty("ContainerRegistryEndpointResourceId", "https://management.azure.com");
82+
return env;
83+
}
84+
85+
public static PSAzureEnvironment GetAzureChinaCloudEndpoints()
86+
{
87+
var env = new PSAzureEnvironment()
88+
{
89+
Name = "AzureChinaCloud",
90+
Type = "Built-in",
91+
EnableAdfsAuthentication = false,
92+
OnPremise = false,
93+
ActiveDirectoryServiceEndpointResourceId = "https://management.core.chinacloudapi.cn/",
94+
AdTenant = "Common",
95+
GalleryUrl = "https://gallery.azure.com/",
96+
ManagementPortalUrl = "https://portal.azure.cn/",
97+
ServiceManagementUrl = "https://management.core.chinacloudapi.cn/",
98+
PublishSettingsFileUrl = "https://go.microsoft.com/fwlink/?LinkID=301776",
99+
ResourceManagerUrl = "https://management.chinacloudapi.cn/",
100+
SqlDatabaseDnsSuffix = ".database.chinacloudapi.cn",
101+
StorageEndpointSuffix = "core.chinacloudapi.cn",
102+
ActiveDirectoryAuthority = "https://login.chinacloudapi.cn/",
103+
GraphUrl = "https://graph.chinacloudapi.cn/",
104+
GraphEndpointResourceId = "https://graph.chinacloudapi.cn/",
105+
TrafficManagerDnsSuffix = "trafficmanager.cn",
106+
AzureKeyVaultDnsSuffix = "vault.azure.cn",
107+
DataLakeEndpointResourceId = null,
108+
AzureDataLakeStoreFileSystemEndpointSuffix = null,
109+
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = null,
110+
AzureKeyVaultServiceEndpointResourceId = "https://vault.azure.cn",
111+
ContainerRegistryEndpointSuffix = "azurecr.cn",
112+
AzureOperationalInsightsEndpointResourceId = "https://api.loganalytics.azure.cn",
113+
AzureOperationalInsightsEndpoint = "https://api.loganalytics.azure.cn/v1",
114+
AzureAnalysisServicesEndpointSuffix = "asazure.chinacloudapi.cn",
115+
AnalysisServicesEndpointResourceId = "https://region.asazure.chinacloudapi.cn",
116+
AzureAttestationServiceEndpointSuffix = null,
117+
AzureAttestationServiceEndpointResourceId = null,
118+
AzureSynapseAnalyticsEndpointSuffix = "dev.azuresynapse.azure.cn",
119+
AzureSynapseAnalyticsEndpointResourceId = "https://dev.azuresynapse.azure.cn",
120+
VersionProfiles = {},
121+
BatchEndpointResourceId = "https://batch.chinacloudapi.cn/",
122+
};
123+
env.SetProperty("OperationalInsightsEndpoint", "https://api.loganalytics.azure.cn/v1");
124+
env.SetProperty("OperationalInsightsEndpointResourceId", "https://api.loganalytics.azure.cn");
125+
env.SetProperty("AzureAnalysisServicesEndpointSuffix", "asazure.chinacloudapi.cn");
126+
env.SetProperty("AnalysisServicesEndpointResourceId", "https://region.asazure.chinacloudapi.cn");
127+
env.SetProperty("AzureSynapseAnalyticsEndpointSuffix", "dev.azuresynapse.azure.cn");
128+
env.SetProperty("AzureSynapseAnalyticsEndpointResourceId", "https://dev.azuresynapse.azure.cn");
129+
env.SetProperty("ManagedHsmServiceEndpointResourceId", "https://managedhsm.azure.cn");
130+
env.SetProperty("ManagedHsmServiceEndpointSuffix", "managedhsm.azure.cn");
131+
env.SetProperty("MicrosoftGraphEndpointResourceId", "https://microsoftgraph.chinacloudapi.cn/");
132+
env.SetProperty("MicrosoftGraphUrl", "https://microsoftgraph.chinacloudapi.cn");
133+
env.SetProperty("ContainerRegistryEndpointResourceId", "https://management.chinacloudapi.cn");
134+
return env;
135+
}
136+
137+
public static PSAzureEnvironment GetAzureUSGovernmentEndpoints()
138+
{
139+
var env = new PSAzureEnvironment()
140+
{
141+
Name = "AzureUSGovernment",
142+
Type = "Built-in",
143+
EnableAdfsAuthentication = false,
144+
OnPremise = false,
145+
ActiveDirectoryServiceEndpointResourceId = "https://management.core.usgovcloudapi.net/",
146+
AdTenant = "Common",
147+
GalleryUrl = "https://gallery.azure.com/",
148+
ManagementPortalUrl = "https://portal.azure.us/",
149+
ServiceManagementUrl = "https://management.core.usgovcloudapi.net/",
150+
PublishSettingsFileUrl = "https://manage.windowsazure.us/publishsettings/index",
151+
ResourceManagerUrl = "https://management.usgovcloudapi.net/",
152+
SqlDatabaseDnsSuffix = ".database.usgovcloudapi.net",
153+
StorageEndpointSuffix = "core.usgovcloudapi.net",
154+
ActiveDirectoryAuthority = "https://login.microsoftonline.us/",
155+
GraphUrl = "https://graph.windows.net/",
156+
GraphEndpointResourceId = "https://graph.windows.net/",
157+
TrafficManagerDnsSuffix = "usgovtrafficmanager.net",
158+
AzureKeyVaultDnsSuffix = "vault.usgovcloudapi.net",
159+
DataLakeEndpointResourceId = null,
160+
AzureDataLakeStoreFileSystemEndpointSuffix = null,
161+
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = null,
162+
AzureKeyVaultServiceEndpointResourceId = "https://vault.usgovcloudapi.net",
163+
ContainerRegistryEndpointSuffix = "azurecr.us",
164+
AzureOperationalInsightsEndpointResourceId = "https://api.loganalytics.us",
165+
AzureOperationalInsightsEndpoint = "https://api.loganalytics.us/v1",
166+
AzureAnalysisServicesEndpointSuffix = "asazure.usgovcloudapi.net",
167+
AnalysisServicesEndpointResourceId = "https://region.asazure.usgovcloudapi.net",
168+
AzureAttestationServiceEndpointSuffix = null,
169+
AzureAttestationServiceEndpointResourceId = null,
170+
AzureSynapseAnalyticsEndpointSuffix = "dev.azuresynapse.usgovcloudapi.net",
171+
AzureSynapseAnalyticsEndpointResourceId = "https://dev.azuresynapse.usgovcloudapi.net",
172+
VersionProfiles = {},
173+
BatchEndpointResourceId = "https://batch.core.usgovcloudapi.net/"
174+
};
175+
env.SetProperty("OperationalInsightsEndpoint", "https://api.loganalytics.us/v1");
176+
env.SetProperty("OperationalInsightsEndpointResourceId", "https://api.loganalytics.us");
177+
env.SetProperty("AzureAnalysisServicesEndpointSuffix", "asazure.usgovcloudapi.net");
178+
env.SetProperty("AnalysisServicesEndpointResourceId", "https://region.asazure.usgovcloudapi.net");
179+
env.SetProperty("AzureSynapseAnalyticsEndpointSuffix", "dev.azuresynapse.usgovcloudapi.net");
180+
env.SetProperty("AzureSynapseAnalyticsEndpointResourceId", "https://dev.azuresynapse.usgovcloudapi.net");
181+
env.SetProperty("ManagedHsmServiceEndpointResourceId", "https://managedhsm.usgovcloudapi.net");
182+
env.SetProperty("ManagedHsmServiceEndpointSuffix", "managedhsm.usgovcloudapi.net");
183+
env.SetProperty("MicrosoftGraphEndpointResourceId", "https://graph.microsoft.us/");
184+
env.SetProperty("MicrosoftGraphUrl", "https://graph.microsoft.us");
185+
env.SetProperty("ContainerRegistryEndpointResourceId", "https://management.usgovcloudapi.net");
186+
return env;
187+
}
188+
189+
public static bool IsAbsolutelyEqual(this PSAzureEnvironment source, PSAzureEnvironment target)
190+
{
191+
bool equal = true;
192+
var properties = target.GetType().GetProperties();
193+
foreach (var property in properties)
194+
{
195+
var propertyName = property.Name;
196+
if (property.PropertyType == typeof(string))
197+
{
198+
equal = (0 == string.Compare(property.GetValue(target) as string,
199+
source.GetType().GetProperty(propertyName).GetValue(source) as string));
200+
if (!equal)
201+
{
202+
break;
203+
}
204+
}
205+
else if (0 == string.Compare(property.Name, "ExtendedProperties"))
206+
{
207+
equal = source.ExtendedProperties.Count == target.ExtendedProperties.Count;
208+
if (equal)
209+
{
210+
foreach (var extendedProperty in target.ExtendedProperties)
211+
{
212+
equal = source.ExtendedProperties.ContainsKey(extendedProperty.Key);
213+
if (!equal)
214+
{
215+
break;
216+
}
217+
equal = (0 == string.Compare(extendedProperty.Value, source.ExtendedProperties[extendedProperty.Key]));
218+
if (!equal)
219+
{
220+
break;
221+
}
222+
}
223+
}
224+
}
225+
}
226+
return equal;
227+
}
228+
}
229+
}

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Fixed `AzureSynapseAnalyticsEndpointResourceId` of `USGovernment` environment.
2223
* Updated Azure.Core to 1.31.0.
2324

2425
## Version 2.12.1

0 commit comments

Comments
 (0)