Path: redb-route/tests/redb.Route.Tests.Tcp/TcpConnectionFactoryTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Tcp/TcpConnectionFactoryTests.cs
----
using redb.Route.Core;
using redb.Route.Tcp;
namespace redb.Route.Tests.Tcp;
///
/// The TLS certificate password must be able to live in the registry instead of the endpoint URI,
/// so it never reaches logs, telemetry, or the dashboard.
///
public sealed class TcpConnectionFactoryTests
{
private const string Secret = "pfxP4ssw0rd";
private static TcpComponent Wire(string name, TcpConnectionFactory factory)
{
var context = new RouteContext();
var component = new TcpComponent();
context.AddComponent(component);
context.AddToRegistry(name, factory);
return component;
}
[Fact]
public void Factory_SuppliesCertPassword_WhenUriCarriesNone()
{
var component = Wire("secure-tcp", new TcpConnectionFactory
{
Ssl = true,
SslCertPath = "/etc/redb/certs/server.pfx",
SslCertPassword = Secret,
ConnectTimeout = 5_000
});
var uri = EndpointUriParser.Parse("tcp://0.0.0.0:9100?connectionFactory=secure-tcp");
var endpoint = component.CreateEndpoint(uri);
endpoint.Should().NotBeNull();
uri.ToUriString().Should().NotContain(Secret);
uri.ToString().Should().NotContain(Secret);
}
[Fact]
public void ExplicitUriValue_WinsOverFactory()
{
var component = Wire("f", new TcpConnectionFactory
{
Ssl = true,
ConnectTimeout = 5_000
});
var uri = EndpointUriParser.Parse(
"tcp://0.0.0.0:9100?connectionFactory=f&connectTimeout=1234");
component.CreateEndpoint(uri).Should().NotBeNull();
uri.RawParameters["connectTimeout"].Should().Be("1234");
}
[Fact]
public void MissingFactory_FailsLoud()
{
var context = new RouteContext();
var component = new TcpComponent();
context.AddComponent(component);
var uri = EndpointUriParser.Parse("tcp://0.0.0.0:9100?connectionFactory=absent");
var act = () => component.CreateEndpoint(uri);
// A typo in connectionFactory must fail loud, not fall back silently
act.Should().Throw()
.Which.Message.Should().Contain("absent");
}
}