< Summary

Information
Class: Elsa.Extensions.ExternalAuthenticationConfigurationExtensions
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Extensions/ExternalAuthenticationConfigurationExtensions.cs
Line coverage
95%
Covered lines: 21
Uncovered lines: 1
Coverable lines: 22
Total lines: 49
Line coverage: 95.4%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
BindExternalAuthenticationOptions(...)100%22100%
BindJsonSettings(...)75%44100%
GetJsonElement(...)50%22100%
GetIndexedChildren(...)0%2266.66%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Extensions/ExternalAuthenticationConfigurationExtensions.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.ExternalAuthentication.Models;
 3using Elsa.ExternalAuthentication.Options;
 4using Microsoft.Extensions.Configuration;
 5
 6namespace Elsa.Extensions;
 7
 8public static class ExternalAuthenticationConfigurationExtensions
 9{
 10    /// <summary>
 11    /// Binds external-authentication options and reconstructs configuration-backed JSON settings.
 12    /// </summary>
 13    public static void BindExternalAuthenticationOptions(this IConfigurationSection section, ExternalAuthenticationOptio
 14    {
 115        section.Bind(options);
 16
 117        var connectionSections = GetIndexedChildren(section.GetSection("Connections"));
 118        var connections = options.ConfigurationConnections.ToArray();
 419        for (var i = 0; i < Math.Min(connectionSections.Length, connections.Length); i++)
 120            BindJsonSettings(connectionSections[i], connections[i]);
 121    }
 22
 23    private static void BindJsonSettings(IConfigurationSection section, IdentityProviderConnection connection)
 24    {
 125        connection.AdapterSettings = GetJsonElement(section, "AdapterSettings");
 26
 127        if (connection.UnlinkedPolicy is not null)
 128            connection.UnlinkedPolicy = connection.UnlinkedPolicy with { Settings = GetJsonElement(section.GetSection("U
 29
 130        var grantSourceSections = GetIndexedChildren(section.GetSection("PermissionGrantSources"));
 131        var grantSources = connection.PermissionGrantSources.ToArray();
 132        connection.PermissionGrantSources = grantSources
 133            .Select((source, index) => index < grantSourceSections.Length
 134                ? source with { Settings = GetJsonElement(grantSourceSections[index], "Settings") }
 135                : source)
 136            .ToArray();
 137    }
 38
 39    private static JsonElement GetJsonElement(IConfiguration configuration, string sectionKey)
 40    {
 341        var json = configuration.GetSectionAsJson(sectionKey);
 342        return json is null ? default : JsonSerializer.Deserialize<JsonElement>(json);
 43    }
 44
 45    private static IConfigurationSection[] GetIndexedChildren(IConfigurationSection section) =>
 246        section.GetChildren()
 047            .OrderBy(child => int.TryParse(child.Key, out var index) ? index : int.MaxValue)
 248            .ToArray();
 49}