parent
3636440cae
commit
e5aeb738e3
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
public class AuthorizeAttributeTests : AuthorizeAttributeTestsBase
|
public class AuthorizeAttributeTests : AuthorizeAttributeTestsBase
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Invoke_ValidClaimShouldNotFail()
|
public async Task Invoke_ValidClaimShouldNotFail()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Invoke_EmptyClaimsShouldRejectAnonymousUser()
|
public async Task Invoke_EmptyClaimsShouldRejectAnonymousUser()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Invoke_EmptyClaimsShouldAuthorizeAuthenticatedUser()
|
public async Task Invoke_EmptyClaimsShouldAuthorizeAuthenticatedUser()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
||||||
|
|
@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Invoke_SingleValidClaimShouldSucceed()
|
public async Task Invoke_SingleValidClaimShouldSucceed()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
||||||
|
|
@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Invoke_InvalidClaimShouldFail()
|
public async Task Invoke_InvalidClaimShouldFail()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
var authorizationService = new DefaultAuthorizationService(Enumerable.Empty<IAuthorizationPolicy>());
|
||||||
|
|
@ -97,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Invoke_FailedContextShouldNotCheckPermission()
|
public async Task Invoke_FailedContextShouldNotCheckPermission()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
bool authorizationServiceIsCalled = false;
|
bool authorizationServiceIsCalled = false;
|
||||||
|
|
@ -123,5 +123,22 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(authorizationServiceIsCalled);
|
Assert.False(authorizationServiceIsCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Invoke_NullPoliciesShouldNotFail()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var authorizationService = new DefaultAuthorizationService(policies: null);
|
||||||
|
var authorizeAttribute = new AuthorizeAttribute("Permission", "CanViewPage");
|
||||||
|
var authorizationContext = GetAuthorizationContext(services =>
|
||||||
|
services.AddInstance<IAuthorizationService>(authorizationService)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await authorizeAttribute.OnAuthorizationAsync(authorizationContext);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Null(authorizationContext.Result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue