Path: redb-identity/tests/redb.Identity.Tests/Pipeline/IntrospectionRevocationPipelineTests.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/Pipeline/IntrospectionRevocationPipelineTests.cs ---- using AwesomeAssertions; using redb.Identity.Contracts.Routes; using redb.Identity.Tests.Infrastructure; using redb.Route.Core; using Xunit; namespace redb.Identity.Tests.Pipeline; /// /// Introspection and Revocation endpoints through the full route pipeline. /// Exercises: DoTry/DoCatch (introspection), WireTap (revocation), error handling. /// [Collection("IdentityRoute")] public class IntrospectionRevocationPipelineTests { private readonly IdentityRouteFixture _fixture; public IntrospectionRevocationPipelineTests(IdentityRouteFixture fixture) => _fixture = fixture; // ── Helpers ── private async Task ObtainAccessToken() { var body = new Dictionary { ["grant_type"] = "client_credentials", ["client_id"] = "introspect-client", ["client_secret"] = "introspect-secret" }; var result = await _fixture.Request(IdentityEndpoints.Token, body); var dict = (Dictionary)result!; return dict["access_token"]!.ToString()!; } /// /// Extracts the response dictionary from the exchange. /// The processor writes to Out.Body; after pipeline merge it may end up in In.Body. /// private static Dictionary GetResponseBody(Exchange exchange) { // Out.Body is the canonical location the processor writes to if (exchange.Out?.Body is Dictionary outDict) return outDict; // After In/Out merge, result may be in In.Body if (exchange.In.Body is Dictionary inDict) return inDict; throw new InvalidOperationException( $"No Dict found. In.Body={exchange.In.Body?.GetType()}, Out.Body={exchange.Out?.Body?.GetType()}"); } // ── Introspection pipeline tests ── [Fact] public async Task Introspect_ValidToken_ThroughPipeline_ReturnsActive() { var token = await ObtainAccessToken(); var body = new Dictionary { ["token"] = token }; var headers = new Dictionary { ["Authorization"] = "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("introspect-client:introspect-secret")) }; var exchange = await _fixture.RequestWithHeaders(IdentityEndpoints.Introspect, body, headers); var dict = GetResponseBody(exchange); dict.Should().ContainKey("active"); dict["active"].Should().Be(true); } [Fact] public async Task Introspect_InvalidToken_ThroughPipeline_ReturnsError() { var body = new Dictionary { ["token"] = "completely-invalid-jwt-garbage" }; var headers = new Dictionary { ["Authorization"] = "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("test-client:test-secret")) }; var exchange = await _fixture.RequestWithHeaders(IdentityEndpoints.Introspect, body, headers); // OpenIddict returns an error for completely invalid tokens (not parseable JWT) var dict = GetResponseBody(exchange); dict.Should().ContainKey("error"); } [Fact] public async Task Introspect_MissingToken_ThroughPipeline_ReturnsInvalidRequest() { var body = new Dictionary(); var headers = new Dictionary { ["Authorization"] = "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("test-client:test-secret")) }; var exchange = await _fixture.RequestWithHeaders(IdentityEndpoints.Introspect, body, headers); var dict = GetResponseBody(exchange); dict.Should().ContainKey("error"); dict["error"].Should().Be("invalid_request"); } // ── Revocation pipeline tests ── [Fact] public async Task Revoke_ValidToken_ThroughPipeline_ReturnsSuccess() { var token = await ObtainAccessToken(); var body = new Dictionary { ["token"] = token }; var headers = new Dictionary { ["Authorization"] = "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("introspect-client:introspect-secret")) }; var exchange = await _fixture.RequestWithHeaders(IdentityEndpoints.Revoke, body, headers); // RFC 7009: successful revocation returns 200 with no error var dict = GetResponseBody(exchange); dict.Should().NotContainKey("error", "revocation should not return an error for a valid token"); } [Fact] public async Task Revoke_InvalidToken_ThroughPipeline_Succeeds() { // RFC 7009 §2.1: invalid/unknown token → still 200 var body = new Dictionary { ["token"] = "not-a-real-token" }; var headers = new Dictionary { ["Authorization"] = "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("test-client:test-secret")) }; var exchange = await _fixture.RequestWithHeaders(IdentityEndpoints.Revoke, body, headers); // Should not throw — pipeline handles it gracefully exchange.Exception.Should().BeNull("revocation of invalid token should not throw"); } [Fact] public async Task Revoke_MissingToken_ThroughPipeline_ReturnsError() { var body = new Dictionary(); var headers = new Dictionary { ["Authorization"] = "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("test-client:test-secret")) }; var exchange = await _fixture.RequestWithHeaders(IdentityEndpoints.Revoke, body, headers); var dict = GetResponseBody(exchange); dict.Should().ContainKey("error"); dict["error"].Should().Be("invalid_request"); } }