parent
e5aeb738e3
commit
b3046a0285
|
|
@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
user.Identity == null ||
|
user.Identity == null ||
|
||||||
!user.Identity.IsAuthenticated;
|
!user.Identity.IsAuthenticated;
|
||||||
|
|
||||||
if(userIsAnonymous)
|
if(userIsAnonymous && !HasAllowAnonymous(context))
|
||||||
{
|
{
|
||||||
base.Fail(context);
|
base.Fail(context);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,26 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
Assert.NotNull(authorizationContext.Result);
|
Assert.NotNull(authorizationContext.Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Invoke_EmptyClaimsWithAllowAnonymousAttributeShouldNotRejectAnonymousUser()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
||||||
|
var authorizeAttribute = new AuthorizeAttribute();
|
||||||
|
var authorizationContext = GetAuthorizationContext(services =>
|
||||||
|
services.AddInstance<IAuthorizationService>(authorizationService),
|
||||||
|
anonymous: true
|
||||||
|
);
|
||||||
|
|
||||||
|
authorizationContext.Filters.Add(new AllowAnonymousAttribute());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await authorizeAttribute.OnAuthorizationAsync(authorizationContext);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Null(authorizationContext.Result);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Invoke_EmptyClaimsShouldAuthorizeAuthenticatedUser()
|
public async Task Invoke_EmptyClaimsShouldAuthorizeAuthenticatedUser()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue