-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1690 from DuendeSoftware/7.1.0-httpcontext-bug
- Loading branch information
Showing
3 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...Tests/Configuration/DependencyInjection/PostConfigureApplicationCookieTicketStoreTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Duende.IdentityServer.Configuration; | ||
using Duende.IdentityServer.Licensing.V2; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Authentication.Cookies; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using UnitTests.Common; | ||
using Xunit; | ||
|
||
namespace UnitTests.Configuration.DependencyInjection; | ||
|
||
public class PostConfigureApplicationCookieTicketStoreTests | ||
{ | ||
|
||
[Fact] | ||
public void can_be_constructed_without_httpcontext_and_used_later_with_httpcontext() | ||
{ | ||
// Register the dependencies of the usage tracker so that we can resolve it in PostConfigure | ||
var httpContextAccessor = new MockHttpContextAccessor(configureServices: sp => | ||
{ | ||
sp.AddSingleton(TestLogger.Create<LicenseAccessor>()); | ||
sp.AddSingleton<LicenseAccessor>(); | ||
sp.AddSingleton<LicenseUsageTracker>(); | ||
}); | ||
|
||
// The mock http context accessor has a convenient HttpContext, but | ||
// initially we simulate not having it by stashing it away and setting | ||
// the accessor's context to null. | ||
var savedContext = httpContextAccessor.HttpContext; | ||
httpContextAccessor.HttpContext = null; | ||
|
||
var sut = new PostConfigureApplicationCookieTicketStore( | ||
httpContextAccessor, | ||
new IdentityServerOptions | ||
{ | ||
Authentication = new AuthenticationOptions | ||
{ | ||
// This is needed so that we operate on the correct scheme | ||
CookieAuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme | ||
} | ||
}, | ||
Options.Create<Microsoft.AspNetCore.Authentication.AuthenticationOptions>(new()), | ||
TestLogger.Create<PostConfigureApplicationCookieTicketStore>() | ||
); | ||
|
||
// Now that we've constructed, we can bring back the http context and run PostConfigure | ||
httpContextAccessor.HttpContext = savedContext; | ||
var cookieOpts = new CookieAuthenticationOptions(); | ||
sut.PostConfigure(CookieAuthenticationDefaults.AuthenticationScheme, cookieOpts); | ||
|
||
cookieOpts.SessionStore.Should().BeOfType<TicketStoreShim>(); | ||
} | ||
} |