Heimdall Gitea / Detect CI scope (pull_request) Successful in 5s
Heimdall Gitea / Build and tests (pull_request) Successful in 20m8s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Failing after 6m10s
Heimdall Gitea / Build and scan server image (pull_request) Failing after 8m2s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 2s
52 lines
1.6 KiB
C#
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();
|
|
}
|
|
}
|