39 lines
1.1 KiB
C#
39 lines
1.1 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();
|
|
}
|
|
}
|