< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Authentication.AuthenticationBuilderExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Authentication/AuthenticationBuilderExtension.cs
Tag: Kestrun/Kestrun@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
95%
Covered lines: 23
Uncovered lines: 1
Coverable lines: 24
Total lines: 54
Line coverage: 95.8%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/12/2025 - 17:27:19 Line coverage: 0% (0/24) Branch coverage: 0% (0/2) Total lines: 54 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd03/26/2026 - 03:54:59 Line coverage: 95.8% (23/24) Branch coverage: 50% (1/2) Total lines: 54 Tag: Kestrun/Kestrun@844b5179fb0492dc6b1182bae3ff65fa7365521d 12/12/2025 - 17:27:19 Line coverage: 0% (0/24) Branch coverage: 0% (0/2) Total lines: 54 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd03/26/2026 - 03:54:59 Line coverage: 95.8% (23/24) Branch coverage: 50% (1/2) Total lines: 54 Tag: Kestrun/Kestrun@844b5179fb0492dc6b1182bae3ff65fa7365521d

Coverage delta

Coverage delta 96 -96

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddCookie(...)50%2295.83%

File(s)

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

#LineLine coverage
 1
 2using Microsoft.AspNetCore.Authentication;
 3using Microsoft.AspNetCore.Authentication.Cookies;
 4using Microsoft.Extensions.DependencyInjection.Extensions;
 5using Microsoft.Extensions.Options;
 6
 7namespace Kestrun.Authentication;
 8
 9/// <summary>
 10/// Extension methods for <see cref="AuthenticationBuilder"/> to add cookie authentication.
 11/// </summary>
 12internal static class AuthenticationBuilderExtensions
 13{
 14    /// <summary>
 15    /// Adds cookie authentication to <see cref="AuthenticationBuilder"/> using the specified scheme.
 16    /// <para>
 17    /// Cookie authentication uses a HTTP cookie persisted in the client to perform authentication.
 18    /// </para>
 19    /// </summary>
 20    /// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
 21    /// <param name="authenticationScheme">The authentication scheme.</param>
 22    /// <param name="displayName">A display name for the authentication handler.</param>
 23    /// <param name="configureOptions">A delegate to configure <see cref="CookieAuthenticationOptions"/>.</param>
 24    /// <returns>A reference to <paramref name="builder"/> after the operation has completed.</returns>
 25    public static AuthenticationBuilder AddCookie(this AuthenticationBuilder builder, string authenticationScheme, strin
 26    {
 127        builder.Services.TryAddEnumerable(
 128            ServiceDescriptor.Singleton<
 129                IPostConfigureOptions<CookieAuthenticationOptions>,
 130                PostConfigureCookieAuthenticationOptions>());
 31
 132        _ = builder.Services
 133            .AddOptions<CookieAuthenticationOptions>(authenticationScheme)
 134            .Validate(o => o.Cookie.Expiration == null,
 135                "Cookie.Expiration is ignored, use ExpireTimeSpan instead.");
 36
 137        return builder.AddScheme<CookieAuthenticationOptions, CookieAuthenticationHandler>(authenticationScheme, display
 138            {
 139                if (configureOptions is null)
 140                {
 041                    return;
 142                }
 143
 144                // Start from a fresh Kestrun-friendly options object
 145                var userOptions = new CookieAuthOptions();
 146
 147                // Let the caller configure all the rich stuff
 148                configureOptions(userOptions);
 149
 150                // Push everything into the real framework options
 151                userOptions.ApplyTo(options);
 252            });
 53    }
 54}