Skip to content

Commit 8e4121b

Browse files
author
Hovsep Mkrtchyan
committed
Added test to handle Adal Exception during login.
1 parent cbe447e commit 8e4121b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
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)]

0 commit comments

Comments
 (0)