Skip to content

Commit c22dc7f

Browse files
Merge pull request #5 from Azure/dev
Merge Azure:dev
2 parents 51f23e1 + 928c243 commit c22dc7f

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

src/Common/Commands.Common.Test/Common/ProfileClientTests.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ public void AddAzureAccountReturnsAccountWithAllSubscriptionsInCsmMode()
290290
Assert.True(account.GetSubscriptions(client.Profile).Any(s => s.Id == new Guid(csmSubscription1.SubscriptionId)));
291291
}
292292

293+
/// <summary>
294+
/// Verify that if a user has a different identity in one tenant, the identity is not added if it has no
295+
/// access to subscriptions
296+
/// </summary>
293297
[Fact]
294298
public void AddAzureAccountWithImpersonatedGuestWithNoSubscriptions()
295299
{
@@ -326,6 +330,10 @@ public void AddAzureAccountWithImpersonatedGuestWithNoSubscriptions()
326330
Assert.Equal("UserA", subrdfe1.Account);
327331
}
328332

333+
/// <summary>
334+
/// Verify that multiple accounts can be added if a user has different identitities in different domains, linked to the same login
335+
/// Verify that subscriptions with admin access forall accounts are added
336+
/// </summary>
329337
[Fact]
330338
public void AddAzureAccountWithImpersonatedGuestWithSubscriptions()
331339
{
@@ -346,7 +354,8 @@ public void AddAzureAccountWithImpersonatedGuestWithSubscriptions()
346354
ProfileClient.DataStore = dataStore;
347355
ProfileClient client = new ProfileClient();
348356

349-
var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null);
357+
var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User },
358+
AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null);
350359

351360
Assert.Equal("UserA", account.Id);
352361
Assert.Equal(1, account.GetSubscriptions(client.Profile).Count);
@@ -363,6 +372,39 @@ public void AddAzureAccountWithImpersonatedGuestWithSubscriptions()
363372
Assert.Equal("UserA", subrdfe1.Account);
364373
Assert.Equal("UserB", subGuest.Account);
365374
}
375+
/// <summary>
376+
/// Test that when account is added more than once with different capitalization, only a single account is added
377+
/// and that accounts can be retrieved case-insensitively
378+
/// </summary>
379+
[Fact]
380+
public void AddAzureAccountIsCaseInsensitive()
381+
{
382+
SetMocks(new[] { rdfeSubscription1, guestRdfeSubscription }.ToList(), new List<Azure.Subscriptions.Models.Subscription>(), new[] { commonTenant, guestTenant }.ToList(),
383+
(userAccount, environment, tenant) =>
384+
{
385+
var token = new MockAccessToken
386+
{
387+
UserId = tenant == commonTenant.TenantId ? userAccount.Id : "USERA",
388+
AccessToken = "def",
389+
LoginType = LoginType.OrgId
390+
};
391+
userAccount.Id = token.UserId;
392+
return token;
393+
});
394+
MockDataStore dataStore = new MockDataStore();
395+
dataStore.VirtualStore[oldProfileDataPath] = oldProfileData;
396+
ProfileClient.DataStore = dataStore;
397+
ProfileClient client = new ProfileClient();
398+
399+
var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User },
400+
AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null);
401+
402+
var userA = client.GetAccount("UserA");
403+
var secondUserA = client.GetAccount("USERA");
404+
Assert.NotNull(userA);
405+
Assert.NotNull(secondUserA);
406+
Assert.Equal(userA.Id, secondUserA.Id);
407+
}
366408

367409
[Fact]
368410
public void GetAzureAccountReturnsAccountWithSubscriptions()

src/Common/Commands.Common/Common/ProfileClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,9 @@ private AzureEnvironment MergeEnvironmentProperties(AzureEnvironment environment
835835
{
836836
throw new ArgumentNullException("environment1");
837837
}
838-
if (environment1.Name != environment2.Name)
838+
if (!string.Equals(environment1.Name, environment2.Name, StringComparison.InvariantCultureIgnoreCase))
839839
{
840-
throw new ArgumentException("Subscription Ids do not match.");
840+
throw new ArgumentException("Environment names do not match.");
841841
}
842842
AzureEnvironment mergedEnvironment = new AzureEnvironment
843843
{
@@ -863,9 +863,9 @@ private AzureAccount MergeAccountProperties(AzureAccount account1, AzureAccount
863863
{
864864
throw new ArgumentNullException("account1");
865865
}
866-
if (account1.Id != account2.Id)
866+
if (!string.Equals(account1.Id, account2.Id, StringComparison.InvariantCultureIgnoreCase))
867867
{
868-
throw new ArgumentException("Account1 Ids do not match.");
868+
throw new ArgumentException("Account Ids do not match.");
869869
}
870870
if (account1.Type != account2.Type)
871871
{
@@ -918,7 +918,7 @@ private IEnumerable<AzureSubscription> ListResourceManagerSubscriptions(AzureAcc
918918
var tenantAccount = new AzureAccount();
919919
CopyAccount(account, tenantAccount);
920920
var tenantToken = AzureSession.AuthenticationFactory.Authenticate(tenantAccount, environment, tenant, password, ShowDialog.Never);
921-
if (tenantAccount.Id == account.Id)
921+
if (string.Equals(tenantAccount.Id, account.Id, StringComparison.InvariantCultureIgnoreCase))
922922
{
923923
tenantAccount = account;
924924
}
@@ -984,7 +984,7 @@ private IEnumerable<AzureSubscription> ListServiceManagementSubscriptions(AzureA
984984
var tenantAccount = new AzureAccount();
985985
CopyAccount(account, tenantAccount);
986986
var tenantToken = AzureSession.AuthenticationFactory.Authenticate(tenantAccount, environment, tenant, password, ShowDialog.Never);
987-
if (tenantAccount.Id == account.Id)
987+
if (string.Equals(tenantAccount.Id, account.Id, StringComparison.InvariantCultureIgnoreCase))
988988
{
989989
tenantAccount = account;
990990
}

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public string GenerateAgentAuthenticationHeader(string clientRequestId)
187187
/// <returns>Custom request headers</returns>
188188
public CustomRequestHeaders GetRequestHeaders()
189189
{
190-
this.ClientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToString("yyyy-mm-dd HH:mm:ssZ") + "-P";
190+
this.ClientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-P";
191191

192192
return new CustomRequestHeaders()
193193
{

0 commit comments

Comments
 (0)