2026-08-10 12:46:15 +02:00
|
|
|
using Heimdall.Web.Services;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Web.Tests.Services;
|
|
|
|
|
|
|
|
|
|
public class AuthStateTests
|
|
|
|
|
{
|
2026-08-11 11:59:18 +02:00
|
|
|
private static AuthResponse AuthResponse(string token = "access") => new(
|
|
|
|
|
token, "refresh", DateTime.UtcNow.AddHours(1), false,
|
|
|
|
|
new UserInfo(Guid.NewGuid(), "admin@heimdall.test", "Admin", ["Admin"]));
|
2026-08-10 12:46:15 +02:00
|
|
|
|
|
|
|
|
[Fact]
|
2026-08-11 11:59:18 +02:00
|
|
|
public void Login_EffaceLeCookieCapture()
|
2026-08-10 12:46:15 +02:00
|
|
|
{
|
2026-08-11 11:59:18 +02:00
|
|
|
var state = new AuthState { AuthCookie = "CfDJ8-vieux-cookie" };
|
2026-08-10 12:46:15 +02:00
|
|
|
|
2026-08-11 11:59:18 +02:00
|
|
|
state.Login(AuthResponse());
|
2026-08-10 12:46:15 +02:00
|
|
|
|
2026-08-11 11:59:18 +02:00
|
|
|
// Le JWT prend le relais : l'ancien cookie ne doit plus être propagé
|
|
|
|
|
state.AuthCookie.ShouldBeNull();
|
|
|
|
|
state.AccessToken.ShouldBe("access");
|
2026-08-10 12:46:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-08-11 11:59:18 +02:00
|
|
|
public void Logout_EffaceAussiLeCookieCapture()
|
2026-08-10 12:46:15 +02:00
|
|
|
{
|
2026-08-11 11:59:18 +02:00
|
|
|
var state = new AuthState { AuthCookie = "CfDJ8-cookie" };
|
|
|
|
|
state.Login(AuthResponse());
|
|
|
|
|
state.AuthCookie.ShouldBeNull();
|
2026-08-10 12:46:15 +02:00
|
|
|
|
2026-08-11 11:59:18 +02:00
|
|
|
// Simule une restauration SSR puis une déconnexion
|
|
|
|
|
state.AuthCookie = "CfDJ8-cookie";
|
2026-08-10 12:46:15 +02:00
|
|
|
state.Logout();
|
|
|
|
|
|
2026-08-11 11:59:18 +02:00
|
|
|
state.AuthCookie.ShouldBeNull();
|
2026-08-10 12:46:15 +02:00
|
|
|
state.IsLoggedIn.ShouldBeFalse();
|
|
|
|
|
}
|
|
|
|
|
}
|