Add test for AuthenticationSchemes (#17816)
This commit is contained in:
parent
5f169dce14
commit
0977c9ac59
|
|
@ -135,6 +135,27 @@ namespace Microsoft.AspNetCore.Authorization.Test
|
||||||
Assert.True(authenticationService.ChallengeCalled);
|
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]
|
[Fact]
|
||||||
public async Task HasEndpointWithAuth_AnonymousUser_ChallengePerScheme()
|
public async Task HasEndpointWithAuth_AnonymousUser_ChallengePerScheme()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue