diff --git a/src/Common/Commands.Common.Test/Common/ProfileClientTests.cs b/src/Common/Commands.Common.Test/Common/ProfileClientTests.cs index 222da7747089..bc610519eaae 100644 --- a/src/Common/Commands.Common.Test/Common/ProfileClientTests.cs +++ b/src/Common/Commands.Common.Test/Common/ProfileClientTests.cs @@ -290,6 +290,10 @@ public void AddAzureAccountReturnsAccountWithAllSubscriptionsInCsmMode() Assert.True(account.GetSubscriptions(client.Profile).Any(s => s.Id == new Guid(csmSubscription1.SubscriptionId))); } + /// + /// Verify that if a user has a different identity in one tenant, the identity is not added if it has no + /// access to subscriptions + /// [Fact] public void AddAzureAccountWithImpersonatedGuestWithNoSubscriptions() { @@ -326,6 +330,10 @@ public void AddAzureAccountWithImpersonatedGuestWithNoSubscriptions() Assert.Equal("UserA", subrdfe1.Account); } + /// + /// Verify that multiple accounts can be added if a user has different identitities in different domains, linked to the same login + /// Verify that subscriptions with admin access forall accounts are added + /// [Fact] public void AddAzureAccountWithImpersonatedGuestWithSubscriptions() { @@ -346,7 +354,8 @@ public void AddAzureAccountWithImpersonatedGuestWithSubscriptions() ProfileClient.DataStore = dataStore; ProfileClient client = new ProfileClient(); - var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null); + var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User }, + AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null); Assert.Equal("UserA", account.Id); Assert.Equal(1, account.GetSubscriptions(client.Profile).Count); @@ -363,6 +372,39 @@ public void AddAzureAccountWithImpersonatedGuestWithSubscriptions() Assert.Equal("UserA", subrdfe1.Account); Assert.Equal("UserB", subGuest.Account); } + /// + /// Test that when account is added more than once with different capitalization, only a single account is added + /// and that accounts can be retrieved case-insensitively + /// + [Fact] + public void AddAzureAccountIsCaseInsensitive() + { + SetMocks(new[] { rdfeSubscription1, guestRdfeSubscription }.ToList(), new List(), new[] { commonTenant, guestTenant }.ToList(), + (userAccount, environment, tenant) => + { + var token = new MockAccessToken + { + UserId = tenant == commonTenant.TenantId ? userAccount.Id : "USERA", + AccessToken = "def", + LoginType = LoginType.OrgId + }; + userAccount.Id = token.UserId; + return token; + }); + MockDataStore dataStore = new MockDataStore(); + dataStore.VirtualStore[oldProfileDataPath] = oldProfileData; + ProfileClient.DataStore = dataStore; + ProfileClient client = new ProfileClient(); + + var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User }, + AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null); + + var userA = client.GetAccount("UserA"); + var secondUserA = client.GetAccount("USERA"); + Assert.NotNull(userA); + Assert.NotNull(secondUserA); + Assert.Equal(userA.Id, secondUserA.Id); + } [Fact] public void GetAzureAccountReturnsAccountWithSubscriptions() diff --git a/src/Common/Commands.Common/Common/ProfileClient.cs b/src/Common/Commands.Common/Common/ProfileClient.cs index 14b612c9babb..217b84df6592 100644 --- a/src/Common/Commands.Common/Common/ProfileClient.cs +++ b/src/Common/Commands.Common/Common/ProfileClient.cs @@ -835,9 +835,9 @@ private AzureEnvironment MergeEnvironmentProperties(AzureEnvironment environment { throw new ArgumentNullException("environment1"); } - if (environment1.Name != environment2.Name) + if (!string.Equals(environment1.Name, environment2.Name, StringComparison.InvariantCultureIgnoreCase)) { - throw new ArgumentException("Subscription Ids do not match."); + throw new ArgumentException("Environment names do not match."); } AzureEnvironment mergedEnvironment = new AzureEnvironment { @@ -863,9 +863,9 @@ private AzureAccount MergeAccountProperties(AzureAccount account1, AzureAccount { throw new ArgumentNullException("account1"); } - if (account1.Id != account2.Id) + if (!string.Equals(account1.Id, account2.Id, StringComparison.InvariantCultureIgnoreCase)) { - throw new ArgumentException("Account1 Ids do not match."); + throw new ArgumentException("Account Ids do not match."); } if (account1.Type != account2.Type) { @@ -918,7 +918,7 @@ private IEnumerable ListResourceManagerSubscriptions(AzureAcc var tenantAccount = new AzureAccount(); CopyAccount(account, tenantAccount); var tenantToken = AzureSession.AuthenticationFactory.Authenticate(tenantAccount, environment, tenant, password, ShowDialog.Never); - if (tenantAccount.Id == account.Id) + if (string.Equals(tenantAccount.Id, account.Id, StringComparison.InvariantCultureIgnoreCase)) { tenantAccount = account; } @@ -984,7 +984,7 @@ private IEnumerable ListServiceManagementSubscriptions(AzureA var tenantAccount = new AzureAccount(); CopyAccount(account, tenantAccount); var tenantToken = AzureSession.AuthenticationFactory.Authenticate(tenantAccount, environment, tenant, password, ShowDialog.Never); - if (tenantAccount.Id == account.Id) + if (string.Equals(tenantAccount.Id, account.Id, StringComparison.InvariantCultureIgnoreCase)) { tenantAccount = account; }