@@ -17,6 +17,39 @@ namespace Microsoft.AspNetCore.Identity.Test
1717{
1818 public class SecurityStampTest
1919 {
20+ private class NoopHandler : IAuthenticationHandler
21+ {
22+ public Task < AuthenticateResult > AuthenticateAsync ( AuthenticateContext context )
23+ {
24+ throw new NotImplementedException ( ) ;
25+ }
26+
27+ public Task ChallengeAsync ( ChallengeContext context )
28+ {
29+ throw new NotImplementedException ( ) ;
30+ }
31+
32+ public Task < bool > HandleRequestAsync ( )
33+ {
34+ throw new NotImplementedException ( ) ;
35+ }
36+
37+ public Task InitializeAsync ( AuthenticationScheme scheme , HttpContext context )
38+ {
39+ throw new NotImplementedException ( ) ;
40+ }
41+
42+ public Task SignInAsync ( SignInContext context )
43+ {
44+ throw new NotImplementedException ( ) ;
45+ }
46+
47+ public Task SignOutAsync ( SignOutContext context )
48+ {
49+ throw new NotImplementedException ( ) ;
50+ }
51+ }
52+
2053 [ Fact ]
2154 public async Task OnValidatePrincipalThrowsWithEmptyServiceCollection ( )
2255 {
@@ -25,7 +58,7 @@ public async Task OnValidatePrincipalThrowsWithEmptyServiceCollection()
2558 httpContext . Setup ( c => c . RequestServices ) . Returns ( new ServiceCollection ( ) . BuildServiceProvider ( ) ) ;
2659 var id = new ClaimsPrincipal ( new ClaimsIdentity ( scheme ) ) ;
2760 var ticket = new AuthenticationTicket ( id , new AuthenticationProperties { IssuedUtc = DateTimeOffset . UtcNow } , scheme ) ;
28- var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( scheme ) . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
61+ var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( scheme ) { HandlerType = typeof ( NoopHandler ) } . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
2962 var ex = await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => SecurityStampValidator . ValidatePrincipalAsync ( context ) ) ;
3063 }
3164
@@ -61,7 +94,7 @@ public async Task OnValidatePrincipalTestSuccess(bool isPersistent)
6194 var ticket = new AuthenticationTicket ( principal ,
6295 properties ,
6396 identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) ;
64- var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
97+ var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) { HandlerType = typeof ( NoopHandler ) } . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
6598 Assert . NotNull ( context . Properties ) ;
6699 Assert . NotNull ( context . Options ) ;
67100 Assert . NotNull ( context . Principal ) ;
@@ -97,7 +130,7 @@ public async Task OnValidateIdentityRejectsWhenValidateSecurityStampFails()
97130 var ticket = new AuthenticationTicket ( new ClaimsPrincipal ( id ) ,
98131 new AuthenticationProperties { IssuedUtc = DateTimeOffset . UtcNow . AddSeconds ( - 1 ) } ,
99132 identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) ;
100- var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
133+ var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) { HandlerType = typeof ( NoopHandler ) } . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
101134 Assert . NotNull ( context . Properties ) ;
102135 Assert . NotNull ( context . Options ) ;
103136 Assert . NotNull ( context . Principal ) ;
@@ -132,7 +165,7 @@ public async Task OnValidateIdentityRejectsWhenNoIssuedUtc()
132165 var ticket = new AuthenticationTicket ( new ClaimsPrincipal ( id ) ,
133166 new AuthenticationProperties ( ) ,
134167 identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) ;
135- var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
168+ var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) { HandlerType = typeof ( NoopHandler ) } . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
136169 Assert . NotNull ( context . Properties ) ;
137170 Assert . NotNull ( context . Options ) ;
138171 Assert . NotNull ( context . Principal ) ;
@@ -168,7 +201,7 @@ public async Task OnValidateIdentityDoesNotRejectsWhenNotExpired()
168201 var ticket = new AuthenticationTicket ( new ClaimsPrincipal ( id ) ,
169202 new AuthenticationProperties { IssuedUtc = DateTimeOffset . UtcNow } ,
170203 identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) ;
171- var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
204+ var context = new CookieValidatePrincipalContext ( httpContext . Object , new AuthenticationSchemeBuilder ( identityOptions . Cookies . ApplicationCookieAuthenticationScheme ) { HandlerType = typeof ( NoopHandler ) } . Build ( ) , ticket , new CookieAuthenticationOptions ( ) ) ;
172205 Assert . NotNull ( context . Properties ) ;
173206 Assert . NotNull ( context . Options ) ;
174207 Assert . NotNull ( context . Principal ) ;
0 commit comments