Skip to content

Commit 1edec5e

Browse files
committed
Merge pull request #334 from Azure/dev
.
2 parents 837bcff + a752edd commit 1edec5e

File tree

4 files changed

+63
-11
lines changed

4 files changed

+63
-11
lines changed

src/ResourceManager/Profile/Commands.Profile.Test/AzureRMProfileTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,40 @@ public void TokenIdAndAccountIdMismatch()
116116
Assert.Equal(1, tenantsInAccount.Length);
117117
Assert.Equal(tenants.First(), tenantsInAccount[0]);
118118
}
119+
120+
[Fact]
121+
[Trait(Category.AcceptanceType, Category.CheckIn)]
122+
public void AdalExceptionsArePropagatedToCaller()
123+
{
124+
var tenants = new List<string> { Guid.NewGuid().ToString(), DefaultTenant.ToString() };
125+
var secondsubscriptionInTheFirstTenant = Guid.NewGuid().ToString();
126+
var firstList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
127+
var secondList = new List<string> { Guid.NewGuid().ToString() };
128+
var thirdList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
129+
var fourthList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
130+
var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList, fourthList);
131+
132+
var tokens = new Queue<MockAccessToken>();
133+
tokens.Enqueue(new MockAccessToken
134+
{
135+
UserId = "[email protected]",
136+
LoginType = LoginType.OrgId,
137+
AccessToken = "bbb"
138+
});
139+
140+
((MockTokenAuthenticationFactory)AzureSession.AuthenticationFactory).TokenProvider = (account, environment, tenant) =>
141+
{
142+
throw new AadAuthenticationCanceledException("Login window was closed", null);
143+
};
144+
145+
Assert.Throws<AadAuthenticationCanceledException>( () => client.Login(
146+
Context.Account,
147+
Context.Environment,
148+
null,
149+
secondsubscriptionInTheFirstTenant,
150+
null,
151+
null));
152+
}
119153

120154
[Fact]
121155
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ResourceManager/Profile/Commands.Profile/Models/RMProfileClient.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ public IEnumerable<AzureSubscription> ListSubscriptions()
386386
}
387387
catch (AadAuthenticationException)
388388
{
389-
WriteWarningMessage(string.Format("Could not authenticate user account {0} with tenant {1}. " +
390-
"Subscriptions in this tenant will not be listed. Please login again using Login-AzureRmAccount " +
391-
"to view the subscriptions in this tenant.", _profile.Context.Account, tenant));
389+
WriteWarningMessage(string.Format(
390+
Microsoft.Azure.Commands.Profile.Properties.Resources.UnableToLogin,
391+
_profile.Context.Account,
392+
tenant));
392393
}
393394

394395
}
@@ -576,11 +577,12 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
576577
{
577578
result =
578579
account.GetPropertyAsArray(AzureAccount.Property.Tenants)
579-
.Select( ti => {
580+
.Select(ti =>
581+
{
580582
var tenant = new AzureTenant();
581-
583+
582584
Guid guid;
583-
if(Guid.TryParse(ti, out guid))
585+
if (Guid.TryParse(ti, out guid))
584586
{
585587
tenant.Id = guid;
586588
tenant.Domain = AccessTokenExtensions.GetDomain(account.Id);
@@ -593,8 +595,12 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
593595
return tenant;
594596
}).ToList();
595597
}
596-
597-
}
598+
if(!result.Any())
599+
{
600+
throw;
601+
}
602+
603+
}
598604

599605
return result;
600606
}
@@ -640,7 +646,7 @@ private void WriteWarningMessage(string message)
640646
WarningLog(message);
641647
}
642648
}
643-
649+
644650
private static AzureTenant CreateTenantFromString(string tenantOrDomain, string accessTokenTenantId)
645651
{
646652
AzureTenant result = new AzureTenant();

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Profile/Commands.Profile/Properties/Resources.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@
168168
<data name="UnableToAqcuireToken" xml:space="preserve">
169169
<value>Unable to acquire token for tenant '{0}'</value>
170170
</data>
171+
<data name="UnableToLogin" xml:space="preserve">
172+
<value>Could not authenticate user account '{0}' with tenant '{1}'. Subscriptions in this tenant will not be listed. Please login again using Login-AzureRmAccount to view the subscriptions in this tenant.</value>
173+
</data>
171174
<data name="UnknownEnvironment" xml:space="preserve">
172175
<value>Unable to find environment with name '{0}'</value>
173176
</data>
174-
</root>
177+
</root>

0 commit comments

Comments
 (0)