Пример #1
0
        public async Task OnlyHandlesAuthZyinRequirement()
        {
            var testRole            = "TestRole";
            var testRoleRequirement = new RolesAuthorizationRequirement(new[] { testRole });
            var identity            = new ClaimsIdentity();

            identity.AddClaim(new Claim(identity.RoleClaimType, testRole));
            var principal            = new ClaimsPrincipal(identity);
            var authorizationContext = new AuthorizationHandlerContext(new [] { testRoleRequirement }, principal, null);

            var handler = new AuthZyinHandler(this.context, this.logger);
            await handler.HandleAsync(authorizationContext);

            Assert.Single(authorizationContext.Requirements);
            Assert.Single(authorizationContext.PendingRequirements);
        }
Пример #2
0
        public async Task SucceedsWhenAllRequirementsSucceed()
        {
            var principal            = new ClaimsPrincipal();
            var authorizationContext = new AuthorizationHandlerContext(
                new []
            {
                TestRequirement.TrueRequirement,
                TestRequirement.TrueRequirement,
                TestRequirement.TrueRequirement
            },
                principal,
                null);

            var handler = new AuthZyinHandler(this.context, this.logger);
            await handler.HandleAsync(authorizationContext);

            Assert.Empty(authorizationContext.PendingRequirements);
        }
Пример #3
0
        public async Task FailsWhenOneRequirementFails()
        {
            var principal            = new ClaimsPrincipal();
            var authorizationContext = new AuthorizationHandlerContext(
                new []
            {
                TestRequirement.TrueRequirement,
                TestRequirement.TrueRequirement,
                TestRequirement.FalseRequirement
            },
                principal,
                null);

            var handler = new AuthZyinHandler(this.context, this.logger);
            await handler.HandleAsync(authorizationContext);

            Assert.Single(authorizationContext.PendingRequirements);
            Assert.All(authorizationContext.PendingRequirements, r => object.ReferenceEquals(r, TestRequirement.FalseRequirement));
        }