Run the stale-client test on a store that skips OpenIddict's bulk delete, which the in-memory database cannot execute

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-27 04:12:10 +01:00
commit 0750d7a59e
2 changed files with 40 additions and 1 deletions

View file

@ -355,7 +355,7 @@ public sealed class OidcIssuerTests : IClassFixture<OidcWebApplicationFactory>
public async Task Startup_removes_every_client_but_the_configured_one()
{
// Own host: the stale client is a row the other tests must not see.
using var own = new OidcWebApplicationFactory();
using var own = new OidcInMemoryStoreFactory();
await new OidcIssuerTests(own).StaleClientIsRemovedAsync();
}

View file

@ -5,7 +5,11 @@ using Bifrost.Web.Features.Shared;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using OpenIddict.EntityFrameworkCore;
using OpenIddict.EntityFrameworkCore.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
@ -230,3 +234,38 @@ public sealed class OidcForeignIssuerFactory : OidcWebApplicationFactory
configuration.AddInMemoryCollection(new Dictionary<string, string?> { ["Host:PublicBaseUrl"] = PublicBaseUrl }));
}
}
/// <summary>
/// An OIDC host whose application store removes a client row without OpenIddict's bulk delete of its tokens and
/// authorizations, which the in-memory test database cannot run (the cascade is the store's, exercised on Postgres only).
/// What the seeder decides to remove is what the host then loses.
/// </summary>
public sealed class OidcInMemoryStoreFactory : OidcWebApplicationFactory
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.ConfigureServices(services =>
{
services.RemoveAll<OpenIddict.Abstractions.IOpenIddictApplicationStore<OpenIddictEntityFrameworkCoreApplication>>();
services.AddScoped<OpenIddict.Abstractions.IOpenIddictApplicationStore<OpenIddictEntityFrameworkCoreApplication>, RowOnlyApplicationStore>();
});
}
private sealed class RowOnlyApplicationStore(
IMemoryCache cache,
BifrostDbContext context,
IOptionsMonitor<OpenIddictEntityFrameworkCoreOptions> options)
: OpenIddictEntityFrameworkCoreApplicationStore<
OpenIddictEntityFrameworkCoreApplication,
OpenIddictEntityFrameworkCoreAuthorization,
OpenIddictEntityFrameworkCoreToken,
BifrostDbContext>(cache, context, options)
{
public override async ValueTask DeleteAsync(OpenIddictEntityFrameworkCoreApplication application, CancellationToken cancellationToken)
{
context.Remove(application);
await context.SaveChangesAsync(cancellationToken);
}
}
}