protected override void Context()
 {
     // Arrange
     _denyAuthenticatedAccessPolicy = new DenyAuthenticatedAccessPolicy();
     _denyAnonymousAccessPolicy     = new DenyAnonymousAccessPolicy();
     Policies = new List <ISecurityPolicy>
     {
         _denyAuthenticatedAccessPolicy
     };
 }
 protected override void Context()
 {
     // Arrange
     _requireAllRolesPolicy     = new RequireAllRolesPolicy("Administrator");
     _denyAnonymousAccessPolicy = new DenyAnonymousAccessPolicy();
     Policies = new List <ISecurityPolicy>
     {
         _denyAnonymousAccessPolicy
     };
 }
Пример #3
0
        public override void SetUp()
        {
            base.SetUp();

            // Arrange
            _denyAuthenticatedAccessPolicy = new DenyAuthenticatedAccessPolicy();
            _denyAnonymousAccessPolicy     = new DenyAnonymousAccessPolicy();
            _policies = new List <ISecurityPolicy>
            {
                _denyAuthenticatedAccessPolicy
            };
        }
Пример #4
0
        public override void SetUp()
        {
            base.SetUp();

            // Arrange
            _requireAllRolesPolicy     = new RequireAllRolesPolicy("Administrator");
            _denyAnonymousAccessPolicy = new DenyAnonymousAccessPolicy();
            _policies = new List <ISecurityPolicy>
            {
                _denyAnonymousAccessPolicy
            };
        }
        public void Should_be_successful_when_the_user_is_authenticated()
        {
            // Arrange
            var        policy        = new DenyAnonymousAccessPolicy();
            const bool authenticated = true;
            var        context       = TestDataFactory.CreateSecurityContext(authenticated);

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

            // Assert
            Assert.That(result.ViolationOccured, Is.False);
        }
Пример #6
0
        public void Should_be_successful_and_have_no_message()
        {
            // Arrange
            var policy = new DenyAnonymousAccessPolicy();

            // Act
            var result = PolicyResult.CreateSuccessResult(policy);

            // Assert
            Assert.That(result.ViolationOccured, Is.False);
            Assert.That(result.Message, Is.Null);
            Assert.That(result.PolicyType, Is.EqualTo(policy.GetType()));
        }
        public void Should_not_be_successful_when_the_user_is_anonymous()
        {
            // Arrange
            var        policy        = new DenyAnonymousAccessPolicy();
            const bool authenticated = false;
            var        context       = TestDataFactory.CreateSecurityContext(authenticated);

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

            // Assert
            Assert.That(result.ViolationOccured, Is.True);
            Assert.That(result.Message, Is.EqualTo("Anonymous access denied"));
        }
Пример #8
0
        public void Should_be_unsuccessful_and_have_a_message()
        {
            // Arrange
            var message = "Failure";
            var policy  = new DenyAnonymousAccessPolicy();

            // Act
            var result = PolicyResult.CreateFailureResult(policy, message);

            // Assert
            Assert.That(result.ViolationOccured, Is.True);
            Assert.That(result.Message, Is.EqualTo(message));
            Assert.That(result.PolicyType, Is.EqualTo(policy.GetType()));
        }
Пример #9
0
        public void Should_have_PolicyResult_PolicyType_and_Message_set()
        {
            // Arrange
            var policy       = new DenyAnonymousAccessPolicy();
            var policyResult = PolicyResult.CreateFailureResult(policy, "Anonymous access denied");

            // Act
            var exception = new PolicyViolationException(policyResult);

            // Assert
            Assert.That(exception.PolicyResult, Is.EqualTo(policyResult));
            Assert.That(exception.PolicyType, Is.EqualTo(typeof(DenyAnonymousAccessPolicy)));
            Assert.That(exception.Message, Is.EqualTo("Anonymous access denied"));
        }
Пример #10
0
        public void Should_add_policy_to_policycontainers()
        {
            // Arrange
            var controllerName   = NameHelper.Controller <AdminController>();
            var policyContainers = new List <PolicyContainer>
            {
                TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
                TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
            };

            var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast <IPolicyContainerConfiguration>().ToList());
            var policy = new DenyAnonymousAccessPolicy();

            // Act
            conventionPolicyContainer.AddPolicy(policy);

            // Assert
            Assert.That(policyContainers[0].GetPolicies().First(), Is.EqualTo(policy));
            Assert.That(policyContainers[1].GetPolicies().First(), Is.EqualTo(policy));
            Assert.That(policyContainers[2].GetPolicies().First(), Is.EqualTo(policy));
        }