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
catch MsalClientException when user cancels auth instead of serviceEx… #587
Conversation
@@ -258,6 +258,12 @@ private void VerifyAuthorizationResult() | |||
MsalErrorMessage.NoPromptFailedErrorMessage); | |||
} | |||
|
|||
if (_authorizationResult.Status == AuthorizationStatus.UserCancel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you look at adding tests for this class? A unit tests should have failed when you added these lines, but it clearly did not since the PR passed. I think it is important to lock this down with unit tests because the exceptions we throw are part of the public API, i.e. if we throw a different exception from one release to the other we have broken customers' handling code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -1049,5 +1049,66 @@ public void GetUserTest() | |||
Assert.AreEqual(userToFind.IdentityProvider, fetchedUser.IdentityProvider); | |||
Assert.AreEqual(userToFind.Name, fetchedUser.Name); | |||
} | |||
|
|||
[TestMethod] | |||
[Description("Test for AcquireToken with user canceling authentication")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
AuthenticationResult result = await app.AcquireTokenAsync(TestConstants.Scope).ConfigureAwait(false); | ||
} | ||
catch (MsalClientException exc) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an exception is not thrown, your test will still pass. You can add a return statement in your catch block and an Assert.Fail("Should not reach here") at line 1082 (after the finally). Note that the finally clause is guaranteed to be executed, even if you return in catch block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool...great suggestion. thanks!
…re. test class needs to be cleaned and rebuilt often -> multitargeting issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…caption
#583