Add test for AuthenticationSchemes (#17816)
This commit is contained in:
parent
5f169dce14
commit
0977c9ac59
|
|
@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Authorization.Test
|
|||
// Assert
|
||||
Assert.False(next.Called);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task HasEndpointWithoutAuth_AnonymousUser_Allows()
|
||||
{
|
||||
|
|
@ -135,6 +135,27 @@ namespace Microsoft.AspNetCore.Authorization.Test
|
|||
Assert.True(authenticationService.ChallengeCalled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HasEndpointWithAuth_ChallengesAuthenticationSchemes()
|
||||
{
|
||||
// Arrange
|
||||
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
|
||||
var policyProvider = new Mock<IAuthorizationPolicyProvider>();
|
||||
policyProvider.Setup(p => p.GetDefaultPolicyAsync()).ReturnsAsync(policy);
|
||||
var next = new TestRequestDelegate();
|
||||
var authenticationService = new TestAuthenticationService();
|
||||
|
||||
var middleware = CreateMiddleware(next.Invoke, policyProvider.Object);
|
||||
var context = GetHttpContext(endpoint: CreateEndpoint(new AuthorizeAttribute() { AuthenticationSchemes = "whatever"}), authenticationService: authenticationService);
|
||||
|
||||
// Act
|
||||
await middleware.Invoke(context);
|
||||
|
||||
// Assert
|
||||
Assert.False(next.Called);
|
||||
Assert.True(authenticationService.ChallengeCalled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HasEndpointWithAuth_AnonymousUser_ChallengePerScheme()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue