Path: redb-identity/tests/redb.Identity.Tests/FullStack/ManagementDeleteAcrossResourcesTests.cs Snapshot: redb-identity, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-identity Page: https://redbase.app/src/dev-2026-12-06/redb-identity/tests/redb.Identity.Tests/FullStack/ManagementDeleteAcrossResourcesTests.cs ---- using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; using AwesomeAssertions; using redb.Identity.Tests.Infrastructure; using Xunit; using Xunit.Abstractions; namespace redb.Identity.Tests.FullStack; /// /// A management DELETE removes a record of its own resource and nothing else. Given the id of a record /// of another resource it answers 404 and that record stays: the scopes that guard each resource /// (applications.write, groups.write, …) mean nothing if one of them can remove the records of another. /// [Collection("ProductionHttp")] public class ManagementDeleteAcrossResourcesTests { private readonly ProductionHttpFixture _fx; private readonly ITestOutputHelper _out; public ManagementDeleteAcrossResourcesTests(ProductionHttpFixture fx, ITestOutputHelper output) { _fx = fx; _out = output; } [Theory] [InlineData("applications")] [InlineData("scopes")] [InlineData("claim-definitions")] [InlineData("roles")] [InlineData("claim-mappers")] [InlineData("claim-scopes")] public async Task DeletingAGroupsIdThroughAnotherResource_LeavesTheGroup(string resource) { var groupId = await CreateAsync("/api/v1/identity/groups", new { name = "cross-delete-" + Guid.NewGuid().ToString("N")[..12] }); using var delete = await SendAsync(HttpMethod.Delete, $"/api/v1/identity/{resource}/{groupId}", null); var answer = await delete.Content.ReadAsStringAsync(); _out.WriteLine($"DELETE /{resource}/{groupId} (a group) -> [{(int)delete.StatusCode}] {answer}"); using var still = await SendAsync(HttpMethod.Get, $"/api/v1/identity/groups/{groupId}", null); ((int)still.StatusCode).Should().Be(200, $"the group must survive a DELETE on /{resource}"); ((int)delete.StatusCode).Should().Be(404, answer); } [Fact] public async Task DeletingARolesIdThroughGroups_LeavesTheRole() { var roleId = await CreateAsync("/api/v1/identity/roles", new { name = "cross-delete-role-" + Guid.NewGuid().ToString("N")[..12], audience = "organization" }); using var delete = await SendAsync(HttpMethod.Delete, $"/api/v1/identity/groups/{roleId}", null); var answer = await delete.Content.ReadAsStringAsync(); _out.WriteLine($"DELETE /groups/{roleId} (a role) -> [{(int)delete.StatusCode}] {answer}"); using var still = await SendAsync(HttpMethod.Get, $"/api/v1/identity/roles/{roleId}", null); ((int)still.StatusCode).Should().Be(200, "the role must survive a DELETE on /groups"); ((int)delete.StatusCode).Should().Be(404, answer); } private async Task CreateAsync(string path, object body) { using var response = await SendAsync(HttpMethod.Post, path, body); var answer = await response.Content.ReadAsStringAsync(); ((int)response.StatusCode).Should().BeInRange(200, 299, answer); return JsonDocument.Parse(answer).RootElement.GetProperty("id").ToString(); } private Task SendAsync(HttpMethod method, string path, object? body) { var request = new HttpRequestMessage(method, path); if (body is not null) request.Content = JsonContent.Create(body); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fx.ManagementToken); return _fx.Http.SendAsync(request); } }