From 0750d7a59e807a847e5a687ee17cb9e5eef64bb6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 27 Oct 2026 04:12:10 +0100 Subject: [PATCH] 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 --- tests/Bifrost.Web.Tests/OidcIssuerTests.cs | 2 +- .../Bifrost.Web.Tests/Support/OidcTestKit.cs | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/Bifrost.Web.Tests/OidcIssuerTests.cs b/tests/Bifrost.Web.Tests/OidcIssuerTests.cs index 5c15505..c0df422 100644 --- a/tests/Bifrost.Web.Tests/OidcIssuerTests.cs +++ b/tests/Bifrost.Web.Tests/OidcIssuerTests.cs @@ -355,7 +355,7 @@ public sealed class OidcIssuerTests : IClassFixture 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(); } diff --git a/tests/Bifrost.Web.Tests/Support/OidcTestKit.cs b/tests/Bifrost.Web.Tests/Support/OidcTestKit.cs index c2421c5..027cd1d 100644 --- a/tests/Bifrost.Web.Tests/Support/OidcTestKit.cs +++ b/tests/Bifrost.Web.Tests/Support/OidcTestKit.cs @@ -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 { ["Host:PublicBaseUrl"] = PublicBaseUrl })); } } + +/// +/// 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. +/// +public sealed class OidcInMemoryStoreFactory : OidcWebApplicationFactory +{ + protected override void ConfigureWebHost(IWebHostBuilder builder) + { + base.ConfigureWebHost(builder); + builder.ConfigureServices(services => + { + services.RemoveAll>(); + services.AddScoped, RowOnlyApplicationStore>(); + }); + } + + private sealed class RowOnlyApplicationStore( + IMemoryCache cache, + BifrostDbContext context, + IOptionsMonitor 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); + } + } +}