internal static async Task <XDocument> FetchMexAsync(string federationMetadataUrl, CallState callState)
        {
            XDocument mexDocument;

            try
            {
                IHttpClient request = new HttpClientWrapper(federationMetadataUrl, callState);
                using (var response = await request.GetResponseAsync().ConfigureAwait(false))
                {
                    mexDocument = XDocument.Load(EncodingHelper.GenerateStreamFromString(response.ResponseString), LoadOptions.None);
                }
            }
            catch (HttpRequestWrapperException ex)
            {
                throw new AdalServiceException(AdalError.AccessingWsMetadataExchangeFailed, ex);
            }
            catch (XmlException ex)
            {
                throw new AdalException(AdalError.ParsingWsMetadataExchangeFailed, ex);
            }

            return(mexDocument);
        }
        public async Task TimeoutTest()
        {
            const string TestServiceUrl = "http://localhost:8080";
            using (WebApp.Start<TestService>(TestServiceUrl))
            {
                HttpClientWrapper webClient = new HttpClientWrapper(TestServiceUrl + "?delay=0&response_code=200", null) { TimeoutInMilliSeconds = 10000 };
                await webClient.GetResponseAsync();

                webClient = new HttpClientWrapper(TestServiceUrl + "?delay=0&response_code=200", null) { TimeoutInMilliSeconds = 10000 };
                await webClient.GetResponseAsync();

                try
                {
                    webClient = new HttpClientWrapper(TestServiceUrl + "?delay=0&response_code=400", null) { TimeoutInMilliSeconds = 10000 };
                    await webClient.GetResponseAsync();
                }
                catch (HttpRequestWrapperException ex)
                {
                    Verify.AreEqual(ex.WebResponse.StatusCode, HttpStatusCode.BadRequest);
                }


                try
                {
                    webClient = new HttpClientWrapper(TestServiceUrl + "?delay=10000&response_code=200", null) { TimeoutInMilliSeconds = 500 };
                    await webClient.GetResponseAsync();
                }
                catch (HttpRequestWrapperException ex)
                {
                    Verify.IsTrue(ex.InnerException is TaskCanceledException);
                    var serviceException = new AdalServiceException(AdalError.Unknown, ex);
                    Verify.AreEqual(serviceException.StatusCode, (int)HttpStatusCode.RequestTimeout);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Creates authentication parameters from the response received from the response received from the resource. This method expects the response to have unauthorized status and
        /// WWW-Authenticate header containing authentication parameters.</summary>
        /// <param name="responseMessage">Response received from the resource (e.g. via an http call using HttpClient).</param>
        /// <returns>AuthenticationParameters object containing authentication parameters</returns>

        public static async Task <AuthenticationParameters> CreateFromUnauthorizedResponseAsync(HttpResponseMessage responseMessage)
        {
            return(CreateFromUnauthorizedResponseCommon(await HttpClientWrapper.CreateResponseAsync(responseMessage)));
        }
        [Ignore]    // This test requires TestService to run in a non-WinRT app. The code can be found in tests\Test.ADAL.NET.Unit\UnitTests.cs
        public async Task TimeoutTest()
        {
            const string TestServiceUrl = "http://localhost:8080";
            HttpClientWrapper webRequest = new HttpClientWrapper(TestServiceUrl + "?delay=0&response_code=200", null) { TimeoutInMilliSeconds = 10000 };
            await webRequest.GetResponseAsync();

            try
            {
                webRequest = new HttpClientWrapper(TestServiceUrl + "?delay=0&response_code=400", null) { TimeoutInMilliSeconds = 10000 };
                await webRequest.GetResponseAsync();
            }
            catch (WebException ex)
            {
                Verify.AreEqual((int)(ex.Status), 7);   // ProtocolError
            }

            try
            {
                webRequest = new HttpClientWrapper(TestServiceUrl + "?delay=10000&response_code=200", null) { TimeoutInMilliSeconds = 500 };
                await webRequest.GetResponseAsync();
            }
            catch (WebException ex)
            {
                Verify.AreEqual((int)(ex.Status), 6);   // RequestCanceled
            }
        }