Skip to content

. #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 19, 2016
Merged

. #334

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,40 @@ public void TokenIdAndAccountIdMismatch()
Assert.Equal(1, tenantsInAccount.Length);
Assert.Equal(tenants.First(), tenantsInAccount[0]);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void AdalExceptionsArePropagatedToCaller()
{
var tenants = new List<string> { Guid.NewGuid().ToString(), DefaultTenant.ToString() };
var secondsubscriptionInTheFirstTenant = Guid.NewGuid().ToString();
var firstList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
var secondList = new List<string> { Guid.NewGuid().ToString() };
var thirdList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
var fourthList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList, fourthList);

var tokens = new Queue<MockAccessToken>();
tokens.Enqueue(new MockAccessToken
{
UserId = "aaa@contoso.com",
LoginType = LoginType.OrgId,
AccessToken = "bbb"
});

((MockTokenAuthenticationFactory)AzureSession.AuthenticationFactory).TokenProvider = (account, environment, tenant) =>
{
throw new AadAuthenticationCanceledException("Login window was closed", null);
};

Assert.Throws<AadAuthenticationCanceledException>( () => client.Login(
Context.Account,
Context.Environment,
null,
secondsubscriptionInTheFirstTenant,
null,
null));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,10 @@ public IEnumerable<AzureSubscription> ListSubscriptions()
}
catch (AadAuthenticationException)
{
WriteWarningMessage(string.Format("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.", _profile.Context.Account, tenant));
WriteWarningMessage(string.Format(
Microsoft.Azure.Commands.Profile.Properties.Resources.UnableToLogin,
_profile.Context.Account,
tenant));
}

}
Expand Down Expand Up @@ -576,11 +577,12 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
{
result =
account.GetPropertyAsArray(AzureAccount.Property.Tenants)
.Select( ti => {
.Select(ti =>
{
var tenant = new AzureTenant();

Guid guid;
if(Guid.TryParse(ti, out guid))
if (Guid.TryParse(ti, out guid))
{
tenant.Id = guid;
tenant.Domain = AccessTokenExtensions.GetDomain(account.Id);
Expand All @@ -593,8 +595,12 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
return tenant;
}).ToList();
}

}
if(!result.Any())
{
throw;
}

}

return result;
}
Expand Down Expand Up @@ -640,7 +646,7 @@ private void WriteWarningMessage(string message)
WarningLog(message);
}
}

private static AzureTenant CreateTenantFromString(string tenantOrDomain, string accessTokenTenantId)
{
AzureTenant result = new AzureTenant();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@
<data name="UnableToAqcuireToken" xml:space="preserve">
<value>Unable to acquire token for tenant '{0}'</value>
</data>
<data name="UnableToLogin" xml:space="preserve">
<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>
</data>
<data name="UnknownEnvironment" xml:space="preserve">
<value>Unable to find environment with name '{0}'</value>
</data>
</root>
</root>