Path: redb-identity/tests/redb.Identity.Tests/Grpc/GrpcManagementResultWireTests.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/Grpc/GrpcManagementResultWireTests.cs ---- using AwesomeAssertions; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; using Grpc.Core; using redb.Identity.Grpc.Management.V1; using redb.Identity.Grpc.V1; using redb.Identity.Tests.Infrastructure; using Xunit; namespace redb.Identity.Tests.Grpc; /// /// The management answers over gRPC, one case per kind of result body. The controller's JSON reaches the /// caller as a protobuf , so the check is member for member against the JSON these routes /// answered before their bodies became declared types in redb.Identity.Contracts; an error document still /// becomes a status with its error code in the trailers. /// [Collection("PostgresCollection")] public class GrpcManagementResultWireTests : IClassFixture { private readonly GrpcIdentityFixture _fixture; public GrpcManagementResultWireTests(GrpcIdentityFixture fixture) => _fixture = fixture; [Fact] public async Task Not_found_is_a_status_with_the_error_code() { var act = async () => await CallAsync("Applications", "Get", """{"id":"987654321"}"""); var ex = await act.Should().ThrowAsync(); ex.Which.StatusCode.Should().Be(StatusCode.NotFound); ex.Which.Trailers.GetValue("error").Should().Be("not_found"); } [Fact] public async Task Deleting_a_scope_answers_success_alone() { var name = "wire_" + Guid.NewGuid().ToString("N")[..10]; var created = await CallAsync("Scopes", "Create", $$"""{"name":"{{name}}"}"""); var id = created.Result.StructValue.Fields["id"]; var deleted = await CallAsync("Scopes", "Delete", $$"""{"id":"{{Text(id)}}"}"""); deleted.Result.Should().Be(Value.Parser.ParseJson("""{"success":true}""")); } [Fact] public async Task Deleting_a_user_answers_success_and_the_sessions_revoked() { var id = await CreateUserAsync(); var deleted = await CallAsync("Users", "Delete", $$"""{"id":"{{id}}"}"""); deleted.Result.Should().Be(Value.Parser.ParseJson("""{"success":true,"sessionsRevoked":0}""")); } [Fact] public async Task Revoking_a_subjects_tokens_answers_the_count() { var id = await CreateUserAsync(); var revoked = await CallAsync("Tokens", "RevokeBySubject", $$"""{"userId":{{id}}}"""); revoked.Result.Should().Be(Value.Parser.ParseJson("""{"revokedCount":0}""")); } [Fact] public async Task A_group_answers_its_fields_membership_and_deletion() { var name = "wire-" + Guid.NewGuid().ToString("N")[..8]; var created = await CallAsync("Groups", "Create", $$"""{"name":"{{name}}","groupType":"team","description":"d"}"""); var fields = created.Result.StructValue.Fields; fields.Keys.Should().Equal("id", "name", "parentId", "groupType", "description", "createdAt", "modifiedAt"); fields["name"].StringValue.Should().Be(name); fields["groupType"].StringValue.Should().Be("team"); var groupId = Text(fields["id"]); var userId = await CreateUserAsync(); var check = await CallAsync("Groups", "IsMember", $$"""{"id":"{{groupId}}","userId":"{{userId}}"}"""); check.Result.Should().Be(Value.Parser.ParseJson($$"""{"isMember":false,"groupId":{{groupId}},"userId":{{userId}}}""")); var deleted = await CallAsync("Groups", "Delete", $$"""{"id":"{{groupId}}"}"""); deleted.Result.Should().Be(Value.Parser.ParseJson($$"""{"success":true,"groupId":{{groupId}}}""")); } private async Task CreateUserAsync() { var login = "wire-" + Guid.NewGuid().ToString("N")[..10]; var created = await CallAsync("Users", "Create", $$"""{"login":"{{login}}","email":"{{login}}@example.test","password":"Str0ng!Passw0rd"}"""); // UserResponse declares no JSON names and the gRPC dispatcher has no naming policy: its id is "Id" here. return Text(created.Result.StructValue.Fields["Id"]); } private static string Text(Value value) => value.KindCase == Value.KindOneofCase.NumberValue ? ((long)value.NumberValue).ToString() : value.StringValue; private async Task CallAsync(string service, string method, string argumentsJson) { var request = new ManagementRequest { Arguments = JsonParser.Default.Parse(argumentsJson) }; var metadata = new Metadata { { "authorization", "Bearer " + await AdminTokenAsync() } }; var reply = await _fixture.CallManagementRawAsync( $"/identity.management.v1.{service}/{method}", request.ToByteArray(), metadata); return ManagementResponse.Parser.ParseFrom(reply); } private async Task AdminTokenAsync() { var issued = await _fixture.CallAsync("Token", new TokenRequest { GrantType = "client_credentials", ClientId = GrpcIdentityFixture.ClientId, ClientSecret = GrpcIdentityFixture.ClientSecret, Scope = GrpcIdentityFixture.GrantedScope, }, TokenResponse.Parser); return issued.AccessToken; } }