< Summary

Class:Azure.Iot.Hub.Service.Authentication.SasTokenAuthenticationPolicy
Assembly:Azure.Iot.Hub.Service
File(s):C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Authentication\SasTokenAuthenticationPolicy.cs
Covered lines:11
Uncovered lines:0
Coverable lines:11
Total lines:41
Line coverage:100% (11 of 11)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
Process(...)-100%100%
ProcessAsync()-100%100%
AddHeaders(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\iot\Azure.Iot.Hub.Service\src\Authentication\SasTokenAuthenticationPolicy.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Threading.Tasks;
 6using Azure.Core;
 7using Azure.Core.Pipeline;
 8
 9namespace Azure.Iot.Hub.Service.Authentication
 10{
 11    /// <summary>
 12    /// The shared access signature based HTTP pipeline policy.
 13    /// This authentication policy injects the sas token into the HTTP authentication header for each HTTP request made.
 14    /// </summary>
 15    internal class SasTokenAuthenticationPolicy : HttpPipelinePolicy
 16    {
 17        private readonly ISasTokenProvider _sasTokenProvider;
 18
 7619        internal SasTokenAuthenticationPolicy(ISasTokenProvider sasTokenProvider)
 20        {
 7621            _sasTokenProvider = sasTokenProvider;
 7622        }
 23
 24        public override void Process(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline)
 25        {
 19626            AddHeaders(message);
 19627            ProcessNext(message, pipeline);
 19628        }
 29
 30        public override async ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline)
 31        {
 19432            AddHeaders(message);
 19433            await ProcessNextAsync(message, pipeline).ConfigureAwait(false);
 19434        }
 35
 36        private void AddHeaders(HttpMessage message)
 37        {
 39038            message.Request.Headers.Add(HttpHeader.Names.Authorization, _sasTokenProvider.GetSasToken());
 39039        }
 40    }
 41}