Path: redb-identity/tests/redb.Identity.Tests/Bugs/FourScopesManagerTest.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/Bugs/FourScopesManagerTest.cs
----
using System.Collections.Immutable;
using AwesomeAssertions;
using Microsoft.Extensions.DependencyInjection;
using OpenIddict.Abstractions;
using redb.Core.Models.Entities;
using redb.Core.Query;
using redb.Identity.Core.Models;
using redb.Identity.Tests.Infrastructure;
using Xunit;
using Xunit.Abstractions;
namespace redb.Identity.Tests.Bugs;
///
/// Direct OpenIddict manager test to isolate the 4-scopes DbException.
/// Uses the production bootstrap fixture's service provider to access managers directly.
///
[Collection("ProductionBootstrap")]
public class FourScopesManagerTest
{
private readonly ProductionBootstrapFixture _fx;
private readonly ITestOutputHelper _output;
public FourScopesManagerTest(ProductionBootstrapFixture fx, ITestOutputHelper output)
{
_fx = fx;
_output = output;
}
[Theory]
[InlineData("openid profile email", "3 scopes")]
[InlineData("openid profile email phone", "4 scopes")]
public async Task CreateAuthorization_ViaManager(string scopeStr, string label)
{
_output.WriteLine($"Testing {label}: {scopeStr}");
var scopes = scopeStr.Split(' ');
var authManager = _fx.ServiceProvider.GetRequiredService();
var appManager = _fx.ServiceProvider.GetRequiredService();
// Find the test app
var app = await appManager.FindByClientIdAsync(ProductionBootstrapFixture.TestClientIdPublic)
?? throw new Exception("Test app not found");
var appId = await appManager.GetIdAsync(app);
_output.WriteLine($" App id: {appId}");
// Find test user — the OpenIddict subject is now the user's value_guid.
var coreUser = await _fx.Redb.UserProvider.GetUserByLoginAsync(ProductionBootstrapFixture.TestUsername)
?? throw new Exception("Test user not found");
var oidcObj = await _fx.Redb.Query()
.WhereRedb(o => o.Key == coreUser.Id)
.FirstOrDefaultAsync()
?? throw new Exception($"UserProps row missing for user {coreUser.Id} — bootstrap should seed value_guid");
if (oidcObj.value_guid is null || oidcObj.value_guid == Guid.Empty)
throw new Exception("UserProps.value_guid not set — bootstrap must populate the per-user GUID");
var userId = oidcObj.value_guid.Value.ToString("D");
_output.WriteLine($" User id (bigint): {coreUser.Id}");
_output.WriteLine($" Subject (GUID): {userId}");
try
{
// Step 1: FindAsync (same as OpenIddict's ProcessSignIn)
_output.WriteLine(" Step 1: FindAsync...");
var existing = new List