Files
Heimdall/tests/Heimdall.Web.Tests/Services/AuthStateTests.cs
T
arnaud.dartois 89c4c43922
Heimdall Gitea / Detect CI scope (push) Successful in 7s
Heimdall Gitea / Build and tests (push) Successful in 14m48s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 4m27s
Heimdall Gitea / Build and scan agent image (push) Successful in 15m42s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m27s
Heimdall Gitea / CI policy (push) Successful in 2s
fix(identity): harden user lifecycle and permissions (#136)
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-04 13:33:30 +01:00

52 lines
1.6 KiB
C#

using Heimdall.Web.Services;
using Shouldly;
namespace Heimdall.Web.Tests.Services;
public class AuthStateTests
{
private static AuthResponse AuthResponse(string token = "access") => new(
token, "refresh", DateTime.UtcNow.AddHours(1), false,
new UserInfo(Guid.NewGuid(), "admin@heimdall.test", "Admin", ["Admin"]));
[Fact]
public void Login_EffaceLeCookieCapture()
{
var state = new AuthState { AuthCookie = "CfDJ8-vieux-cookie" };
state.Login(AuthResponse());
// Le JWT prend le relais : l'ancien cookie ne doit plus être propagé
state.AuthCookie.ShouldBeNull();
state.AccessToken.ShouldBe("access");
}
[Fact]
public void Logout_EffaceAussiLeCookieCapture()
{
var state = new AuthState { AuthCookie = "CfDJ8-cookie" };
state.Login(AuthResponse());
state.AuthCookie.ShouldBeNull();
// Simule une restauration SSR puis une déconnexion
state.AuthCookie = "CfDJ8-cookie";
state.Logout();
state.AuthCookie.ShouldBeNull();
state.IsLoggedIn.ShouldBeFalse();
}
[Fact]
public void Login_UsesPersistedPermissionsFromTheAuthResponse()
{
var response = new AuthResponse("access", "refresh", DateTime.UtcNow.AddHours(1), false,
new UserInfo(Guid.NewGuid(), "viewer@heimdall.test", "Viewer", ["Viewer"], ["Camera.Write"]));
var state = new AuthState();
state.Login(response);
state.HasPermission("Camera.Write").ShouldBeTrue();
state.HasPermission("Camera.Live").ShouldBeFalse();
}
}