< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Authentication.BasicAuthenticationOptions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/BasicAuthenticationOptions.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
100%
Covered lines: 37
Uncovered lines: 0
Coverable lines: 37
Total lines: 142
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 09/08/2025 - 20:34:03 Line coverage: 100% (12/12) Total lines: 88 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7212/12/2025 - 17:27:19 Line coverage: 97% (33/34) Branch coverage: 100% (6/6) Total lines: 137 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/21/2025 - 06:07:10 Line coverage: 100% (37/37) Branch coverage: 100% (6/6) Total lines: 142 Tag: Kestrun/Kestrun@8cf7f77e55fd1fd046ea4e5413eb9ef96e49fe6a 12/12/2025 - 17:27:19 Line coverage: 97% (33/34) Branch coverage: 100% (6/6) Total lines: 137 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd12/21/2025 - 06:07:10 Line coverage: 100% (37/37) Branch coverage: 100% (6/6) Total lines: 142 Tag: Kestrun/Kestrun@8cf7f77e55fd1fd046ea4e5413eb9ef96e49fe6a

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_DisplayName()100%11100%
get_GlobalScheme()100%11100%
get_Description()100%11100%
get_DocumentationId()100%11100%
get_Host()100%11100%
get_Deprecated()100%11100%
get_Logger()100%44100%
get_HeaderName()100%11100%
get_Base64Encoded()100%11100%
get_SeparatorRegex()100%11100%
get_Realm()100%11100%
get_AllowInsecureHttp()100%11100%
get_SuppressWwwAuthenticate()100%11100%
get_ValidateCredentialsAsync()100%11100%
get_ValidateCodeSettings()100%11100%
get_IssueClaims()100%11100%
get_IssueClaimsCodeSettings()100%11100%
get_ClaimPolicyConfig()100%11100%
ApplyTo(...)100%22100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/BasicAuthenticationOptions.cs

