I've got a policy that I want to test in C#
public class WorkflowCreatePolicy
{
public AuthorizationPolicy AuthorizationPolicy =>
new AuthorizationPolicyBuilder()
.RequireClaim("scope", "WorkflowAdmin")
.Build();
}
Does anyone know of a way to test the AuthorizationPolicy to confirm that the scope "WorkflowAdmin" is successful and all others aren't?
This is what I see when I inspect the object:
I've managed to find this website: Authorization Handler Unit Tests but its talking about testing handlers and has code that marks the auth attempt as successful.
i'm not sure if this is getting close or not. It currently doesn't pass
[Test]
public void GivenPolicyName_WhenICallPolicyChecks_ThenItPasses()
{
ClaimsPrincipal user = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim> { new Claim(CustomClaims.Scope, "WorkflowAdmin") }));
WorkflowCreatePolicy workflowCreatePolicy = new WorkflowCreatePolicy();
AuthorizationHandlerContext authorizationHandlerContext = new AuthorizationHandlerContext(workflowCreatePolicy.AuthorizationPolicy.Requirements, user, null);
Assert.That(authorizationHandlerContext.HasSucceeded, Is.EqualTo(true));
}