Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Commit d453e4e

Browse files
committed
Identity tests passing
1 parent 0c8bb4a commit d453e4e

File tree

7 files changed

+59
-14
lines changed

7 files changed

+59
-14
lines changed

src/Microsoft.AspNetCore.Identity.Specification.Tests/Microsoft.AspNetCore.Identity.Specification.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
2020
<PackageReference Include="System.Linq.Queryable" Version="$(CoreFxVersion)" />
2121
</ItemGroup>
22+
<ItemGroup>
23+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
24+
</ItemGroup>
2225
</Project>

src/Microsoft.AspNetCore.Identity/SignInManager.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ public virtual async Task<SignInResult> CheckPasswordSignInAsync(TUser user, str
329329
public virtual async Task<bool> IsTwoFactorClientRememberedAsync(TUser user)
330330
{
331331
var userId = await UserManager.GetUserIdAsync(user);
332-
var result = await Context.Authentication.AuthenticateAsync(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme);
333-
return (result != null && result.FindFirstValue(ClaimTypes.Name) == userId);
332+
var result = await Context.AuthenticateAsync(Options.Cookies.TwoFactorRememberMeCookieAuthenticationScheme);
333+
return (result?.Principal != null && result.Principal.FindFirstValue(ClaimTypes.Name) == userId);
334334
}
335335

336336
/// <summary>
@@ -681,28 +681,28 @@ await UserManager.GetTwoFactorEnabledAsync(user) &&
681681
{
682682
// Store the userId for use after two factor check
683683
var userId = await UserManager.GetUserIdAsync(user);
684-
await Context.Authentication.SignInAsync(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme, StoreTwoFactorInfo(userId, loginProvider));
684+
await Context.SignInAsync(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme, StoreTwoFactorInfo(userId, loginProvider));
685685
return SignInResult.TwoFactorRequired;
686686
}
687687
}
688688
// Cleanup external cookie
689689
if (loginProvider != null)
690690
{
691-
await Context.Authentication.SignOutAsync(Options.Cookies.ExternalCookieAuthenticationScheme);
691+
await Context.SignOutAsync(Options.Cookies.ExternalCookieAuthenticationScheme);
692692
}
693693
await SignInAsync(user, isPersistent, loginProvider);
694694
return SignInResult.Success;
695695
}
696696

697697
private async Task<TwoFactorAuthenticationInfo> RetrieveTwoFactorInfoAsync()
698698
{
699-
var result = await Context.Authentication.AuthenticateAsync(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme);
700-
if (result != null)
699+
var result = await Context.AuthenticateAsync(Options.Cookies.TwoFactorUserIdCookieAuthenticationScheme);
700+
if (result?.Principal != null)
701701
{
702702
return new TwoFactorAuthenticationInfo
703703
{
704-
UserId = result.FindFirstValue(ClaimTypes.Name),
705-
LoginProvider = result.FindFirstValue(ClaimTypes.AuthenticationMethod)
704+
UserId = result.Principal.FindFirstValue(ClaimTypes.Name),
705+
LoginProvider = result.Principal.FindFirstValue(ClaimTypes.AuthenticationMethod)
706706
};
707707
}
708708
return null;

test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.InMemory.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
<PackageReference Include="xunit" Version="2.2.0-*" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-*" />
2424
</ItemGroup>
25+
<ItemGroup>
26+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
27+
</ItemGroup>
2528
</Project>

test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test/Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@
2828
<PackageReference Include="xunit" Version="2.2.0-*" />
2929
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-*" />
3030
</ItemGroup>
31+
<ItemGroup>
32+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
33+
</ItemGroup>
3134
</Project>

test/Microsoft.AspNetCore.Identity.Test/Microsoft.AspNetCore.Identity.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@
2222
<PackageReference Include="xunit" Version="2.2.0-*" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-*" />
2424
</ItemGroup>
25+
<ItemGroup>
26+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
27+
</ItemGroup>
2528
</Project>

test/Microsoft.AspNetCore.Identity.Test/SecurityStampValidatorTest.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

test/Microsoft.AspNetCore.Identity.Test/SignInManagerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public async Task CanResignIn(bool isPersistent, bool externalLogin)
498498
// Setup
499499
var user = new TestUser { UserName = "Foo" };
500500
var context = new DefaultHttpContext();
501-
var auth = new Mock<IAuthenticationService>();
501+
var auth = MockAuth(context);
502502
var loginProvider = "loginprovider";
503503
var id = new ClaimsIdentity();
504504
if (externalLogin)

0 commit comments

Comments
 (0)