コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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");
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public async Task HandleAsyncShouldThrowWhenPassedNullContext()
 {
     var requirement = new ClaimsAuthorizationRequirement("asdf", new string[0]);
     await requirement.HandleAsync(null);
 }