public void Should_throw_when_the_user_is_anonymous()
        {
            // Arrange
            SecurityConfigurator.Configure(policy =>
            {
                policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                policy.For <BlogController>(x => x.Index()).DenyAnonymousAccess();
            });

            var securityHandler = new SecurityHandler();

            // Act
            var exception = Assert.Throws <PolicyViolationException>(() => securityHandler.HandleSecurityFor(NameHelper.Controller <BlogController>(), "Index", SecurityContext.Current));

            // Assert
            Assert.That(exception.PolicyType, Is.EqualTo(typeof(DenyAnonymousAccessPolicy)));
            Assert.That(exception.Message, Does.Contain("Anonymous access denied"));
        }
Beispiel #2
0
        public void Should_have_1_policycontainer()
        {
            SecurityConfigurator.Reset();

            // Act
            SecurityConfigurator.Configure(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.GetRolesFrom(StaticHelper.GetRolesExcludingOwner);
                configuration.For <BlogController>(x => x.Index());
                configuration.For <BlogController>(x => x.Index());
            });

            Assert.That(SecurityConfiguration.Current.PolicyContainers.Count(), Is.EqualTo(1));
            Assert.That(SecurityConfiguration.Current.PolicyContainers.First().ControllerName, Is.EqualTo(NameHelper.Controller <BlogController>()));
            Assert.That(SecurityConfiguration.Current.PolicyContainers.First().ActionName, Is.EqualTo("Index"));
        }
        public void Should_have_policycontainer_for_Blog_Index()
        {
            // Act
            Because();

            // Assert
            var policyContainer = _configurationExpression.Runtime.PolicyContainers.GetContainerFor(NameHelper.Controller <BlogController>(), "Index");

            Assert.That(policyContainer, Is.Not.Null);
            Assert.That(_configurationExpression.Runtime.PolicyContainers.Count(), Is.EqualTo(1));
        }
        public void Should_have_policyappender_set_to_instance_of_DefaultPolicyAppender()
        {
            // Arrange
            var expectedPolicyAppender  = new DefaultPolicyAppender();
            var configurationExpression = TestDataFactory.CreateValidConfigurationExpression();

            // Act
            configurationExpression.SetPolicyAppender(expectedPolicyAppender);

            // Assert
            configurationExpression.For <BlogController>(x => x.Index());
            var policyContainer = (PolicyContainer)configurationExpression.Runtime.PolicyContainers.GetContainerFor(NameHelper.Controller <BlogController>(), "Index");

            Assert.That(policyContainer.PolicyAppender, Is.EqualTo(expectedPolicyAppender));
        }
        public void Should_have_PolicyAppender_set_to_PolicyAppender()
        {
            // Act
            Because();

            // Assert
            var policyContainer = (PolicyContainer)_configurationExpression.Runtime.PolicyContainers.GetContainerFor(NameHelper.Controller <BlogController>(), "Index");

            Assert.That(policyContainer.PolicyAppender, Is.TypeOf(typeof(DefaultPolicyAppender)));
        }