Reenable Functional tests/Fix security stamp
This commit is contained in:
parent
9fc993122e
commit
85d2d3d46a
|
|
@ -12,7 +12,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<DevelopmentServerPort>5131</DevelopmentServerPort>
|
<DevelopmentServerPort>41532</DevelopmentServerPort>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -30,7 +30,9 @@ namespace Microsoft.AspNet.Identity
|
||||||
var user = await manager.ValidateSecurityStampAsync(context.Principal, userId);
|
var user = await manager.ValidateSecurityStampAsync(context.Principal, userId);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
await manager.SignInAsync(user, context.Properties, authenticationMethod: null);
|
// REVIEW: note we lost login authenticaiton method
|
||||||
|
context.ReplacePrincipal(await manager.CreateUserPrincipalAsync(user));
|
||||||
|
context.ShouldRenew = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,332 +1,330 @@
|
||||||
//// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
//// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
//using System;
|
using System;
|
||||||
//using System.IO;
|
using System.IO;
|
||||||
//using System.Linq;
|
using System.Linq;
|
||||||
//using System.Net;
|
using System.Net;
|
||||||
//using System.Net.Http;
|
using System.Net.Http;
|
||||||
//using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
//using System.Text;
|
using System.Text;
|
||||||
//using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
//using System.Xml;
|
using System.Xml;
|
||||||
//using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
//using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
//using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
//using Microsoft.AspNet.Http.Authentication;
|
using Microsoft.AspNet.Http.Authentication;
|
||||||
//using Microsoft.AspNet.Http.Features.Authentication;
|
using Microsoft.AspNet.Http.Features.Authentication;
|
||||||
//using Microsoft.AspNet.TestHost;
|
using Microsoft.AspNet.TestHost;
|
||||||
//using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
//using Shouldly;
|
using Shouldly;
|
||||||
//using Xunit;
|
using Xunit;
|
||||||
//using Microsoft.AspNet.Identity.Test;
|
using Microsoft.AspNet.Identity.Test;
|
||||||
//using System.Diagnostics;
|
|
||||||
|
|
||||||
//namespace Microsoft.AspNet.Identity.InMemory
|
namespace Microsoft.AspNet.Identity.InMemory
|
||||||
//{
|
{
|
||||||
// public class FunctionalTest
|
public class FunctionalTest
|
||||||
// {
|
{
|
||||||
// const string TestPassword = "1qaz!QAZ";
|
const string TestPassword = "1qaz!QAZ";
|
||||||
|
|
||||||
// [Fact]
|
[Fact]
|
||||||
// public async Task CanChangePasswordOptions()
|
public async Task CanChangePasswordOptions()
|
||||||
// {
|
{
|
||||||
// var clock = new TestClock();
|
var clock = new TestClock();
|
||||||
// var server = CreateServer(services => services.ConfigureIdentity(options =>
|
var server = CreateServer(services => services.ConfigureIdentity(options =>
|
||||||
// {
|
{
|
||||||
// options.Password.RequireUppercase = false;
|
options.Password.RequireUppercase = false;
|
||||||
// options.Password.RequireNonLetterOrDigit = false;
|
options.Password.RequireNonLetterOrDigit = false;
|
||||||
// options.Password.RequireDigit = false;
|
options.Password.RequireDigit = false;
|
||||||
// }));
|
}));
|
||||||
|
|
||||||
// var transaction1 = await SendAsync(server, "http://example.com/createSimple");
|
var transaction1 = await SendAsync(server, "http://example.com/createSimple");
|
||||||
// transaction1.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction1.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
// Assert.Null(transaction1.SetCookie);
|
Assert.Null(transaction1.SetCookie);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// [Fact]
|
[Fact]
|
||||||
// public async Task CanCreateMeLoginAndCookieStopsWorkingAfterExpiration()
|
public async Task CanCreateMeLoginAndCookieStopsWorkingAfterExpiration()
|
||||||
// {
|
{
|
||||||
// var clock = new TestClock();
|
var clock = new TestClock();
|
||||||
// var server = CreateServer(services => services.ConfigureIdentityApplicationCookie(appCookieOptions =>
|
var server = CreateServer(services => services.ConfigureIdentityApplicationCookie(appCookieOptions =>
|
||||||
// {
|
{
|
||||||
// appCookieOptions.SystemClock = clock;
|
appCookieOptions.SystemClock = clock;
|
||||||
// appCookieOptions.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
appCookieOptions.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
||||||
// appCookieOptions.SlidingExpiration = false;
|
appCookieOptions.SlidingExpiration = false;
|
||||||
// }));
|
}));
|
||||||
|
|
||||||
// var transaction1 = await SendAsync(server, "http://example.com/createMe");
|
var transaction1 = await SendAsync(server, "http://example.com/createMe");
|
||||||
// transaction1.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction1.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
// Assert.Null(transaction1.SetCookie);
|
Assert.Null(transaction1.SetCookie);
|
||||||
|
|
||||||
// var transaction2 = await SendAsync(server, "http://example.com/pwdLogin/false");
|
var transaction2 = await SendAsync(server, "http://example.com/pwdLogin/false");
|
||||||
// transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
// Assert.NotNull(transaction2.SetCookie);
|
Assert.NotNull(transaction2.SetCookie);
|
||||||
// transaction2.SetCookie.ShouldNotContain("; expires=");
|
transaction2.SetCookie.ShouldNotContain("; expires=");
|
||||||
|
|
||||||
// var transaction3 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
var transaction3 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
||||||
// FindClaimValue(transaction3, ClaimTypes.Name).ShouldBe("hao");
|
FindClaimValue(transaction3, ClaimTypes.Name).ShouldBe("hao");
|
||||||
// Assert.Null(transaction3.SetCookie);
|
Assert.Null(transaction3.SetCookie);
|
||||||
|
|
||||||
// clock.Add(TimeSpan.FromMinutes(7));
|
clock.Add(TimeSpan.FromMinutes(7));
|
||||||
|
|
||||||
// var transaction4 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
var transaction4 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
||||||
// FindClaimValue(transaction4, ClaimTypes.Name).ShouldBe("hao");
|
FindClaimValue(transaction4, ClaimTypes.Name).ShouldBe("hao");
|
||||||
// Assert.Null(transaction4.SetCookie);
|
Assert.Null(transaction4.SetCookie);
|
||||||
|
|
||||||
// clock.Add(TimeSpan.FromMinutes(7));
|
clock.Add(TimeSpan.FromMinutes(7));
|
||||||
|
|
||||||
// var transaction5 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
var transaction5 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
||||||
// FindClaimValue(transaction5, ClaimTypes.Name).ShouldBe(null);
|
FindClaimValue(transaction5, ClaimTypes.Name).ShouldBe(null);
|
||||||
// Assert.Null(transaction5.SetCookie);
|
Assert.Null(transaction5.SetCookie);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// [Theory]
|
[Theory]
|
||||||
// [InlineData(true)]
|
[InlineData(true)]
|
||||||
// [InlineData(false)]
|
[InlineData(false)]
|
||||||
// public async Task CanCreateMeLoginAndSecurityStampExtendsExpiration(bool rememberMe)
|
public async Task CanCreateMeLoginAndSecurityStampExtendsExpiration(bool rememberMe)
|
||||||
// {
|
{
|
||||||
// var clock = new TestClock();
|
var clock = new TestClock();
|
||||||
// var server = CreateServer(services => services.ConfigureIdentityApplicationCookie(appCookieOptions =>
|
var server = CreateServer(services => services.ConfigureIdentityApplicationCookie(appCookieOptions =>
|
||||||
// {
|
{
|
||||||
// appCookieOptions.SystemClock = clock;
|
appCookieOptions.SystemClock = clock;
|
||||||
// }));
|
}));
|
||||||
|
|
||||||
// var transaction1 = await SendAsync(server, "http://example.com/createMe");
|
var transaction1 = await SendAsync(server, "http://example.com/createMe");
|
||||||
// transaction1.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction1.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
// Assert.Null(transaction1.SetCookie);
|
Assert.Null(transaction1.SetCookie);
|
||||||
|
|
||||||
// var transaction2 = await SendAsync(server, "http://example.com/pwdLogin/" + rememberMe);
|
var transaction2 = await SendAsync(server, "http://example.com/pwdLogin/" + rememberMe);
|
||||||
// transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
// Assert.NotNull(transaction2.SetCookie);
|
Assert.NotNull(transaction2.SetCookie);
|
||||||
// if (rememberMe)
|
if (rememberMe)
|
||||||
// {
|
{
|
||||||
// transaction2.SetCookie.ShouldContain("; expires=");
|
transaction2.SetCookie.ShouldContain("; expires=");
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// transaction2.SetCookie.ShouldNotContain("; expires=");
|
transaction2.SetCookie.ShouldNotContain("; expires=");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// var transaction3 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
var transaction3 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
||||||
// FindClaimValue(transaction3, ClaimTypes.Name).ShouldBe("hao");
|
FindClaimValue(transaction3, ClaimTypes.Name).ShouldBe("hao");
|
||||||
// Assert.Null(transaction3.SetCookie);
|
Assert.Null(transaction3.SetCookie);
|
||||||
|
|
||||||
// // Make sure we don't get a new cookie yet
|
// Make sure we don't get a new cookie yet
|
||||||
// clock.Add(TimeSpan.FromMinutes(10));
|
clock.Add(TimeSpan.FromMinutes(10));
|
||||||
// var transaction4 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
var transaction4 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
||||||
// FindClaimValue(transaction4, ClaimTypes.Name).ShouldBe("hao");
|
FindClaimValue(transaction4, ClaimTypes.Name).ShouldBe("hao");
|
||||||
// Assert.Null(transaction4.SetCookie);
|
Assert.Null(transaction4.SetCookie);
|
||||||
|
|
||||||
// // Go past SecurityStampValidation interval and ensure we get a new cookie
|
// Go past SecurityStampValidation interval and ensure we get a new cookie
|
||||||
// clock.Add(TimeSpan.FromMinutes(21));
|
clock.Add(TimeSpan.FromMinutes(21));
|
||||||
|
|
||||||
// var transaction5 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
var transaction5 = await SendAsync(server, "http://example.com/me", transaction2.CookieNameValue);
|
||||||
// Assert.NotNull(transaction5.SetCookie);
|
Assert.NotNull(transaction5.SetCookie);
|
||||||
// FindClaimValue(transaction5, ClaimTypes.Name).ShouldBe("hao");
|
FindClaimValue(transaction5, ClaimTypes.Name).ShouldBe("hao");
|
||||||
|
|
||||||
// // Make sure new cookie is valid
|
// Make sure new cookie is valid
|
||||||
// var transaction6 = await SendAsync(server, "http://example.com/me", transaction5.CookieNameValue);
|
var transaction6 = await SendAsync(server, "http://example.com/me", transaction5.CookieNameValue);
|
||||||
// FindClaimValue(transaction6, ClaimTypes.Name).ShouldBe("hao");
|
FindClaimValue(transaction6, ClaimTypes.Name).ShouldBe("hao");
|
||||||
// }
|
}
|
||||||
|
|
||||||
// [Fact]
|
[Fact]
|
||||||
// public async Task TwoFactorRememberCookieVerification()
|
public async Task TwoFactorRememberCookieVerification()
|
||||||
// {
|
{
|
||||||
// var server = CreateServer();
|
var server = CreateServer();
|
||||||
|
|
||||||
// var transaction1 = await SendAsync(server, "http://example.com/createMe");
|
var transaction1 = await SendAsync(server, "http://example.com/createMe");
|
||||||
// transaction1.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction1.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
// Assert.Null(transaction1.SetCookie);
|
Assert.Null(transaction1.SetCookie);
|
||||||
|
|
||||||
// var transaction2 = await SendAsync(server, "http://example.com/twofactorRememeber");
|
var transaction2 = await SendAsync(server, "http://example.com/twofactorRememeber");
|
||||||
// transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction2.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
|
|
||||||
// string setCookie = transaction2.SetCookie;
|
string setCookie = transaction2.SetCookie;
|
||||||
// setCookie.ShouldContain(IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme + "=");
|
setCookie.ShouldContain(IdentityOptions.TwoFactorRememberMeCookieAuthenticationScheme + "=");
|
||||||
// setCookie.ShouldContain("; expires=");
|
setCookie.ShouldContain("; expires=");
|
||||||
|
|
||||||
// var transaction3 = await SendAsync(server, "http://example.com/isTwoFactorRememebered", transaction2.CookieNameValue);
|
var transaction3 = await SendAsync(server, "http://example.com/isTwoFactorRememebered", transaction2.CookieNameValue);
|
||||||
// transaction3.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
transaction3.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// private static string FindClaimValue(Transaction transaction, string claimType)
|
private static string FindClaimValue(Transaction transaction, string claimType)
|
||||||
// {
|
{
|
||||||
// var claim = transaction.ResponseElement.Elements("claim").SingleOrDefault(elt => elt.Attribute("type").Value == claimType);
|
var claim = transaction.ResponseElement.Elements("claim").SingleOrDefault(elt => elt.Attribute("type").Value == claimType);
|
||||||
// if (claim == null)
|
if (claim == null)
|
||||||
// {
|
{
|
||||||
// return null;
|
return null;
|
||||||
// }
|
}
|
||||||
// return claim.Attribute("value").Value;
|
return claim.Attribute("value").Value;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// private static async Task<XElement> GetAuthData(TestServer server, string url, string cookie)
|
private static async Task<XElement> GetAuthData(TestServer server, string url, string cookie)
|
||||||
// {
|
{
|
||||||
// var request = new HttpRequestMessage(HttpMethod.Get, url);
|
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
// request.Headers.Add("Cookie", cookie);
|
request.Headers.Add("Cookie", cookie);
|
||||||
|
|
||||||
// HttpResponseMessage response2 = await server.CreateClient().SendAsync(request);
|
HttpResponseMessage response2 = await server.CreateClient().SendAsync(request);
|
||||||
// string text = await response2.Content.ReadAsStringAsync();
|
string text = await response2.Content.ReadAsStringAsync();
|
||||||
// XElement me = XElement.Parse(text);
|
XElement me = XElement.Parse(text);
|
||||||
// return me;
|
return me;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// private static TestServer CreateServer(Action<IServiceCollection> configureServices = null, Func<HttpContext, Task> testpath = null, Uri baseAddress = null)
|
private static TestServer CreateServer(Action<IServiceCollection> configureServices = null, Func<HttpContext, Task> testpath = null, Uri baseAddress = null)
|
||||||
// {
|
{
|
||||||
// var server = TestServer.Create(app =>
|
var server = TestServer.Create(app =>
|
||||||
// {
|
{
|
||||||
// app.UseIdentity();
|
app.UseIdentity();
|
||||||
// app.Use(async (context, next) =>
|
app.Use(async (context, next) =>
|
||||||
// {
|
{
|
||||||
// var req = context.Request;
|
var req = context.Request;
|
||||||
// var res = context.Response;
|
var res = context.Response;
|
||||||
// var userManager = context.RequestServices.GetRequiredService<UserManager<TestUser>>();
|
var userManager = context.RequestServices.GetRequiredService<UserManager<TestUser>>();
|
||||||
// var signInManager = context.RequestServices.GetRequiredService<SignInManager<TestUser>>();
|
var signInManager = context.RequestServices.GetRequiredService<SignInManager<TestUser>>();
|
||||||
// PathString remainder;
|
PathString remainder;
|
||||||
// if (req.Path == new PathString("/normal"))
|
if (req.Path == new PathString("/normal"))
|
||||||
// {
|
{
|
||||||
// res.StatusCode = 200;
|
res.StatusCode = 200;
|
||||||
// }
|
}
|
||||||
// else if (req.Path == new PathString("/createMe"))
|
else if (req.Path == new PathString("/createMe"))
|
||||||
// {
|
{
|
||||||
// var result = await userManager.CreateAsync(new TestUser("hao"), TestPassword);
|
var result = await userManager.CreateAsync(new TestUser("hao"), TestPassword);
|
||||||
// res.StatusCode = result.Succeeded ? 200 : 500;
|
res.StatusCode = result.Succeeded ? 200 : 500;
|
||||||
// }
|
}
|
||||||
// else if (req.Path == new PathString("/createSimple"))
|
else if (req.Path == new PathString("/createSimple"))
|
||||||
// {
|
{
|
||||||
// var result = await userManager.CreateAsync(new TestUser("simple"), "aaaaaa");
|
var result = await userManager.CreateAsync(new TestUser("simple"), "aaaaaa");
|
||||||
// res.StatusCode = result.Succeeded ? 200 : 500;
|
res.StatusCode = result.Succeeded ? 200 : 500;
|
||||||
// }
|
}
|
||||||
// else if (req.Path == new PathString("/protected"))
|
else if (req.Path == new PathString("/protected"))
|
||||||
// {
|
{
|
||||||
// res.StatusCode = 401;
|
res.StatusCode = 401;
|
||||||
// }
|
}
|
||||||
// else if (req.Path.StartsWithSegments(new PathString("/pwdLogin"), out remainder))
|
else if (req.Path.StartsWithSegments(new PathString("/pwdLogin"), out remainder))
|
||||||
// {
|
{
|
||||||
// var isPersistent = bool.Parse(remainder.Value.Substring(1));
|
var isPersistent = bool.Parse(remainder.Value.Substring(1));
|
||||||
// var result = await signInManager.PasswordSignInAsync("hao", TestPassword, isPersistent, false);
|
var result = await signInManager.PasswordSignInAsync("hao", TestPassword, isPersistent, false);
|
||||||
// res.StatusCode = result.Succeeded ? 200 : 500;
|
res.StatusCode = result.Succeeded ? 200 : 500;
|
||||||
// }
|
}
|
||||||
// else if (req.Path == new PathString("/twofactorRememeber"))
|
else if (req.Path == new PathString("/twofactorRememeber"))
|
||||||
// {
|
{
|
||||||
// var user = await userManager.FindByNameAsync("hao");
|
var user = await userManager.FindByNameAsync("hao");
|
||||||
// await signInManager.RememberTwoFactorClientAsync(user);
|
await signInManager.RememberTwoFactorClientAsync(user);
|
||||||
// res.StatusCode = 200;
|
res.StatusCode = 200;
|
||||||
// }
|
}
|
||||||
// else if (req.Path == new PathString("/isTwoFactorRememebered"))
|
else if (req.Path == new PathString("/isTwoFactorRememebered"))
|
||||||
// {
|
{
|
||||||
// var user = await userManager.FindByNameAsync("hao");
|
var user = await userManager.FindByNameAsync("hao");
|
||||||
// var result = await signInManager.IsTwoFactorClientRememberedAsync(user);
|
var result = await signInManager.IsTwoFactorClientRememberedAsync(user);
|
||||||
// res.StatusCode = result ? 200 : 500;
|
res.StatusCode = result ? 200 : 500;
|
||||||
// }
|
}
|
||||||
// else if (req.Path == new PathString("/twofactorSignIn"))
|
else if (req.Path == new PathString("/twofactorSignIn"))
|
||||||
// {
|
{
|
||||||
// }
|
}
|
||||||
// else if (req.Path == new PathString("/me"))
|
else if (req.Path == new PathString("/me"))
|
||||||
// {
|
{
|
||||||
// var auth = new AuthenticateContext("Application");
|
var auth = new AuthenticateContext("Application");
|
||||||
// Debugger.Launch();
|
auth.Authenticated(context.User, new AuthenticationProperties().Items, new AuthenticationDescription().Items);
|
||||||
// auth.Authenticated(context.User, new AuthenticationProperties().Items, new AuthenticationDescription().Items);
|
Describe(res, auth);
|
||||||
// Describe(res, auth);
|
}
|
||||||
// }
|
else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder))
|
||||||
// else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder))
|
{
|
||||||
// {
|
var auth = new AuthenticateContext(remainder.Value.Substring(1));
|
||||||
// var auth = new AuthenticateContext(remainder.Value.Substring(1));
|
await context.Authentication.AuthenticateAsync(auth);
|
||||||
// await context.Authentication.AuthenticateAsync(auth);
|
Describe(res, auth);
|
||||||
// Describe(res, auth);
|
}
|
||||||
// }
|
else if (req.Path == new PathString("/testpath") && testpath != null)
|
||||||
// else if (req.Path == new PathString("/testpath") && testpath != null)
|
{
|
||||||
// {
|
await testpath(context);
|
||||||
// await testpath(context);
|
}
|
||||||
// }
|
else
|
||||||
// else
|
{
|
||||||
// {
|
await next();
|
||||||
// await next();
|
}
|
||||||
// }
|
});
|
||||||
// });
|
},
|
||||||
// },
|
services =>
|
||||||
// services =>
|
{
|
||||||
// {
|
services.AddIdentity<TestUser, TestRole>();
|
||||||
// services.AddIdentity<TestUser, TestRole>();
|
services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore<TestUser>>();
|
||||||
// services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore<TestUser>>();
|
services.AddSingleton<IRoleStore<TestRole>, InMemoryRoleStore<TestRole>>();
|
||||||
// services.AddSingleton<IRoleStore<TestRole>, InMemoryRoleStore<TestRole>>();
|
if (configureServices != null)
|
||||||
// if (configureServices != null)
|
{
|
||||||
// {
|
configureServices(services);
|
||||||
// configureServices(services);
|
}
|
||||||
// }
|
});
|
||||||
// });
|
server.BaseAddress = baseAddress;
|
||||||
// server.BaseAddress = baseAddress;
|
return server;
|
||||||
// return server;
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void Describe(HttpResponse res, AuthenticateContext result)
|
private static void Describe(HttpResponse res, AuthenticateContext result)
|
||||||
// {
|
{
|
||||||
// res.StatusCode = 200;
|
res.StatusCode = 200;
|
||||||
// res.ContentType = "text/xml";
|
res.ContentType = "text/xml";
|
||||||
// var xml = new XElement("xml");
|
var xml = new XElement("xml");
|
||||||
// if (result != null && result.Principal != null)
|
if (result != null && result.Principal != null)
|
||||||
// {
|
{
|
||||||
// xml.Add(result.Principal.Claims.Select(claim => new XElement("claim", new XAttribute("type", claim.Type), new XAttribute("value", claim.Value))));
|
xml.Add(result.Principal.Claims.Select(claim => new XElement("claim", new XAttribute("type", claim.Type), new XAttribute("value", claim.Value))));
|
||||||
// }
|
}
|
||||||
// if (result != null && result.Properties != null)
|
if (result != null && result.Properties != null)
|
||||||
// {
|
{
|
||||||
// xml.Add(result.Properties.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value))));
|
xml.Add(result.Properties.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value))));
|
||||||
// }
|
}
|
||||||
// using (var memory = new MemoryStream())
|
using (var memory = new MemoryStream())
|
||||||
// {
|
{
|
||||||
// using (var writer = new XmlTextWriter(memory, Encoding.UTF8))
|
using (var writer = new XmlTextWriter(memory, Encoding.UTF8))
|
||||||
// {
|
{
|
||||||
// xml.WriteTo(writer);
|
xml.WriteTo(writer);
|
||||||
// }
|
}
|
||||||
// res.Body.Write(memory.ToArray(), 0, memory.ToArray().Length);
|
res.Body.Write(memory.ToArray(), 0, memory.ToArray().Length);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// private static async Task<Transaction> SendAsync(TestServer server, string uri, string cookieHeader = null, bool ajaxRequest = false)
|
private static async Task<Transaction> SendAsync(TestServer server, string uri, string cookieHeader = null, bool ajaxRequest = false)
|
||||||
// {
|
{
|
||||||
// var request = new HttpRequestMessage(HttpMethod.Get, uri);
|
var request = new HttpRequestMessage(HttpMethod.Get, uri);
|
||||||
// if (!string.IsNullOrEmpty(cookieHeader))
|
if (!string.IsNullOrEmpty(cookieHeader))
|
||||||
// {
|
{
|
||||||
// request.Headers.Add("Cookie", cookieHeader);
|
request.Headers.Add("Cookie", cookieHeader);
|
||||||
// }
|
}
|
||||||
// if (ajaxRequest)
|
if (ajaxRequest)
|
||||||
// {
|
{
|
||||||
// request.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
|
||||||
// }
|
}
|
||||||
// var transaction = new Transaction
|
var transaction = new Transaction
|
||||||
// {
|
{
|
||||||
// Request = request,
|
Request = request,
|
||||||
// Response = await server.CreateClient().SendAsync(request),
|
Response = await server.CreateClient().SendAsync(request),
|
||||||
// };
|
};
|
||||||
// if (transaction.Response.Headers.Contains("Set-Cookie"))
|
if (transaction.Response.Headers.Contains("Set-Cookie"))
|
||||||
// {
|
{
|
||||||
// transaction.SetCookie = transaction.Response.Headers.GetValues("Set-Cookie").SingleOrDefault();
|
transaction.SetCookie = transaction.Response.Headers.GetValues("Set-Cookie").SingleOrDefault();
|
||||||
// }
|
}
|
||||||
// if (!string.IsNullOrEmpty(transaction.SetCookie))
|
if (!string.IsNullOrEmpty(transaction.SetCookie))
|
||||||
// {
|
{
|
||||||
// transaction.CookieNameValue = transaction.SetCookie.Split(new[] { ';' }, 2).First();
|
transaction.CookieNameValue = transaction.SetCookie.Split(new[] { ';' }, 2).First();
|
||||||
// }
|
}
|
||||||
// transaction.ResponseText = await transaction.Response.Content.ReadAsStringAsync();
|
transaction.ResponseText = await transaction.Response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
// if (transaction.Response.Content != null &&
|
if (transaction.Response.Content != null &&
|
||||||
// transaction.Response.Content.Headers.ContentType != null &&
|
transaction.Response.Content.Headers.ContentType != null &&
|
||||||
// transaction.Response.Content.Headers.ContentType.MediaType == "text/xml")
|
transaction.Response.Content.Headers.ContentType.MediaType == "text/xml")
|
||||||
// {
|
{
|
||||||
// transaction.ResponseElement = XElement.Parse(transaction.ResponseText);
|
transaction.ResponseElement = XElement.Parse(transaction.ResponseText);
|
||||||
// }
|
}
|
||||||
// return transaction;
|
return transaction;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// private class Transaction
|
private class Transaction
|
||||||
// {
|
{
|
||||||
// public HttpRequestMessage Request { get; set; }
|
public HttpRequestMessage Request { get; set; }
|
||||||
// public HttpResponseMessage Response { get; set; }
|
public HttpResponseMessage Response { get; set; }
|
||||||
|
|
||||||
// public string SetCookie { get; set; }
|
public string SetCookie { get; set; }
|
||||||
// public string CookieNameValue { get; set; }
|
public string CookieNameValue { get; set; }
|
||||||
|
|
||||||
// public string ResponseText { get; set; }
|
public string ResponseText { get; set; }
|
||||||
// public XElement ResponseElement { get; set; }
|
public XElement ResponseElement { get; set; }
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,20 +44,22 @@ namespace Microsoft.AspNet.Identity.Test
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
var contextAccessor = new Mock<IHttpContextAccessor>();
|
var contextAccessor = new Mock<IHttpContextAccessor>();
|
||||||
contextAccessor.Setup(a => a.HttpContext).Returns(httpContext.Object);
|
contextAccessor.Setup(a => a.HttpContext).Returns(httpContext.Object);
|
||||||
|
var id = new ClaimsIdentity(IdentityOptions.ApplicationCookieAuthenticationScheme);
|
||||||
|
id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
|
||||||
|
var principal = new ClaimsPrincipal(id);
|
||||||
|
|
||||||
var properties = new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow, IsPersistent = isPersistent };
|
var properties = new AuthenticationProperties { IssuedUtc = DateTimeOffset.UtcNow, IsPersistent = isPersistent };
|
||||||
var signInManager = new Mock<SignInManager<TestUser>>(userManager.Object,
|
var signInManager = new Mock<SignInManager<TestUser>>(userManager.Object,
|
||||||
contextAccessor.Object, claimsManager.Object, options.Object, null);
|
contextAccessor.Object, claimsManager.Object, options.Object, null);
|
||||||
signInManager.Setup(s => s.ValidateSecurityStampAsync(It.IsAny<ClaimsPrincipal>(), user.Id)).ReturnsAsync(user).Verifiable();
|
signInManager.Setup(s => s.ValidateSecurityStampAsync(It.IsAny<ClaimsPrincipal>(), user.Id)).ReturnsAsync(user).Verifiable();
|
||||||
signInManager.Setup(s => s.SignInAsync(user, properties, null)).Returns(Task.FromResult(0)).Verifiable();
|
signInManager.Setup(s => s.CreateUserPrincipalAsync(user)).ReturnsAsync(principal).Verifiable();
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
services.AddInstance(options.Object);
|
services.AddInstance(options.Object);
|
||||||
services.AddInstance(signInManager.Object);
|
services.AddInstance(signInManager.Object);
|
||||||
services.AddInstance<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
services.AddInstance<ISecurityStampValidator>(new SecurityStampValidator<TestUser>());
|
||||||
httpContext.Setup(c => c.RequestServices).Returns(services.BuildServiceProvider());
|
httpContext.Setup(c => c.RequestServices).Returns(services.BuildServiceProvider());
|
||||||
var id = new ClaimsIdentity(IdentityOptions.ApplicationCookieAuthenticationScheme);
|
|
||||||
id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
|
|
||||||
|
|
||||||
var ticket = new AuthenticationTicket(new ClaimsPrincipal(id),
|
var ticket = new AuthenticationTicket(principal,
|
||||||
properties,
|
properties,
|
||||||
IdentityOptions.ApplicationCookieAuthenticationScheme);
|
IdentityOptions.ApplicationCookieAuthenticationScheme);
|
||||||
var context = new CookieValidatePrincipalContext(httpContext.Object, ticket, new CookieAuthenticationOptions());
|
var context = new CookieValidatePrincipalContext(httpContext.Object, ticket, new CookieAuthenticationOptions());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue