Esempio n. 1
0
        public void Should_retun_the_type_of_lazy_policies()
        {
            // Arrange
            ISecurityPolicy policy = new LazySecurityPolicy <IgnorePolicy>();

            // Act & assert
            Assert.That(policy.GetPolicyType(), Is.EqualTo(typeof(IgnorePolicy)));
        }
        public void Should_throw_when_no_policy_was_loaded()
        {
            // Arrange
            var lazySecurityPolicy = new LazySecurityPolicy <PolicyWithConstructorArguments>();
            var context            = new MockSecurityContext();

            // Act & assert
            var exception = Assert.Throws <InvalidOperationException>(() => lazySecurityPolicy.Enforce(context));

            Assert.That(exception.Message, Is.EqualTo("A policy of type FluentSecurity.Specification.Policy.PolicyWithConstructorArguments could not be loaded! Make sure the policy has an empty constructor or is registered in your IoC-container."));
        }
        public void Should_not_be_match_for_lazy_policy()
        {
            // Arrange
            var expectation = new HasTypeExpectation<DenyAnonymousAccessPolicy>();
            var policy = new LazySecurityPolicy<IgnorePolicy>();

            // Act
            var isMatch = expectation.IsMatch(policy);

            // Assert
            Assert.That(isMatch, Is.False);
        }
        public void Should_be_match_for_lazy_policy()
        {
            // Arrange
            var expectation = new HasTypeExpectation<IgnorePolicy>();
            var policy = new LazySecurityPolicy<IgnorePolicy>();

            // Act
            var isMatch = expectation.IsMatch(policy);

            // Assert
            Assert.That(isMatch, Is.True);
        }
        public void Should_return_null_when_loading_policy_with_constructor_arguments()
        {
            // Arrange
            SecurityConfigurator.Configure(configuration => {});
            var lazySecurityPolicy = new LazySecurityPolicy <PolicyWithConstructorArguments>();

            // Act
            var policy = lazySecurityPolicy.Load();

            // Assert
            Assert.That(policy, Is.Null);
        }
        public void Should_handle_loading_policy_with_empty_constructor_based_on_SecurityPolicyBase()
        {
            // Arrange
            SecurityConfigurator.Configure(configuraiton => {});
            var lazySecurityPolicy = new LazySecurityPolicy <PolicyWithBaseClass>();

            // Act
            var policy = lazySecurityPolicy.Load();

            // Assert
            Assert.That(policy, Is.TypeOf <PolicyWithBaseClass>());
        }
        public void Should_be_match_for_lazy_policy()
        {
            // Arrange
            var expectation = new DoesNotHaveTypeExpectation <IgnorePolicy>();
            var policy      = new LazySecurityPolicy <IgnorePolicy>();

            // Act
            var isMatch = expectation.IsMatch(policy);

            // Assert
            Assert.That(isMatch, Is.True);
        }
Esempio n. 8
0
        public void Should_return_null_when_no_policy_is_returned_by_service_locator()
        {
            // Arrange
            SecurityConfigurator.Configure(configuration => configuration.ResolveServicesUsing(t => Enumerable.Empty <object>()));
            var lazySecurityPolicy = new LazySecurityPolicy <PolicyWithConstructorArguments>();

            // Act
            var policy = lazySecurityPolicy.Load();

            // Assert
            Assert.That(policy, Is.Null);
        }
        public void Should_not_be_match_for_lazy_policy()
        {
            // Arrange
            var expectation = new HasTypeExpectation <DenyAnonymousAccessPolicy>();
            var policy      = new LazySecurityPolicy <IgnorePolicy>();

            // Act
            var isMatch = expectation.IsMatch(policy);

            // Assert
            Assert.That(isMatch, Is.False);
        }
        public void Should_load_and_enforce_policy_with_failed_result()
        {
            // Arrange
            var lazySecurityPolicy = new LazySecurityPolicy <PolicyWithEmptyConstructor>();
            var context            = new MockSecurityContext(isAuthenticated: false);

            // Act
            var result = lazySecurityPolicy.Enforce(context);

            // Assert
            Assert.That(result.PolicyType, Is.EqualTo(typeof(PolicyWithEmptyConstructor)));
            Assert.That(result.ViolationOccured, Is.True);
        }
        public void Should_load_and_enforce_policy_with_success_result()
        {
            // Arrange
            SecurityConfigurator.Configure(configuraiton => {});
            var lazySecurityPolicy = new LazySecurityPolicy <PolicyWithBaseClass>();
            var context            = new MockSecurityContext(isAuthenticated: true);

            // Act
            var result = lazySecurityPolicy.Enforce(context);

            // Assert
            Assert.That(result.PolicyType, Is.EqualTo(typeof(PolicyWithBaseClass)));
            Assert.That(result.ViolationOccured, Is.False);
        }
        public void Should_handle_loading_policy_from_container()
        {
            // Arrange
            var expectedPolicy = new PolicyWithConstructorArguments("arg1", "arg2", "arg3");

            FakeIoC.GetAllInstancesProvider = () => new List <object> {
                expectedPolicy
            };
            SecurityConfigurator.Configure(configuration =>
            {
                configuration.GetAuthenticationStatusFrom(() => true);
                configuration.ResolveServicesUsing(FakeIoC.GetAllInstances);
            });
            var lazySecurityPolicy = new LazySecurityPolicy <PolicyWithConstructorArguments>();

            // Act
            var policy = lazySecurityPolicy.Load();

            // Assert
            Assert.That(policy, Is.EqualTo(expectedPolicy));
        }
Esempio n. 13
0
        public void Should_retun_the_type_of_lazy_policies()
        {
            // Arrange
            ISecurityPolicy policy = new LazySecurityPolicy<IgnorePolicy>();

            // Act & assert
            Assert.That(policy.GetPolicyType(), Is.EqualTo(typeof(IgnorePolicy)));
        }