Files
jellyfin-plugin-sso/tests/SSO-Auth.Tests/SsoAuthServiceRegistratorTests.cs
unkin-agent a167d00b73
ci/woodpecker/pr/ci Pipeline was successful
store OAuth state in the shared cache
Keys each in-flight OpenID flow in the server's Valkey/Redis connection so a login
can start on one replica and finish on another. Falls back to an in-memory store
when no multiplexer is registered.
2026-09-19 22:47:43 +10:00

48 lines
1.5 KiB
C#

using Jellyfin.Plugin.SSO_Auth.State;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Moq;
using StackExchange.Redis;
using Xunit;
namespace Jellyfin.Plugin.SSO_Auth.Tests;
public class SsoAuthServiceRegistratorTests
{
[Fact]
public void RegisterServices_WithoutAMultiplexer_FallsBackToTheInMemoryStore()
{
var provider = Register(withMultiplexer: false);
Assert.IsType<InMemorySsoStateStore>(provider.GetRequiredService<ISsoStateStore>());
}
[Fact]
public void RegisterServices_WithAMultiplexer_UsesTheSharedStore()
{
var provider = Register(withMultiplexer: true);
Assert.IsType<RedisSsoStateStore>(provider.GetRequiredService<ISsoStateStore>());
}
private static ServiceProvider Register(bool withMultiplexer)
{
var loggerFactory = new Mock<ILoggerFactory>();
loggerFactory.Setup(f => f.CreateLogger(It.IsAny<string>())).Returns(new Mock<ILogger>().Object);
var services = new ServiceCollection();
services.AddSingleton(loggerFactory.Object);
if (withMultiplexer)
{
var mux = new Mock<IConnectionMultiplexer>();
mux.Setup(m => m.GetDatabase(It.IsAny<int>(), It.IsAny<object>())).Returns(new Mock<IDatabase>().Object);
services.AddSingleton(mux.Object);
}
new SsoAuthServiceRegistrator().RegisterServices(services, null);
return services.BuildServiceProvider();
}
}