< Summary

Class:Microsoft.Azure.KeyVault.Customized.Authentication.ChallengeCacheHandler
Assembly:Microsoft.Azure.KeyVault
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault\src\Customized\Authentication\ChallengeCacheHandler.cs
Covered lines:6
Uncovered lines:0
Coverable lines:6
Total lines:50
Line coverage:100% (6 of 6)
Covered branches:4
Total branches:4
Branch coverage:100% (4 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ProcessRequest(...)-100%100%
ProcessResponse(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Microsoft.Azure.KeyVault\src\Customized\Authentication\ChallengeCacheHandler.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Net.Http;
 5using System.Text;
 6using System.Threading;
 7using System.Threading.Tasks;
 8
 9namespace Microsoft.Azure.KeyVault.Customized.Authentication
 10{
 11    /// <summary>
 12    /// A <see cref="DelegatingHandler"/> which will update the <see cref="HttpBearerChallengeCache"/> when a 401 respon
 13    /// </summary>
 14    public class ChallengeCacheHandler : MessageProcessingHandler
 15    {
 16        /// <summary>
 17        /// Returns the specified request without performing any processing
 18        /// </summary>
 19        /// <param name="request"></param>
 20        /// <param name="cancellationToken"></param>
 21        /// <returns></returns>
 22        protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationT
 23        {
 92224            return request;
 25        }
 26        /// <summary>
 27        /// Updates the <see cref="HttpBearerChallengeCache"/> when the specified response has a return code of 401
 28        /// </summary>
 29        /// <param name="response">The response to evaluate</param>
 30        /// <param name="cancellationToken">The cancellation token</param>
 31        /// <returns></returns>
 32        protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, CancellationToken cancellat
 33        {
 34            // if the response came back as 401 and the response contains a bearer challenge update the challenge cache
 92235            if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
 36            {
 837                HttpBearerChallenge challenge = HttpBearerChallenge.GetBearerChallengeFromResponse(response);
 38
 839                if (challenge != null)
 40                {
 41                    // Update challenge cache
 442                    HttpBearerChallengeCache.GetInstance().SetChallengeForURL(response.RequestMessage.RequestUri, challe
 43                }
 44            }
 45
 92246            return response;
 47        }
 48
 49    }
 50}