Path: redb-identity/tests/redb.Identity.Tests/Module/IdentityModuleConfigBinderTests.cs
Snapshot: redb-identity, 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-identity
Page: https://redbase.app/src/dev-2026-12-06/redb-identity/tests/redb.Identity.Tests/Module/IdentityModuleConfigBinderTests.cs
----
using System.Net;
using AwesomeAssertions;
using NSubstitute;
using redb.Identity.Contracts.Configuration;
using redb.Identity.Core.Configuration;
using redb.Identity.Core.Module;
using redb.Route.Abstractions;
using redb.Route.Core;
using Xunit;
namespace redb.Identity.Tests.Module;
///
/// Verifies that correctly hydrates
/// from the nested IDictionary<string, object?>
/// structure that Tsak deposits on the route context via SetProperty.
///
public sealed class IdentityModuleConfigBinderTests
{
private static IRouteContext MakeContext(IDictionary? identitySection)
{
var sp = Substitute.For();
var ctx = new RouteContext(sp, "_test");
if (identitySection is not null)
ctx.SetProperty(IdentityModuleConfigBinder.SectionName, identitySection);
return ctx;
}
[Fact]
public void Bind_ReturnsDefaults_WhenNoIdentitySection()
{
var opts = IdentityModuleConfigBinder.Bind(MakeContext(null));
opts.Should().NotBeNull();
opts.Issuer.Should().Be(new Uri("https://localhost/"));
opts.RateLimit.Enabled.Should().BeFalse();
}
[Fact]
public void Bind_HydratesScalarsAndTimespans()
{
var section = new Dictionary
{
["RedbInstanceName"] = "identity-pg",
["Issuer"] = "https://identity.example.com/",
["AllowEphemeralKeys"] = "true",
["AccessTokenLifetime"] = "00:30:00",
["RecoveryCodePbkdf2Iterations"] = "750000",
["Features"] = new Dictionary
{
["EnableDeviceCodeFlow"] = "true",
},
};
var opts = IdentityModuleConfigBinder.Bind(MakeContext(section));
opts.RedbInstanceName.Should().Be("identity-pg");
opts.Issuer.Should().Be(new Uri("https://identity.example.com/"));
opts.AllowEphemeralKeys.Should().BeTrue();
opts.AccessTokenLifetime.Should().Be(TimeSpan.FromMinutes(30));
opts.RecoveryCodePbkdf2Iterations.Should().Be(750_000);
opts.Features.EnableDeviceCodeFlow.Should().BeTrue();
}
[Fact]
public void Bind_HydratesNestedRateLimitOptions()
{
var section = new Dictionary
{
["RateLimit"] = new Dictionary
{
["Enabled"] = "true",
["PerIpPerMinute"] = "120",
["PerIpUsernameFailures"] = "3",
["PerIpUsernameWindow"] = "00:30:00",
["Backend"] = "redis",
["RedisConnectionString"] = "localhost:6379",
["RedisKeyPrefix"] = "myapp:rl:"
}
};
var opts = IdentityModuleConfigBinder.Bind(MakeContext(section));
opts.RateLimit.Enabled.Should().BeTrue();
opts.RateLimit.PerIpPerMinute.Should().Be(120);
opts.RateLimit.PerIpUsernameFailures.Should().Be(3);
opts.RateLimit.PerIpUsernameWindow.Should().Be(TimeSpan.FromMinutes(30));
opts.RateLimit.Backend.Should().Be("redis");
opts.RateLimit.RedisConnectionString.Should().Be("localhost:6379");
opts.RateLimit.RedisKeyPrefix.Should().Be("myapp:rl:");
}
[Fact]
public void Bind_HydratesStringArrays()
{
var section = new Dictionary
{
["DynamicRegistrationAllowedScopes"] = new List