Skip to content
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

Merged
merged 5 commits into from Jul 5, 2018

Conversation

jennyf19
Copy link
Collaborator

…caption

#583

@@ -258,6 +258,12 @@ private void VerifyAuthorizationResult()
MsalErrorMessage.NoPromptFailedErrorMessage);
}

if (_authorizationResult.Status == AuthorizationStatus.UserCancel)
Copy link
Member

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.

Copy link
Collaborator Author

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")]
Copy link
Member

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)
{
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool...great suggestion. thanks!

Copy link
Member

@bgavrilMS bgavrilMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jennyf19 jennyf19 merged commit f4a3e1f into dev Jul 5, 2018
@jennyf19 jennyf19 deleted the jennyf/fixException branch July 5, 2018 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants