Add test for CookieAuthentication
This commit is contained in:
parent
6a9f1f9887
commit
1ef62a40b3
|
|
@ -90,7 +90,6 @@ namespace Microsoft.AspNetCore.Authentication.Cookies
|
||||||
Assert.True(responded.Single().StartsWith("http://example.com/Account/Login"));
|
Assert.True(responded.Single().StartsWith("http://example.com/Account/Login"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(true)]
|
[InlineData(true)]
|
||||||
[InlineData(false)]
|
[InlineData(false)]
|
||||||
|
|
@ -1052,6 +1051,53 @@ namespace Microsoft.AspNetCore.Authentication.Cookies
|
||||||
Assert.Equal("?ReturnUrl=%2F", location.Query);
|
Assert.Equal("?ReturnUrl=%2F", location.Query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task RedirectUriIsHoneredAfterSignin()
|
||||||
|
{
|
||||||
|
var options = new CookieAuthenticationOptions
|
||||||
|
{
|
||||||
|
LoginPath = "/testpath",
|
||||||
|
CookieName = "TestCookie"
|
||||||
|
};
|
||||||
|
|
||||||
|
var server = CreateServer(options, async context =>
|
||||||
|
{
|
||||||
|
await context.Authentication.SignInAsync(
|
||||||
|
CookieAuthenticationDefaults.AuthenticationScheme,
|
||||||
|
new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", CookieAuthenticationDefaults.AuthenticationScheme))),
|
||||||
|
new AuthenticationProperties { RedirectUri = "/redirect_test" });
|
||||||
|
});
|
||||||
|
var transaction = await SendAsync(server, "http://example.com/testpath");
|
||||||
|
|
||||||
|
Assert.NotEmpty(transaction.SetCookie);
|
||||||
|
Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode);
|
||||||
|
Assert.Equal("/redirect_test", transaction.Response.Headers.Location.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task EnsurePrecedenceOfRedirectUriAfterSignin()
|
||||||
|
{
|
||||||
|
var options = new CookieAuthenticationOptions
|
||||||
|
{
|
||||||
|
LoginPath = "/testpath",
|
||||||
|
ReturnUrlParameter = "return",
|
||||||
|
CookieName = "TestCookie"
|
||||||
|
};
|
||||||
|
|
||||||
|
var server = CreateServer(options, async context =>
|
||||||
|
{
|
||||||
|
await context.Authentication.SignInAsync(
|
||||||
|
CookieAuthenticationDefaults.AuthenticationScheme,
|
||||||
|
new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice", CookieAuthenticationDefaults.AuthenticationScheme))),
|
||||||
|
new AuthenticationProperties { RedirectUri = "/redirect_test" });
|
||||||
|
});
|
||||||
|
var transaction = await SendAsync(server, "http://example.com/testpath?return=%2Fret_path_2");
|
||||||
|
|
||||||
|
Assert.NotEmpty(transaction.SetCookie);
|
||||||
|
Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode);
|
||||||
|
Assert.Equal("/ret_path_2", transaction.Response.Headers.Location.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task NestedMapWillNotAffectAccessDenied()
|
public async Task NestedMapWillNotAffectAccessDenied()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue