Path: redb-identity/tests/redb.Identity.Tests/FullStack/ManagementResultWireTests.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/ManagementResultWireTests.cs ---- using System.Net; using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; using System.Text.RegularExpressions; using AwesomeAssertions; using redb.Identity.Tests.Infrastructure; using Xunit; namespace redb.Identity.Tests.FullStack; /// /// The management API's answers as bytes on the wire, one case per kind of result body: the error document, /// the success answers with their optional members, the revoked count and the token prune results. The /// expected strings are what these routes answered before their bodies became declared types in /// redb.Identity.Contracts; a renamed member, a reordered one or a null that starts being written fails here. /// [Collection("ProductionHttp")] public class ManagementResultWireTests { private readonly ProductionHttpFixture _fx; public ManagementResultWireTests(ProductionHttpFixture fx) => _fx = fx; [Fact] public async Task Not_found_is_the_error_document() { var (status, body) = await SendAsync(HttpMethod.Get, "/api/v1/identity/applications/987654321"); status.Should().Be(HttpStatusCode.NotFound); body.Should().Be("""{"error":"not_found","error_description":"Application not found"}"""); } [Fact] public async Task A_validation_refusal_is_the_error_document() { var (status, body) = await SendAsync(HttpMethod.Post, "/api/v1/identity/scopes", new { name = "bad name!" }); status.Should().Be(HttpStatusCode.BadRequest); Regex.IsMatch(body, """^\{"error":"validation_error","error_description":"[^"]+"\}$""").Should().BeTrue(body); } [Fact] public async Task A_missing_token_is_the_error_document_with_its_id() { var (status, body) = await SendAsync(HttpMethod.Delete, "/api/v1/identity/tokens/987654321"); status.Should().Be(HttpStatusCode.NotFound); body.Should().Be("""{"error":"not_found","error_description":"Token 987654321 not found"}"""); } [Fact] public async Task Deleting_a_scope_answers_success_alone() { var name = "wire_" + Guid.NewGuid().ToString("N")[..10]; var (createStatus, created) = await SendAsync(HttpMethod.Post, "/api/v1/identity/scopes", new { name }); createStatus.Should().Be(HttpStatusCode.OK, created); var id = Id(created); var (status, body) = await SendAsync(HttpMethod.Delete, $"/api/v1/identity/scopes/{id}"); status.Should().Be(HttpStatusCode.OK); body.Should().Be("""{"success":true}"""); } [Fact] public async Task Deleting_a_user_answers_success_and_the_sessions_revoked() { var id = await CreateUserAsync(); var (status, body) = await SendAsync(HttpMethod.Delete, $"/api/v1/identity/users/{id}"); status.Should().Be(HttpStatusCode.OK); body.Should().Be("""{"success":true,"sessionsRevoked":0}"""); } [Fact] public async Task Admin_password_reset_answers_success_and_the_sessions_revoked() { var id = await CreateUserAsync(); var (status, body) = await SendAsync(HttpMethod.Post, $"/api/v1/identity/users/{id}/admin-reset-password", new { id = long.Parse(id), newPassword = "Reset1234Pass!x" }); status.Should().Be(HttpStatusCode.OK, body); body.Should().Be("""{"success":true,"sessionsRevoked":0}"""); } [Fact] public async Task Revoking_a_subjects_tokens_answers_the_count() { var id = await CreateUserAsync(); var (status, body) = await SendAsync(HttpMethod.Post, "/api/v1/identity/tokens/revoke-by-subject", new { userId = id }); status.Should().Be(HttpStatusCode.OK, body); body.Should().Be("""{"revokedCount":0}"""); } [Fact] public async Task Revoking_a_consent_answers_success_and_the_count() { var id = await CreateUserAsync(); var (status, body) = await SendAsync(HttpMethod.Delete, $"/api/v1/identity/consents?userId={id}&applicationId=987654321"); status.Should().Be(HttpStatusCode.OK, body); body.Should().Be("""{"success":true,"revoked":0}"""); var (allStatus, all) = await SendAsync(HttpMethod.Delete, $"/api/v1/identity/consents/all?userId={id}"); allStatus.Should().Be(HttpStatusCode.OK, all); all.Should().Be("""{"success":true,"revoked":0}"""); } [Fact] public async Task A_prune_preview_answers_what_it_would_prune() { var (status, body) = await SendAsync(HttpMethod.Post, "/api/v1/identity/tokens/prune?dryRun=true"); status.Should().Be(HttpStatusCode.OK, body); Regex.IsMatch(body, """^\{"dryRun":true,"wouldPruneTokens":\d+,"wouldPruneAuthorizations":\d+,"threshold":"[^"]+"\}$""") .Should().BeTrue(body); } [Fact] public async Task A_prune_answers_what_it_pruned() { var (status, body) = await SendAsync(HttpMethod.Post, "/api/v1/identity/tokens/prune"); status.Should().Be(HttpStatusCode.OK, body); Regex.IsMatch(body, """^\{"prunedTokens":\d+,"prunedAuthorizations":\d+\}$""").Should().BeTrue(body); } private async Task CreateUserAsync() { var login = "wire-" + Guid.NewGuid().ToString("N")[..10]; var (status, body) = await SendAsync(HttpMethod.Post, "/api/v1/identity/users", new { login, password = "Str0ng!Passw0rd", displayName = login }); status.Should().Be(HttpStatusCode.OK, body); return Id(body); } private async Task<(HttpStatusCode Status, string Body)> SendAsync(HttpMethod method, string path, object? content = null) { using var request = new HttpRequestMessage(method, path); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fx.ManagementToken); if (content is not null) request.Content = JsonContent.Create(content); using var response = await _fx.Http.SendAsync(request); return (response.StatusCode, await response.Content.ReadAsStringAsync()); } private static string Id(string json) { using var document = JsonDocument.Parse(json); var id = document.RootElement.GetProperty("id"); return id.ValueKind == JsonValueKind.Number ? id.GetInt64().ToString() : id.GetString()!; } }