fix(identity): harden user lifecycle and permissions
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

This commit is contained in:
arnaud.dartois committed 2026-11-04 10:26:07 +01:00
1 parent ea5f0b7589
commit 2bf3dbc95b
80 files changed
+1208 -507

No files matched your search

@@ -147,7 +147,7 @@ public class AuthFlowTests : IAsyncLifetime
/// This validates the complete auth pipeline works end-to-end.
/// </summary>
[Fact]
public async Task RegisterAdmin_ThenLogin_ReturnsJwt_AndAccessesProtectedApi()
public async Task FirstAdminBootstraps_AndCreatesFurtherAdminsThroughUserManagement()
{
var email = $"e2e-{Guid.NewGuid()}@heimdall.test";
var password = "E2eTestPwd123!";
@@ -166,33 +166,35 @@ public class AuthFlowTests : IAsyncLifetime
var bootToken = bootContent.GetProperty("accessToken").GetString();
bootToken.ShouldNotBeNullOrEmpty();
// Enable the admin-registration feature flag
// Further accounts, including additional administrators, use the same
// user-management path that the authenticated UI calls.
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", bootToken);
var flagResponse = await client.PostAsJsonAsync("/api/settings", new
var createResponse = await client.PostAsJsonAsync("/api/users", new
{
key = "auth.admin-registration.enabled",
value = "true",
valueType = "bool",
category = "Auth",
description = "Enable admin registration via API"
email,
password,
displayName = "E2E Test Admin",
roles = new[] { "Admin" }
});
flagResponse.StatusCode.ShouldBe(HttpStatusCode.OK);
createResponse.StatusCode.ShouldBe(HttpStatusCode.OK);
// Step 2: Register a new admin via RegisterAdmin
var registerResponse = await client.PostAsJsonAsync("/api/auth/register-admin", new
var legacyAdminRegistration = await client.PostAsJsonAsync("/api/auth/register-admin", new
{
email,
password,
displayName = "E2E Test Admin"
});
legacyAdminRegistration.StatusCode.ShouldBe(HttpStatusCode.NotFound);
registerResponse.StatusCode.ShouldBe(HttpStatusCode.OK);
var registerContent = await registerResponse.Content.ReadFromJsonAsync<JsonElement>(Json);
var accessToken = registerContent.GetProperty("accessToken").GetString();
var refreshToken = registerContent.GetProperty("refreshToken").GetString();
accessToken.ShouldNotBeNullOrEmpty("register-admin must return an access token");
refreshToken.ShouldNotBeNullOrEmpty("register-admin must return a refresh token");
// New accounts are not implicitly signed in by account-management actions.
var loginResponse = await client.PostAsJsonAsync("/api/auth/login", new { email, password });
loginResponse.StatusCode.ShouldBe(HttpStatusCode.OK);
var loginContent = await loginResponse.Content.ReadFromJsonAsync<JsonElement>(Json);
var accessToken = loginContent.GetProperty("accessToken").GetString();
var refreshToken = loginContent.GetProperty("refreshToken").GetString();
accessToken.ShouldNotBeNullOrEmpty();
refreshToken.ShouldNotBeNullOrEmpty();
// Step 3: Use the new admin token to access a protected API endpoint
client.DefaultRequestHeaders.Authorization =