< 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@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
97%
Covered lines: 33
Uncovered lines: 1
Coverable lines: 34
Total lines: 137
Line coverage: 97%
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 08/26/2025 - 14:53:17 Line coverage: 100% (12/12) Total lines: 88 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743112/12/2025 - 17:27:19 Line coverage: 97% (33/34) Branch coverage: 100% (6/6) Total lines: 137 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd 12/12/2025 - 17:27:19 Line coverage: 97% (33/34) Branch coverage: 100% (6/6) Total lines: 137 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_DisplayName()100%210%
get_GlobalScheme()100%11100%
get_Description()100%11100%
get_DocumentationId()100%11100%
get_Host()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/>
 015    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    private Serilog.ILogger? _logger;
 29    /// <inheritdoc/>
 30    public Serilog.ILogger Logger
 31    {
 1432        get => _logger ?? (Host is null ? Serilog.Log.Logger : Host.Logger); set => _logger = value;
 33    }
 34    /// <summary>
 35    /// Gets or sets the name of the HTTP header used for authentication.
 36    /// </summary>
 8437    public string HeaderName { get; set; } = "Authorization";
 38    /// <summary>
 39    /// Gets or sets a value indicating whether the credentials are Base64 encoded.
 40    /// </summary>
 8541    public bool Base64Encoded { get; set; } = true;
 42
 43    /// <summary>
 44    /// Gets or sets the regular expression used to separate the username and password in the credentials.
 45    /// </summary>
 9146    public Regex SeparatorRegex { get; set; } = MyRegex();
 47
 48    /// <summary>
 49    /// Gets or sets the authentication realm used in the WWW-Authenticate header.
 50    /// </summary>
 5951    public string Realm { get; set; } = "Kestrun";
 52
 53    [GeneratedRegex("^([^:]*):(.*)$", RegexOptions.Compiled)]
 54    private static partial Regex MyRegex();
 55
 56    /// <summary>
 57    /// Gets or sets a value indicating whether to allow insecure HTTP connections.
 58    /// </summary>
 4259    public bool AllowInsecureHttp { get; set; }
 60
 61    /// <summary>
 62    /// Gets or sets a value indicating whether to suppress the WWW-Authenticate header in responses.
 63    /// </summary>
 1664    public bool SuppressWwwAuthenticate { get; set; }
 65
 66    /// <summary>
 67    /// Delegate to validate user credentials.
 68    /// Parameters: HttpContext, username, password. Returns: Task&lt;bool&gt; indicating validity.
 69    /// </summary>
 9970    public Func<HttpContext, string, string, Task<bool>> ValidateCredentialsAsync { get; set; } = (_, _, _) => Task.From
 71
 72    /// <summary>
 73    /// Settings for the authentication code, if using a script.
 74    /// </summary>
 75    /// <remarks>
 76    /// This allows you to specify the language, code, and additional imports/refs.
 77    /// </remarks>
 6978    public AuthenticationCodeSettings ValidateCodeSettings { get; set; } = new();
 79
 80    /// <summary>
 81    /// After credentials are valid, this is called to add extra Claims.
 82    /// Parameters: HttpContext, username → IEnumerable of extra claims.
 83    /// </summary>
 2484    public Func<HttpContext, string, Task<IEnumerable<Claim>>>? IssueClaims { get; set; }
 85
 86    /// <summary>
 87    /// Settings for the claims issuing code, if using a script.
 88    /// </summary>
 89    /// <remarks>
 90    /// This allows you to specify the language, code, and additional imports/refs for claims issuance.
 91    /// </remarks>
 6992    public AuthenticationCodeSettings IssueClaimsCodeSettings { get; set; } = new();
 93
 94    /// <summary>
 95    /// Gets or sets the claim policy configuration.
 96    /// </summary>
 97    /// <remarks>
 98    /// This allows you to define multiple authorization policies based on claims.
 99    /// Each policy can specify a claim type and allowed values.
 100    /// </remarks>
 20101    public ClaimPolicyConfig? ClaimPolicyConfig { get; set; }
 102
 103    /// <summary>
 104    /// Helper to copy values from a user-supplied BasicAuthenticationOptions instance to the instance
 105    /// created by the framework inside AddBasic(). Reassigning the local variable (opts = source) would
 106    /// not work because only the local reference changes – the framework keeps the original instance.
 107    /// </summary>
 108    /// <param name="target">The target instance to which values will be copied. </param>
 109    public void ApplyTo(BasicAuthenticationOptions target)
 110    {
 111        // Copy properties from the provided configure object
 7112        target.HeaderName = HeaderName;
 7113        target.Base64Encoded = Base64Encoded;
 7114        if (SeparatorRegex is not null)
 115        {
 7116            target.SeparatorRegex = new Regex(SeparatorRegex.ToString(), SeparatorRegex.Options);
 117        }
 118
 7119        target.Realm = Realm;
 7120        target.AllowInsecureHttp = AllowInsecureHttp;
 7121        target.SuppressWwwAuthenticate = SuppressWwwAuthenticate;
 7122        target.ValidateCredentialsAsync = ValidateCredentialsAsync;
 123        // Copy properties from the provided configure object
 7124        target.ValidateCodeSettings = ValidateCodeSettings;
 7125        target.IssueClaimsCodeSettings = IssueClaimsCodeSettings;
 7126        target.IssueClaims = IssueClaims;
 127        // Claims policy configuration
 7128        target.ClaimPolicyConfig = ClaimPolicyConfig;
 129
 130        // Copy IAuthenticationHostOptions properties
 7131        target.Host = Host;
 132        // OpenAPI / documentation properties(IOpenApiAuthenticationOptions)
 7133        target.GlobalScheme = GlobalScheme;
 7134        target.Description = Description;
 7135        target.DocumentationId = DocumentationId;
 7136    }
 137}