- Implement UserCameraAccess entity and CRUD API (issues #131, #133) - Add CameraAccessPanel UI component for granular access management (issue #134) - Implement camera toggle UI (issues #59, #199) - Implement site filtering by user rights (issue #136) - Implement Groups camera access assignment (issue #138) - Implement audit logging for camera access changes (issue #140) - Add comprehensive camera access test coverage (issue #141) - Implement i18n/l10n localization infrastructure (issue #142) - Implement OpenTelemetry metrics infrastructure (issue #14) - Implement Agent GPU worker (issue #76) - Implement Agent remote sensor mode (issue #75) - Fix Docker GPU exposure in compose files (issues #76, #77) - Fix mDNS divergence by extracting shared MdnsClient library (issue #81) - Implement User email confirm/edit UI (issues #88, #89) - Implement Persons UI (issue #11) - Fix E2E test timing issues by increasing circuit delay - Add MdnsClient library with unified unicast/multicast mDNS support - Refactor MdnsProbeService and HomeKitMdnsProbe to use shared client - Add GroupCameraAccess entity for group-based camera access - Add comprehensive camera access test coverage - Add i18n localization infrastructure with fr/en support - Add Docker GPU exposure for NVIDIA/AMD/Intel - Update Docker compose files with GPU device exposure - Fix mDNS divergence between Central unicast and Agent multicast - Fix E2E test timing issues with increased circuit delay All 1700+ tests pass (unit + integration)
158 lines
6.7 KiB
C#
158 lines
6.7 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using Heimdall.TestCommon;
|
|
using Microsoft.Playwright;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.E2E.Tests.Pages;
|
|
|
|
/// <summary>
|
|
/// User-management tests driven through the real Blazor UI (/users):
|
|
/// list, create, edit roles, lock/unlock, reset password — as the seeded admin.
|
|
/// </summary>
|
|
public class UserManagementTests : E2ETestBase
|
|
{
|
|
public UserManagementTests(PostgreSqlContainerFixture postgres) : base(postgres) { }
|
|
|
|
[Fact]
|
|
public async Task Users_page_lists_admin_when_authenticated()
|
|
{
|
|
await LoginViaUiAsync();
|
|
await GotoWithCircuitAsync("/users");
|
|
// Wait for the specific element that indicates the page is fully loaded
|
|
await Page.WaitForSelectorAsync("text=Nouvel utilisateur", new() { Timeout = 60000 });
|
|
await Page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
|
await Task.Delay(3000);
|
|
|
|
var body = (await Page.Locator("body").TextContentAsync())!;
|
|
body.ShouldContain(AdminEmail);
|
|
body.ShouldContain("Admin Test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Admin_can_create_a_viewer_user_via_the_dialog()
|
|
{
|
|
await LoginViaUiAsync();
|
|
await GotoWithCircuitAsync("/users");
|
|
await Page.WaitForSelectorAsync("text=Nouvel utilisateur", new() { Timeout = 20000 });
|
|
|
|
await Page.ClickAsync("text=Nouvel utilisateur");
|
|
var dialog = Page.Locator(".mud-dialog");
|
|
await dialog.WaitForAsync(new() { Timeout = 10000 });
|
|
await dialog.Locator("input[autocomplete='email']").WaitForAsync(new() { Timeout = 10000 });
|
|
|
|
var email = $"e2e-user-{Guid.NewGuid():N}@heimdall.test";
|
|
await dialog.Locator("input[autocomplete='email']").FillAsync(email);
|
|
await dialog.Locator("input[autocomplete='name']").FillAsync("E2E Viewer");
|
|
await dialog.Locator("input[autocomplete='new-password']").FillAsync("ViewerPass123!");
|
|
|
|
// Role defaults to Viewer in the select — create directly
|
|
await dialog.Locator("button:has-text('Créer')").ClickAsync();
|
|
|
|
// Dialog closes, table reloads and contains the new user
|
|
await Page.WaitForSelectorAsync($"text={email}", new() { Timeout = 15000 });
|
|
var body = (await Page.Locator("body").TextContentAsync())!;
|
|
body.ShouldContain("E2E Viewer");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task New_user_can_log_in_with_viewer_role()
|
|
{
|
|
// Create a viewer through the API (admin token), then sign in via the UI
|
|
var email = $"e2e-viewer-{Guid.NewGuid():N}@heimdall.test";
|
|
var password = "ViewerPass123!";
|
|
var token = await LoginViaApiAsync();
|
|
using var http = new HttpClient { BaseAddress = new Uri(BaseUrl) };
|
|
http.DefaultRequestHeaders.Authorization = new("Bearer", token);
|
|
var createResp = await http.PostAsJsonAsync("/api/users", new
|
|
{
|
|
email,
|
|
password,
|
|
displayName = "E2E Viewer Login",
|
|
roles = new[] { "Viewer" }
|
|
});
|
|
createResp.StatusCode.ShouldBeOneOf(HttpStatusCode.OK, HttpStatusCode.Created);
|
|
|
|
await GotoWithCircuitAsync("/login");
|
|
await Page.FillAsync("input[autocomplete='email']", email);
|
|
await Page.FillAsync("input[autocomplete='current-password']", password);
|
|
await Page.ClickAsync("button:has-text('Se connecter')");
|
|
await Page.WaitForURLAsync("**/dashboard**", new() { Timeout = 20000 });
|
|
await Page.WaitForSelectorAsync("text=Bienvenue", new() { Timeout = 15000 });
|
|
|
|
(await Page.Locator("body").TextContentAsync())!.ShouldContain("Bienvenue");
|
|
|
|
// A viewer must NOT see the admin Users page in the nav
|
|
var usersNav = await Page.Locator("a[href='/users']").CountAsync();
|
|
usersNav.ShouldBe(0);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Admin_can_edit_user_display_name_and_roles()
|
|
{
|
|
// Create a throwaway user via the API
|
|
var email = $"e2e-edit-{Guid.NewGuid():N}@heimdall.test";
|
|
var token = await LoginViaApiAsync();
|
|
using var http = new HttpClient { BaseAddress = new Uri(BaseUrl) };
|
|
http.DefaultRequestHeaders.Authorization = new("Bearer", token);
|
|
var createResp = await http.PostAsJsonAsync("/api/users", new
|
|
{
|
|
email,
|
|
password = "EditPass123!",
|
|
displayName = "Avant Modification",
|
|
roles = new[] { "Viewer" }
|
|
});
|
|
createResp.StatusCode.ShouldBeOneOf(HttpStatusCode.OK, HttpStatusCode.Created);
|
|
|
|
await LoginViaUiAsync();
|
|
await GotoWithCircuitAsync("/users");
|
|
await Page.WaitForSelectorAsync($"text={email}", new() { Timeout = 20000 });
|
|
|
|
// Open the edit dialog via the pencil icon in the user row
|
|
var row = Page.Locator($"tr:has-text('{email}')");
|
|
await row.Locator("button").First.ClickAsync();
|
|
|
|
// Rename + grant Supervisor (scope to the edit dialog)
|
|
var dialog = Page.Locator(".mud-dialog");
|
|
await dialog.WaitForAsync(new() { Timeout = 10000 });
|
|
// The display-name field is the first text input in the dialog
|
|
var nameInput = dialog.Locator("input:not([type='password'])").First;
|
|
await nameInput.WaitForAsync(new() { Timeout = 10000 });
|
|
await nameInput.FillAsync("Après Modification");
|
|
await dialog.Locator("label:has-text('Supervisor')").ClickAsync();
|
|
|
|
await dialog.Locator("button:has-text('Enregistrer')").ClickAsync();
|
|
await Page.WaitForSelectorAsync("text=Après Modification", new() { Timeout = 15000 });
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Admin_can_reset_user_password()
|
|
{
|
|
var email = $"e2e-reset-{Guid.NewGuid():N}@heimdall.test";
|
|
var token = await LoginViaApiAsync();
|
|
using var http = new HttpClient { BaseAddress = new Uri(BaseUrl) };
|
|
http.DefaultRequestHeaders.Authorization = new("Bearer", token);
|
|
var createResp = await http.PostAsJsonAsync("/api/users", new
|
|
{
|
|
email,
|
|
password = "ResetPass123!",
|
|
displayName = "E2E Reset",
|
|
roles = new[] { "Viewer" }
|
|
});
|
|
createResp.StatusCode.ShouldBeOneOf(HttpStatusCode.OK, HttpStatusCode.Created);
|
|
|
|
await LoginViaUiAsync();
|
|
await GotoWithCircuitAsync("/users");
|
|
await Page.WaitForSelectorAsync($"text={email}", new() { Timeout = 20000 });
|
|
|
|
var row = Page.Locator($"tr:has-text('{email}')");
|
|
await row.Locator("button").First.ClickAsync();
|
|
|
|
var dialog = Page.Locator(".mud-dialog");
|
|
await dialog.WaitForAsync(new() { Timeout = 10000 });
|
|
await dialog.Locator("button:has-text('Réinitialiser le mot de passe')").ClickAsync();
|
|
// The dialog reveals a temporary password
|
|
await dialog.Locator("text=temporaire").WaitForAsync(new() { Timeout = 10000 });
|
|
}
|
|
}
|