Files
Heimdall/tests/Heimdall.E2E.Tests/Pages/SessionRefreshTests.cs
T
arnaud.dartois 2bf3dbc95b
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
fix(identity): harden user lifecycle and permissions
2026-11-04 10:26:07 +01:00

39 lines
1.9 KiB
C#

using Heimdall.Infrastructure.Data;
using System.IdentityModel.Tokens.Jwt;
using System.Text.Json;
using Heimdall.TestCommon;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Playwright;
using Shouldly;
namespace Heimdall.E2E.Tests.Pages;
[Collection("E2E")]
public sealed class SessionRefreshTests(PostgreSqlContainerFixture postgres) : E2ETestBase(postgres)
{
[Fact]
public async Task Active_blazor_session_refreshes_expired_nonempty_jwt_without_http_context()
{
App.Configuration["Jwt:AccessTokenExpiryMinutes"] = "0.25";
var signinRequest = Page.WaitForRequestAsync(r => r.Url.EndsWith("/_auth/signin", StringComparison.Ordinal));
await LoginViaUiAsync();
using var payload = JsonDocument.Parse((await signinRequest).PostData!);
var access = new JwtSecurityTokenHandler().ReadJwtToken(payload.RootElement.GetProperty("accessToken").GetString());
(access.ValidTo - DateTime.UtcNow).TotalSeconds.ShouldBeInRange(0, 16);
await Page.WaitForSelectorAsync("text=Bienvenue", new() { Timeout = 15000 });
int before;
using (var scope = App.Services.CreateScope())
before = await scope.ServiceProvider.GetRequiredService<AppDbContext>().RevokedRefreshTokens.CountAsync();
await Task.Delay(TimeSpan.FromSeconds(17));
App.Configuration["Jwt:AccessTokenExpiryMinutes"] = "15";
await Page.GetByRole(AriaRole.Button, new() { Name = "Gestion des utilisateurs" }).ClickAsync();
await Page.Locator("a[href='/users']:visible").First.ClickAsync();
await Page.WaitForSelectorAsync($"text={AdminEmail}", new() { Timeout = 15000 });
Page.Url.ShouldNotContain("/login");
using var after = App.Services.CreateScope();
(await after.ServiceProvider.GetRequiredService<AppDbContext>().RevokedRefreshTokens.CountAsync()).ShouldBeGreaterThan(before);
}
}