< Summary

Information
Class: Elsa.ExternalAuthentication.Services.ValidatedOutboundConnectionFactory
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Services/ValidatedOutboundConnectionFactory.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 40
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Services/ValidatedOutboundConnectionFactory.cs

#LineLine coverage
 1using System.Net;
 2using System.Net.Sockets;
 3using Elsa.ExternalAuthentication.Validation;
 4
 5namespace Elsa.ExternalAuthentication.Services;
 6
 7/// <summary>
 8/// Pins each outbound connection to an address that was resolved and validated at connection time.
 9/// </summary>
 310public sealed class ValidatedOutboundConnectionFactory(OutboundDestinationValidator destinationValidator, IValidatedAddr
 11{
 12    public async ValueTask<Stream> ConnectAsync(DnsEndPoint endpoint, CancellationToken cancellationToken = default)
 13    {
 214        var address = await destinationValidator.ResolveApprovedAddressAsync(endpoint, cancellationToken);
 115        return await connector.ConnectAsync(address, endpoint.Port, cancellationToken);
 116    }
 17}
 18
 19public interface IValidatedAddressConnector
 20{
 21    ValueTask<Stream> ConnectAsync(IPAddress address, int port, CancellationToken cancellationToken = default);
 22}
 23
 24public sealed class SocketValidatedAddressConnector : IValidatedAddressConnector
 25{
 26    public async ValueTask<Stream> ConnectAsync(IPAddress address, int port, CancellationToken cancellationToken = defau
 27    {
 28        var socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
 29        try
 30        {
 31            await socket.ConnectAsync(new IPEndPoint(address, port), cancellationToken);
 32            return new NetworkStream(socket, ownsSocket: true);
 33        }
 34        catch
 35        {
 36            socket.Dispose();
 37            throw;
 38        }
 39    }
 40}