Skip to content

Fix the sliding cookie configuration when using frontend tests#2041

Merged
Erwinvandervalk merged 1 commit intomainfrom
ev/bff/sliding-cookies
Jun 10, 2025
Merged

Fix the sliding cookie configuration when using frontend tests#2041
Erwinvandervalk merged 1 commit intomainfrom
ev/bff/sliding-cookies

Conversation

@Erwinvandervalk
Copy link
Contributor

@Erwinvandervalk Erwinvandervalk commented Jun 6, 2025

What issue does this PR address?
The sliding cookie tests were still in the 'old' testing style.

Turns out that the new frontend style of wiring things wasn't working for sliding cookies. So now the tests explicitly run the 'old' and the 'new' style of wiring things up. This will likely be the pattern I'll use for future tests also, because I want to make sure you can still use V3 style (explicit auth wireup) and v4 style (automatic wireup)

Also, it turns out that, if you do AddScheme, aspnet core also adds a specific post configuration middleware:

https://github.com/dotnet/aspnetcore/blob/main/src/Security/Authentication/Core/src/AuthenticationBuilder.cs#L52

We have to do the same in our dynamic scheme wireup. (basically, it only adds the timeprovider, but still, quite important)

Important: Any code or remarks in your Pull Request are under the following terms:

If You provide us with any comments, bug reports, feedback, enhancements, or modifications proposed or suggested by You for the Software, such Feedback is provided on a non-confidential basis (notwithstanding any notice to the contrary You may include in any accompanying communication), and Licensor shall have the right to use such Feedback at its discretion, including, but not limited to the incorporation of such suggested changes into the Software. You hereby grant Licensor a perpetual, irrevocable, transferable, sublicensable, nonexclusive license under all rights necessary to incorporate and use your Feedback for any purpose, including to make and sell any products and services.

(see our license, section 7)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the sliding cookie configuration when using frontend tests, ensuring compatibility between the legacy (V3) and new (V4) configuration styles. It introduces explicit wiring of the TimeProvider in tests and production code, supports both manual and frontend-managed BFF setups via parameterized tests, and adjusts cookie configuration events for sliding expiration.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
bff/test/Bff.Tests/TestInfra/TestHost.cs Adds TimeProvider to the DI container for testing purposes.
bff/test/Bff.Tests/TestInfra/TestDataBuilder.cs Introduces a helper method for generating UserSessionsFilter for tests.
bff/test/Bff.Tests/TestInfra/TestData.cs Provides a FakeTimeProvider instance and current time accessor.
bff/test/Bff.Tests/TestInfra/BffTestBase.cs Implements a new parameterized test configuration with BFF setup type options.
bff/test/Bff.Tests/SessionManagement/CookieSlidingTests.cs Updates cookie sliding tests to run with both V3 and V4 setup configurations and refines clock advancing logic.
bff/src/Bff/SessionManagement/Configuration/PostConfigureSlidingExpirationCheck.cs Adjusts the cookie sliding expiration configuration to check multiple scheme types.
bff/src/Bff/SessionManagement/Configuration/PostConfigureApplicationCookieTicketStore.cs Applies similar scheme checking logic for the application cookie ticket store.
bff/src/Bff/DynamicFrontends/BffConfigureOpenIdConnectOptions.cs Injects and assigns the TimeProvider to OpenIdConnect options.
bff/src/Bff/DynamicFrontends/BffConfigureCookieOptions.cs Injects and assigns the TimeProvider to Cookie options.
bff/src/Bff/BffBuilder.cs Minor cleanup in the builder class.

@Erwinvandervalk Erwinvandervalk merged commit 25121b3 into main Jun 10, 2025
14 checks passed
@Erwinvandervalk Erwinvandervalk deleted the ev/bff/sliding-cookies branch June 10, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants