< Summary

Information
Class: Elsa.Connections.Services.DefaultConnectionMetadataInspector
Assembly: Elsa.Connections
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Connections/Services/DefaultConnectionMetadataInspector.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 40
Line coverage: 100%
Branch coverage
100%
Covered branches: 30
Total branches: 30
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
InspectAsync()100%3030100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Connections/Services/DefaultConnectionMetadataInspector.cs

#LineLine coverage
 1using System.Security.Claims;
 2using Elsa.Common.Multitenancy;
 3using Elsa.Connections.Contracts;
 4using Elsa.Connections.Features;
 5using Microsoft.Extensions.Options;
 6
 7namespace Elsa.Connections.Services;
 8
 9/// <summary>Separates metadata inspection from connection management and credential use.</summary>
 410public sealed class DefaultConnectionMetadataInspector(
 411    IConnectionLifecycleStore? store,
 412    IConnectionUseAuthorizer authorizer,
 413    ITenantAccessor tenantAccessor,
 414    IOptions<ConnectionInspectionOptions> options) : IConnectionMetadataInspector
 15{
 16    public async Task<ConnectionInspectionMetadata?> InspectAsync(
 17        ClaimsPrincipal principal, string connectionId, CancellationToken cancellationToken = default)
 18    {
 1119        var tenantId = tenantAccessor.TenantId;
 1120        var environmentId = options.Value.EnvironmentId;
 1121        if (store is null || principal.Identity?.IsAuthenticated != true || string.IsNullOrWhiteSpace(connectionId) || c
 1122            string.IsNullOrWhiteSpace(tenantId) || tenantId is Tenant.DefaultTenantId or Tenant.AgnosticTenantId || tena
 1123            string.IsNullOrWhiteSpace(environmentId) || environmentId.Length > 200)
 24        {
 625            return null;
 26        }
 27
 528        var request = new ConnectionUseRequest(principal, ConnectionUseKind.Human, tenantId, environmentId, connectionId
 529        if (!await authorizer.AuthorizeAsync(request, cancellationToken))
 30        {
 331            return null;
 32        }
 33
 234        var connection = await store.FindAsync(connectionId, tenantId, environmentId, cancellationToken);
 235        return connection is null
 236            ? null
 237            : new ConnectionInspectionMetadata(connection.Id, connection.ProviderId, connection.ProviderAccountId,
 238                connection.Status, connection.Revision);
 1139    }
 40}