< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Jwt.JwtInspector
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Jwt/JwtInspector.cs
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 47
Line coverage: 100%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ReadAllParameters(...)70%1010100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Jwt/JwtInspector.cs

#LineLine coverage
 1using System.IdentityModel.Tokens.Jwt;
 2
 3namespace Kestrun.Jwt;
 4/// <summary>
 5/// Provides methods for inspecting and extracting parameters from JWT tokens.
 6/// </summary>
 7public static class JwtInspector
 8{
 9    /// <summary>
 10    /// Reads out every header field, standard property, and claim from a compact JWT.
 11    /// </summary>
 12    public static JwtParameters ReadAllParameters(string token)
 13    {
 1014        var handler = new JwtSecurityTokenHandler();
 15
 16        // parse without validating signature or lifetime
 1017        var jwt = handler.ReadJwtToken(token);
 18
 1019        var result = new JwtParameters
 1020        {
 1021            Issuer = jwt.Issuer,
 1022            Audiences = jwt.Audiences,
 1023            Subject = jwt.Subject,
 1024            NotBefore = jwt.ValidFrom == DateTime.MinValue ? null : jwt.ValidFrom,
 1025            Expires = jwt.ValidTo == DateTime.MinValue ? null : jwt.ValidTo,
 1026            IssuedAt = jwt.Payload.IssuedAt == DateTime.MinValue ? null : jwt.Payload.IssuedAt,
 1027            Algorithm = jwt.SignatureAlgorithm,
 1028            Type = jwt.Header.Typ,
 1029            KeyId = jwt.Header.Kid
 1030        };
 31
 32        // copy all header entries
 8833        foreach (var kv in jwt.Header)
 34        {
 3435            result.Header[kv.Key] = kv.Value!;
 36        }
 37
 38        // copy all payload claims (including custom ones)
 15839        foreach (var claim in jwt.Claims)
 40        {
 41            // if a claim type can appear multiple times, you might want to handle lists
 6942            result.Claims[claim.Type] = claim.Value;
 43        }
 44
 1045        return result;
 46    }
 47}