public void OAuthClient_FailsWithServiceExceptionWhenResponseIsEmpty()
        {
            using (var httpManager = new MockHttpManager())
            {
                var serviceBundle = ServiceBundle.CreateWithCustomHttpManager(httpManager, _myReceiver);

                var authority = Authority.CreateAuthority(serviceBundle, MsalTestConstants.AuthorityHomeTenant, false);

                httpManager.AddMockHandler(
                    new MockHttpMessageHandler
                {
                    Method          = HttpMethod.Get,
                    ResponseMessage = MockHelpers.CreateEmptyResponseMessage()
                });

                var parameters = new AuthenticationRequestParameters
                {
                    Authority      = authority,
                    ClientId       = MsalTestConstants.ClientId,
                    Scope          = MsalTestConstants.Scope,
                    TokenCache     = null,
                    RequestContext = new RequestContext(null, new MsalLogger(Guid.NewGuid(), null)),
                    RedirectUri    = new Uri("some://uri"),
                };

                var ui = new MockWebUI();

                var request = new InteractiveRequest(
                    serviceBundle,
                    parameters,
                    ApiEvent.ApiIds.None,
                    MsalTestConstants.ScopeForAnotherResource.ToArray(),
                    MsalTestConstants.DisplayableId,
                    UIBehavior.SelectAccount,
                    ui);

                try
                {
                    request.ExecuteAsync(CancellationToken.None).Wait();

                    Assert.Fail("MsalException should have been thrown here");
                }
                catch (Exception exc)
                {
                    var serverEx = exc.InnerException as MsalServiceException;
                    Assert.IsNotNull(serverEx);
                    Assert.AreEqual((int)HttpStatusCode.BadRequest, serverEx.StatusCode);
                    Assert.IsNotNull(serverEx.ResponseBody);
                    Assert.AreEqual(MsalError.HttpStatusCodeNotOk, serverEx.ErrorCode);
                }
            }
        }
Beispiel #2
0
 public void OAuthClient_FailsWithServiceExceptionWhenResponseIsEmpty()
 {
     ValidateOathClient(
         MockHelpers.CreateEmptyResponseMessage(),
         exception =>
     {
         var serverEx = exception.InnerException as MsalServiceException;
         Assert.IsNotNull(serverEx);
         Assert.AreEqual((int)HttpStatusCode.BadRequest, serverEx.StatusCode);
         Assert.IsNotNull(serverEx.ResponseBody);
         Assert.AreEqual(MsalError.HttpStatusCodeNotOk, serverEx.ErrorCode);
     });
 }
 public async Task OAuthClient_FailsWithServiceExceptionWhenResponseIsEmpty_Async()
 {
     await ValidateOathClientAsync(
         MockHelpers.CreateEmptyResponseMessage(),
         exception =>
     {
         var serverEx = exception as MsalServiceException;
         Assert.IsNotNull(serverEx);
         Assert.AreEqual((int)HttpStatusCode.BadRequest, serverEx.StatusCode);
         Assert.IsNotNull(serverEx.ResponseBody);
         Assert.AreEqual(MsalError.HttpStatusCodeNotOk, serverEx.ErrorCode);
     }).ConfigureAwait(false);
 }