Flow endpoint and httpcontext always from authz middleware (#22672)

This commit is contained in:
Hao Kung 2020-06-19 18:14:47 -07:00 committed by GitHub
parent 4d7a79ad64
commit 8541bf6c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -61,8 +61,7 @@ namespace Microsoft.AspNetCore.Authorization
return;
}
// Note that the resource will be null if there is no matched endpoint
var authorizeResult = await policyEvaluator.AuthorizeAsync(policy, authenticateResult, context, resource: endpoint);
var authorizeResult = await policyEvaluator.AuthorizeAsync(policy, authenticateResult, context, resource: context);
var authorizationMiddlewareResultHandler = context.RequestServices.GetRequiredService<IAuthorizationMiddlewareResultHandler>();
await authorizationMiddlewareResultHandler.HandleAsync(_next, context, policy, authorizeResult);

View File

@ -314,13 +314,13 @@ namespace Microsoft.AspNetCore.Authorization.Test
}
[Fact]
public async Task AuthZResourceShouldBeEndpoint()
public async Task AuthZResourceShouldBeHttpContextAndHaveHEndpoint()
{
// Arrange
object resource = null;
HttpContext resource = null;
var policy = new AuthorizationPolicyBuilder().RequireAssertion(c =>
{
resource = c.Resource;
resource = c.Resource as HttpContext;
return true;
}).Build();
var policyProvider = new Mock<IAuthorizationPolicyProvider>();
@ -335,7 +335,9 @@ namespace Microsoft.AspNetCore.Authorization.Test
await middleware.Invoke(context);
// Assert
Assert.Equal(endpoint, resource);
Assert.NotNull(resource);
Assert.Equal(context, resource);
Assert.Equal(endpoint, resource.GetEndpoint());
}
[Fact]