< Summary

Information
Class: Elsa.Identity.Providers.AdminApiKeyProvider
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Providers/AdminApiKeyProvider.cs
Line coverage
83%
Covered lines: 5
Uncovered lines: 1
Coverable lines: 6
Total lines: 27
Line coverage: 83.3%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
ProvideAsync(...)50%2280%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Providers/AdminApiKeyProvider.cs

#LineLine coverage
 1using System.Security.Claims;
 2using AspNetCore.Authentication.ApiKey;
 3using Elsa.Identity.Models;
 4
 5namespace Elsa.Identity.Providers;
 6
 7/// <summary>
 8/// Provides an <see cref="IApiKey"/> with admin privileges for the default admin API key.
 9/// </summary>
 10public class AdminApiKeyProvider : IApiKeyProvider
 11{
 12    /// <summary>
 13    /// The default admin API key.
 14    /// </summary>
 115    public static readonly string DefaultApiKey = Guid.Empty.ToString();
 16
 17    /// <inheritdoc />
 18    public Task<IApiKey?> ProvideAsync(string key)
 19    {
 23620        if(key != DefaultApiKey)
 021            return Task.FromResult<IApiKey?>(null);
 22
 23623        var claims = new List<Claim> { new("permissions", "*") };
 23624        var apiKey = new ApiKey(key, "admin", claims);
 23625        return Task.FromResult<IApiKey>(apiKey)!;
 26    }
 27}