public async Task HandleAsyncShouldFailWhenUserIsNull() { var requirement = new ClaimsAuthorizationRequirement("asdf", null); var context = new AuthorizationHandlerContext(new [] { requirement }, null, null); await requirement.HandleAsync(context); Assert.IsFalse(context.HasSucceeded); }
public async Task ShouldFailWithoutExpectedClaim() { var requirement = new ClaimsAuthorizationRequirement("asdf", new [] { "hi" }); var context = new AuthorizationHandlerContext(new[] { requirement }, new ClaimsPrincipal(), null); await requirement.HandleAsync(context); Assert.IsFalse(context.HasSucceeded); }
private static async Task AssertMissingAllowedValuesShouldSucceed(ClaimsAuthorizationRequirement requirement) { Assert.IsNotNull(requirement); var context = new AuthorizationHandlerContext(new [] { requirement }, UserWithClaim(requirement.ClaimType), null); await requirement.HandleAsync(context); Assert.IsTrue(context.HasSucceeded, "context.HasSucceeded"); }
private static async Task AssertClaimValueAffectsSuccess(string claimValue, ClaimsAuthorizationRequirement requirement, bool shouldSucceed) { var identity = new ClaimsIdentity(new[] { new Claim(requirement.ClaimType, claimValue) }); var user = new ClaimsPrincipal(identity); var context = new AuthorizationHandlerContext(new[] { requirement }, user, null); await requirement.HandleAsync(context); Assert.AreEqual(shouldSucceed, context.HasSucceeded); }
public async Task HandleAsyncShouldThrowWhenPassedNullContext() { var requirement = new ClaimsAuthorizationRequirement("asdf", new string[0]); await requirement.HandleAsync(null); }