public void Should_throw_ArgumentNullException_when_configuration_is_null()
        {
            // Arrange
            SecurityConfigurator.Reset();
            const ISecurityConfiguration nullConfiguration = null;

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => SecurityConfigurator.SetConfiguration(nullConfiguration));
        }
Exemple #2
0
        public void Should_throw_when_security_has_not_been_configured()
        {
            // Arrange
            SecurityConfigurator.Reset();

            // Act
            var exception = Assert.Throws <InvalidOperationException>(() => { var x = SecurityContext.Current; });

            // Assert
            Assert.That(exception.Message, Is.EqualTo("Security has not been configured!"));
        }
        public void Should_have_configuration()
        {
            // Arrange
            SecurityConfigurator.Reset();
            var configuration = MockRepository.GenerateMock <ISecurityConfiguration>();

            // Act
            SecurityConfigurator.SetConfiguration(configuration);

            // Assert
            Assert.That(SecurityConfiguration.Current, Is.EqualTo(configuration));
        }
Exemple #4
0
        public void Should_have_configuration()
        {
            // Arrange
            SecurityConfigurator.Reset();
            var configuration = new Mock <ISecurityConfiguration>();

            // Act
            SecurityConfigurator.SetConfiguration(configuration.Object);

            // Assert
            Assert.That(SecurityConfiguration.Current, Is.EqualTo(configuration));
        }
        public void SetUp()
        {
            // Arrange
            SecurityConfigurator.Reset();

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

            _policyContainers = SecurityConfiguration.Current.PolicyContainers;
        }
        public void Should_create_new_configuration_instance()
        {
            // Arrange
            var configuration = MockRepository.GenerateMock <ISecurityConfiguration>();

            SecurityConfigurator.SetConfiguration(configuration);

            // Act
            SecurityConfigurator.Reset();

            // Assert
            var exception = Assert.Throws <InvalidOperationException>(() => {
                var x = SecurityConfiguration.Current;
            });

            Assert.That(exception.Message, Is.EqualTo("Security has not been configured!"));
        }
        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 <BlogController> .Controller()));
            Assert.That(SecurityConfiguration.Current.PolicyContainers.First().ActionName, Is.EqualTo("Index"));
        }
Exemple #8
0
        public void SetUp()
        {
            // Arrange
            SecurityConfigurator.Reset();

            // Act
            SecurityConfigurator.Configure(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.GetRolesFrom(StaticHelper.GetRolesExcludingOwner);

                configuration.For <BlogController>(x => x.Index()).DenyAnonymousAccess();
                configuration.For <BlogController>(x => x.AddPost()).RequireAnyRole(UserRole.Writer, UserRole.Publisher, UserRole.Owner);
            });

            _policyContainers = SecurityConfiguration.Current.PolicyContainers;
        }
        public void SetUp()
        {
            // Arrange
            _defaultPolicyAppender = TestDataFactory.CreateValidPolicyAppender();
            _fakePolicyAppender    = TestDataFactory.CreateFakePolicyAppender();

            SecurityConfigurator.Reset();

            // Act
            SecurityConfigurator.Configure(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);
                configuration.GetRolesFrom(StaticHelper.GetRolesExcludingOwner);

                configuration.SetPolicyAppender(_defaultPolicyAppender);
                configuration.For <BlogController>(x => x.Index()).DenyAnonymousAccess();

                configuration.SetPolicyAppender(_fakePolicyAppender);
                configuration.For <BlogController>(x => x.AddPost()).RequireRole(UserRole.Writer, UserRole.Publisher, UserRole.Owner);
            });

            _policyContainers = SecurityConfiguration.Current.PolicyContainers;
        }
 public void SetUp()
 {
     // Arrange
     SecurityConfigurator.Reset();
     _configurationExpression = delegate { TestDataFactory.CreateValidConfigurationExpression(); };
 }
Exemple #11
0
 public void SetUp()
 {
     SecurityConfigurator.Reset();
 }
Exemple #12
0
 public void SetUp()
 {
     SecurityConfigurator.Reset();
     FakeIoC.Reset();
     _context = new MockSecurityContext();
 }