Path: redb-identity/tests/redb.Identity.Tests/Routes/MeConsentsProcessorTests.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/Routes/MeConsentsProcessorTests.cs
----
using AwesomeAssertions;
using redb.Identity.Core.Routes.Processors;
using redb.Route.Core;
using Xunit;
namespace redb.Identity.Tests.Routes;
///
/// H3 (v1.0 DoD ยง6) unit tests for . Covers the
/// token-subject precondition paths which reject before any
/// access, so no DB or service wiring is required.
/// Happy-path list + revoke flows (incl. ownership and 404-on-unknown-clientId)
/// live in the integration suite.
///
public sealed class MeConsentsProcessorTests
{
private static Exchange BuildExchange(long? userId, string operation, object? body = null)
{
var ex = new Exchange(new Message { Body = body ?? new Dictionary() });
ex.In.Headers["operation"] = operation;
if (userId is not null)
ex.Properties["identity:management-user-id"] = userId.Value;
return ex;
}
[Fact]
public async Task MissingSubject_List_Returns401()
{
var sut = new MeConsentsProcessor(context: null!, redbName: null);
var ex = BuildExchange(userId: null, operation: "list");
await sut.Process(ex);
ex.HasOut.Should().BeTrue();
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(401);
ex.IsStopped.Should().BeTrue();
var body = (Dictionary)ex.Out.Body!;
body["error"].Should().Be("invalid_token");
}
[Fact]
public async Task MissingSubject_Revoke_Returns401()
{
var sut = new MeConsentsProcessor(context: null!, redbName: null);
var ex = BuildExchange(
userId: null, operation: "revoke",
body: new Dictionary { ["clientId"] = "demo-client" });
await sut.Process(ex);
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(401);
}
[Fact]
public async Task NonPositiveSubject_Returns401()
{
var sut = new MeConsentsProcessor(context: null!, redbName: null);
var ex = BuildExchange(userId: 0, operation: "list");
await sut.Process(ex);
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(401);
}
[Fact]
public async Task Grant_MissingSubject_Returns401()
{
var sut = new MeConsentsProcessor(context: null!, redbName: null);
var ex = BuildExchange(
userId: null, operation: "grant",
body: new Dictionary
{
["clientId"] = "demo-client",
["scopes"] = new[] { "openid" },
});
await sut.Process(ex);
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(401);
}
[Fact]
public async Task Grant_MissingClientId_Returns400()
{
var sut = new MeConsentsProcessor(context: null!, redbName: null);
var ex = BuildExchange(
userId: 42, operation: "grant",
body: new Dictionary
{
["clientId"] = " ",
["scopes"] = new[] { "openid" },
});
await sut.Process(ex);
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(400);
var body = (Dictionary)ex.Out.Body!;
body["error"].Should().Be("validation_error");
}
[Fact]
public async Task Grant_MissingScopes_Returns400()
{
var sut = new MeConsentsProcessor(context: null!, redbName: null);
var ex = BuildExchange(
userId: 42, operation: "grant",
body: new Dictionary
{
["clientId"] = "demo-client",
["scopes"] = Array.Empty(),
});
await sut.Process(ex);
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(400);
var body = (Dictionary)ex.Out.Body!;
body["error"].Should().Be("validation_error");
}
}