< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.GoogleSignInRegistrationExtensions
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Registration/GoogleSignInRegistrationExtensions.cs
Line coverage
50%
Covered lines: 9
Uncovered lines: 9
Coverable lines: 18
Total lines: 58
Line coverage: 50%
Branch coverage
33%
Covered branches: 2
Total branches: 6
Branch coverage: 33.3%
Method coverage
100%
Covered methods: 1
Fully covered methods: 0
Total methods: 1
Method coverage: 100%
Full method coverage: 0%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddGoogleSignIn(...)33.33%11650%

File(s)

/home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Registration/GoogleSignInRegistrationExtensions.cs

#LineLine coverage
 1using ArturRios.Data.Relational.Core.DependencyInjection;
 2using ArturRios.Heimdall.Command.Services;
 3using ArturRios.Heimdall.WebApi.Security;
 4using ArturRios.Util.WebApi.Configuration;
 5using ArturRios.Util.WebApi.Security.Extensions;
 6using Serilog;
 7
 8namespace ArturRios.Heimdall.WebApi;
 9
 10public static class GoogleSignInRegistrationExtensions
 11{
 12    /// <summary>
 13    ///     Chooses how UC-25 verifies a Google ID token (FR-GO-11, NFR-13). With Google client IDs
 14    ///     configured, tokens are validated against Google; without them, every token is refused, so
 15    ///     an unconfigured deployment answers 401 rather than trusting a token no one checked.
 16    /// </summary>
 17    /// <remarks>
 18    ///     The third branch exists for the functional suite, which cannot override a DI registration
 19    ///     (<c>WebApiTest&lt;T&gt;</c> exposes neither its factory nor a settable gateway) and must
 20    ///     still reach the flows behind verification. It is guarded twice — never in Production, and
 21    ///     never without an explicitly set signing secret — and is checked before the real verifier so
 22    ///     a test environment cannot accidentally run both. See <see cref="LocalGoogleIdTokenVerifier" />.
 23    /// </remarks>
 24    public static IServiceCollection AddGoogleSignIn(this IServiceCollection services, IHostEnvironment environment)
 25    {
 97326        var options = GoogleSignInOptions.FromEnvironment();
 27
 97328        services.AddSingleton(options);
 29
 97330        if (!environment.IsProduction() && options.TestSigningConfigured)
 31        {
 97332            Log.Warning(
 97333                "Google ID tokens will be verified against a local signing secret ({Variable}), not " +
 97334                "against Google. This is for automated tests only",
 97335                GoogleSignInOptions.TestSigningSecretVariable);
 36
 97337            services.AddScoped<IGoogleIdTokenVerifier, LocalGoogleIdTokenVerifier>();
 38
 97339            return services;
 40        }
 41
 042        if (!options.GoogleConfigured)
 43        {
 044            Log.Warning(
 045                "No Google client is configured ({Variable}); Google sign-in (UC-25) will refuse " +
 046                "every token",
 047                GoogleSignInOptions.ClientIdsVariable);
 48
 049            services.AddScoped<IGoogleIdTokenVerifier, UnconfiguredGoogleIdTokenVerifier>();
 50
 051            return services;
 52        }
 53
 054        services.AddScoped<IGoogleIdTokenVerifier, GoogleIdTokenVerifier>();
 55
 056        return services;
 57    }
 58}