コード例 #1
0
        public void Initialize()
        {
            _agent = new Mock<IControllersAgent>();
            _controllersExecutor = new Mock<IControllerExecutor>();
            _processor = new ControllersProcessor(_agent.Object, _controllersExecutor.Object);

            _context = new Mock<IOwinContext>();

            _metaData = new ControllerMetaData(typeof(TestController1),
                new ControllerExecParameters(new ControllerRouteInfo("/foo/bar")));

            _agent.Setup(x => x.MatchControllerRoute(It.IsAny<IControllerMetaData>(), It.IsAny<string>(), It.IsAny<string>())).Returns(new RouteMatchResult(true, _routeParameters));
            _agent.Setup(x => x.GetStandardControllersMetaData()).Returns(() => new List<IControllerMetaData>
            {
                _metaData
            });

            _agent.Setup(x => x.IsSecurityRulesViolated(It.IsAny<IControllerMetaData>(), It.IsAny<ClaimsPrincipal>())).Returns(SecurityRuleCheckResult.Ok);

            _context.SetupGet(x => x.Request.Path).Returns(new PathString("/foo/bar"));
            _context.SetupGet(x => x.Request.Method).Returns("GET");
            _context.SetupGet(x => x.Authentication).Returns(new Mock<IAuthenticationManager>().Object);
        }
コード例 #2
0
        public void IsAnyPageController_404Handler_False()
        {
            // Assign
            var metaData = new ControllerMetaData(null, null, new ControllerRole(false, false, true));

            // Act & Assert
            Assert.IsFalse(_agent.IsAnyPageController(metaData));
        }
コード例 #3
0
        public void IsSecurityRulesViolated_UserExistNotAuthenticatedUser_NotAuthenticated()
        {
            // Assign

            var metaData = new ControllerMetaData(null, null, null, new ControllerSecurity(true));

            var id = new Mock<IIdentity>();
            id.Setup(x => x.IsAuthenticated).Returns(false);
            var user = new ClaimsPrincipal(id.Object);

            // Act & Assert
            Assert.AreEqual(SecurityRuleCheckResult.NotAuthenticated, _agent.IsSecurityRulesViolated(metaData, user));
        }
コード例 #4
0
        public void IsSecurityRulesViolated_NoSecurityRules_Ok()
        {
            // Assign
            var metaData = new ControllerMetaData(null);

            // Act & Assert
            Assert.AreEqual(SecurityRuleCheckResult.Ok, _agent.IsSecurityRulesViolated(metaData, null));
        }
コード例 #5
0
        public void IsSecurityRulesViolated_AuthorizationRequiredWithGroupNotAuthorized_NotAuthenticated()
        {
            // Assign

            var metaData = new ControllerMetaData(null, null, null, new ControllerSecurity(true, "Admin"));

            // Act & Assert
            Assert.AreEqual(SecurityRuleCheckResult.NotAuthenticated, _agent.IsSecurityRulesViolated(metaData, null));
        }
コード例 #6
0
        public void IsSecurityRulesViolated_AuthorizationRequiredWithGroupAuthorizedNotInGroup_Forbidden()
        {
            // Assign

            var metaData = new ControllerMetaData(null, null, null, new ControllerSecurity(true, "Admin"));
            var claims = new List<Claim>
            {
                new Claim(ClaimTypes.Name, "Foo"),
                new Claim(ClaimTypes.Role, "User")
            };

            var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
            var user = new ClaimsPrincipal(id);

            // Act & Assert
            Assert.AreEqual(SecurityRuleCheckResult.Forbidden, _agent.IsSecurityRulesViolated(metaData, user));
        }
コード例 #7
0
        public void IsAnyPageController_NormalController_False()
        {
            // Assign
            var metaData = new ControllerMetaData(null, new ControllerExecParameters(new ControllerRouteInfo("/")));

            // Act & Assert
            Assert.IsFalse(_agent.IsAnyPageController(metaData));
        }
コード例 #8
0
        public void IsAnyPageController_AnyPageController_True()
        {
            // Assign
            var metaData = new ControllerMetaData(null);

            // Act & Assert
            Assert.IsTrue(_agent.IsAnyPageController(metaData));
        }