#LineLine coverage
 1using System.Security.Claims;
 2using System.Text.RegularExpressions;
 3using Microsoft.AspNetCore.Authentication;
 4using Kestrun.Claims;
 5using Kestrun.Hosting;
 6
 7namespace Kestrun.Authentication;
 8
 9/// <summary>
 10/// Options for configuring Basic Authentication in Kestrun.
 11/// </summary>
 12public partial class BasicAuthenticationOptions : AuthenticationSchemeOptions, IAuthenticationCommonOptions, IOpenApiAut
 13{
 14    /// <inheritdoc/>
 1415    public string? DisplayName { get; set; }
 16    /// <inheritdoc/>
 2217    public bool GlobalScheme { get; set; }
 18
 19    /// <inheritdoc/>
 2220    public string? Description { get; set; }
 21
 22    /// <inheritdoc/>
 8923    public string[] DocumentationId { get; set; } = [];
 24
 25    /// <inheritdoc/>
 6626    public KestrunHost Host { get; set; } = default!;
 27
 28    /// <inheritdoc/>
 2229    public bool Deprecated { get; set; }
 30
 31    private Serilog.ILogger? _logger;
 32    /// <inheritdoc/>
 33    public Serilog.ILogger Logger
 34    {
 1435        get => _logger ?? (Host is null ? Serilog.Log.Logger : Host.Logger); set => _logger = value;
 36    }
 37    /// <summary>
 38    /// Gets or sets the name of the HTTP header used for authentication.
 39    /// </summary>
 8440    public string HeaderName { get; set; } = "Authorization";
 41    /// <summary>
 42    /// Gets or sets a value indicating whether the credentials are Base64 encoded.
 43    /// </summary>
 8544    public bool Base64Encoded { get; set; } = true;
 45
 46    /// <summary>
 47    /// Gets or sets the regular expression used to separate the username and password in the credentials.
 48    /// </summary>
 9149    public Regex SeparatorRegex { get; set; } = MyRegex();
 50
 51    /// <summary>
 52    /// Gets or sets the authentication realm used in the WWW-Authenticate header.
 53    /// </summary>
 5954    public string Realm { get; set; } = "Kestrun";
 55
 56    [GeneratedRegex("^([^:]*):(.*)$", RegexOptions.Compiled)]
 57    private static partial Regex MyRegex();
 58
 59    /// <summary>
 60    /// Gets or sets a value indicating whether to allow insecure HTTP connections.
 61    /// </summary>
 4262    public bool AllowInsecureHttp { get; set; }
 63
 64    /// <summary>
 65    /// Gets or sets a value indicating whether to suppress the WWW-Authenticate header in responses.
 66    /// </summary>
 1667    public bool SuppressWwwAuthenticate { get; set; }
 68
 69    /// <summary>
 70    /// Delegate to validate user credentials.
 71    /// Parameters: HttpContext, username, password. Returns: Task&lt;bool&gt; indicating validity.
 72    /// </summary>
 9973    public Func<HttpContext, string, string, Task<bool>> ValidateCredentialsAsync { get; set; } = (_, _, _) => Task.From
 74
 75    /// <summary>
 76    /// Settings for the authentication code, if using a script.
 77    /// </summary>
 78    /// <remarks>
 79    /// This allows you to specify the language, code, and additional imports/refs.
 80    /// </remarks>
 6981    public AuthenticationCodeSettings ValidateCodeSettings { get; set; } = new();
 82
 83    /// <summary>
 84    /// After credentials are valid, this is called to add extra Claims.
 85    /// Parameters: HttpContext, username → IEnumerable of extra claims.
 86    /// </summary>
 2487    public Func<HttpContext, string, Task<IEnumerable<Claim>>>? IssueClaims { get; set; }
 88
 89    /// <summary>
 90    /// Settings for the claims issuing code, if using a script.
 91    /// </summary>
 92    /// <remarks>
 93    /// This allows you to specify the language, code, and additional imports/refs for claims issuance.
 94    /// </remarks>
 6995    public AuthenticationCodeSettings IssueClaimsCodeSettings { get; set; } = new();
 96
 97    /// <summary>
 98    /// Gets or sets the claim policy configuration.
 99    /// </summary>
 100    /// <remarks>
 101    /// This allows you to define multiple authorization policies based on claims.
 102    /// Each policy can specify a claim type and allowed values.
 103    /// </remarks>
 20104    public ClaimPolicyConfig? ClaimPolicyConfig { get; set; }
 105
 106    /// <summary>
 107    /// Helper to copy values from a user-supplied BasicAuthenticationOptions instance to the instance
 108    /// created by the framework inside AddBasic(). Reassigning the local variable (opts = source) would
 109    /// not work because only the local reference changes – the framework keeps the original instance.
 110    /// </summary>
 111    /// <param name="target">The target instance to which values will be copied. </param>
 112    public void ApplyTo(BasicAuthenticationOptions target)
 113    {
 114        // Copy properties from the provided configure object
 7115        target.HeaderName = HeaderName;
 7116        target.Base64Encoded = Base64Encoded;
 7117        if (SeparatorRegex is not null)
 118        {
 7119            target.SeparatorRegex = new Regex(SeparatorRegex.ToString(), SeparatorRegex.Options);
 120        }
 121
 7122        target.Realm = Realm;
 7123        target.AllowInsecureHttp = AllowInsecureHttp;
 7124        target.SuppressWwwAuthenticate = SuppressWwwAuthenticate;
 7125        target.ValidateCredentialsAsync = ValidateCredentialsAsync;
 126        // Copy properties from the provided configure object
 7127        target.ValidateCodeSettings = ValidateCodeSettings;
 7128        target.IssueClaimsCodeSettings = IssueClaimsCodeSettings;
 7129        target.IssueClaims = IssueClaims;
 130        // Claims policy configuration
 7131        target.ClaimPolicyConfig = ClaimPolicyConfig;
 132
 133        // Copy IAuthenticationHostOptions properties
 7134        target.Host = Host;
 135        // OpenAPI / documentation properties(IOpenApiAuthenticationOptions)
 7136        target.GlobalScheme = GlobalScheme;
 7137        target.Description = Description;
 7138        target.DocumentationId = DocumentationId;
 7139        target.DisplayName = DisplayName;
 7140        target.Deprecated = Deprecated;
 7141    }
 142}