feat(security): wire Security:Auth:DisableLogin into AddOtOpcUaAuth

This commit is contained in:
Joseph Doherty
2026-06-11 04:39:23 -04:00
parent caeaae21f9
commit 82fec753c8
2 changed files with 68 additions and 2 deletions
@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Security;
using ZB.MOM.WW.OtOpcUa.Security.Auth;
namespace ZB.MOM.WW.OtOpcUa.Security.Tests;
public class AddOtOpcUaAuthWiringTests
{
private static async Task<Type> CookieHandlerTypeAsync(bool disableLogin)
{
var config = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
{
["Security:Auth:DisableLogin"] = disableLogin ? "true" : "false",
}).Build();
var services = new ServiceCollection();
services.AddLogging();
services.AddOtOpcUaAuth(config);
await using var sp = services.BuildServiceProvider();
var provider = sp.GetRequiredService<IAuthenticationSchemeProvider>();
var scheme = await provider.GetSchemeAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return scheme!.HandlerType;
}
[Fact]
public async Task DisableLogin_true_registers_autologin_handler_for_cookie_scheme()
=> (await CookieHandlerTypeAsync(true)).ShouldBe(typeof(AutoLoginAuthenticationHandler));
[Fact]
public async Task DisableLogin_false_registers_cookie_handler()
=> (await CookieHandlerTypeAsync(false)).ShouldBe(typeof(CookieAuthenticationHandler));
}