< Summary

Information
Class: webapi.Filter.RequestHashAttribute
Assembly: webapi
File(s): /home/runner/work/poc-request-body-to-hash/poc-request-body-to-hash/src/webapi/Filter/RequestHashAsyncActionFilter.cs
Tag: 11_2152250506
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 20
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Coverage History

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
OnActionExecutionAsync()100%1100%

File(s)

/home/runner/work/poc-request-body-to-hash/poc-request-body-to-hash/src/webapi/Filter/RequestHashAsyncActionFilter.cs

#LineLine coverage
 1using System.Security.Cryptography;
 2using Microsoft.AspNetCore.Mvc.Filters;
 3
 4namespace webapi.Filter;
 5
 6public class RequestHashAttribute : ActionFilterAttribute
 7{
 8    public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
 19    {
 110        var req = context.HttpContext.Request;
 111        req.Body.Position = 0;
 12
 113        using var sha = HashAlgorithm.Create("SHA512")!;
 114        var hash = await sha.ComputeHashAsync(req.Body);
 15
 116        req.Headers.Add("HashSHA512", Convert.ToBase64String(hash));
 17
 118        await base.OnActionExecutionAsync(context, next);
 119    }
 20}

Methods/Properties

OnActionExecutionAsync()