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

@@ -69,4 +69,30 @@ public class UsersControllerTests : PostgresTestBase
var resetContent = await resetResponse.Content.ReadFromJsonAsync<JsonElement>();
resetContent.GetProperty("temporaryPassword").GetString().ShouldNotBeNullOrEmpty();
}
[Fact]
public async Task Last_unlocked_admin_cannot_be_locked_when_another_admin_is_already_locked()
{
var admin = await Factory.CreateAdminClientAsync();
var list = await admin.GetFromJsonAsync<JsonElement>("api/users?page=1&pageSize=20");
var firstAdminId = list.GetProperty("items").EnumerateArray()
.Single(user => user.GetProperty("roles").EnumerateArray().Any(role => role.GetString() == "Admin"))
.GetProperty("id").GetGuid();
var created = await admin.PostAsJsonAsync("api/users", new
{
email = $"extra-admin-{Guid.NewGuid():N}@heimdall.test",
password = "ExtraAdmin123!",
displayName = "Extra Admin",
roles = new[] { "Admin" }
});
created.EnsureSuccessStatusCode();
var secondAdminId = (await created.Content.ReadFromJsonAsync<JsonElement>())
.GetProperty("id").GetGuid();
(await admin.PostAsync($"api/users/{secondAdminId}/lock", null)).StatusCode
.ShouldBe(System.Net.HttpStatusCode.OK);
var lockLast = await admin.PostAsync($"api/users/{firstAdminId}/lock", null);
lockLast.StatusCode.ShouldBe(System.Net.HttpStatusCode.BadRequest);
}
}