Ejemplo n.º 1
0
        public override void SetUp()
        {
            base.SetUp();

            _testHelper = new TestHelper();
            _extension  = new SecurityClientTransactionExtension();

            _propertyInfo             = typeof(SecurableObject).GetProperty("StringProperty");
            _getMethodInformation     = MethodInfoAdapter.Create(_propertyInfo.GetGetMethod());
            _stringPropertyDefinition = PropertyDefinitionObjectMother.CreatePropertyDefinition(_propertyInfo);

            _testHelper.SetupSecurityIoCConfiguration();
        }
Ejemplo n.º 2
0
        public void Test_WithNonSecurableObject_DoesNotPerformSecurityCheck()
        {
            var propertyInfo = typeof(NonSecurableObject).GetProperty("StringProperty");
            NonSecurableObject nonSecurableObject = _testHelper.CreateNonSecurableObject();

            _testHelper.ReplayAll();

            _extension.PropertyValueReading(
                _testHelper.Transaction,
                nonSecurableObject,
                PropertyDefinitionObjectMother.CreatePropertyDefinition(propertyInfo, typeof(NonSecurableObject)),
                ValueAccess.Current);

            _testHelper.VerifyAll();
        }
Ejemplo n.º 3
0
        public void Test_AccessDenied_WithMissingAccessor_ThrowsPermissionDeniedException()
        {
            var             propertyInfo    = typeof(SecurableObject).GetProperty("PropertyWithMissingGetAccessor");
            SecurableObject securableObject = _testHelper.CreateSecurableObject();

            _testHelper.ExpectPermissionReflectorGetRequiredMethodPermissions(new NullMethodInformation());
            _testHelper.ExpectObjectSecurityStrategyHasAccess(securableObject, GeneralAccessTypes.Read, false);
            _testHelper.ReplayAll();

            _extension.PropertyValueReading(
                _testHelper.Transaction,
                securableObject,
                PropertyDefinitionObjectMother.CreatePropertyDefinition(propertyInfo),
                ValueAccess.Current);
        }
Ejemplo n.º 4
0
        public void Test_AccessDenied_WithNonPublicAccessor_ThrowsPermissionDeniedException()
        {
            var propertyInfo =
                typeof(SecurableObject).GetProperty("NonPublicPropertyWithCustomPermission", BindingFlags.NonPublic | BindingFlags.Instance);
            var             getMethodInformation = MethodInfoAdapter.Create(propertyInfo.GetGetMethod(true));
            SecurableObject securableObject      = _testHelper.CreateSecurableObject();

            _testHelper.ExpectPermissionReflectorGetRequiredMethodPermissions(getMethodInformation, TestAccessTypes.First);
            _testHelper.ExpectObjectSecurityStrategyHasAccess(securableObject, TestAccessTypes.First, false);
            _testHelper.ReplayAll();

            _extension.PropertyValueReading(
                _testHelper.Transaction,
                securableObject,
                PropertyDefinitionObjectMother.CreatePropertyDefinition(propertyInfo),
                ValueAccess.Current);
        }
Ejemplo n.º 5
0
        public void Test_AccessGranted_WithMissingAccessor_DowsNotThrow()
        {
            var             propertyInfo    = typeof(SecurableObject).GetProperty("PropertyWithMissingSetAccessor");
            SecurableObject securableObject = _testHelper.CreateSecurableObject();

            _testHelper.ExpectPermissionReflectorGetRequiredMethodPermissions(new NullMethodInformation());
            _testHelper.ExpectObjectSecurityStrategyHasAccess(securableObject, GeneralAccessTypes.Edit, true);
            _testHelper.ReplayAll();

            _extension.PropertyValueChanging(
                _testHelper.Transaction,
                securableObject,
                PropertyDefinitionObjectMother.CreatePropertyDefinition(propertyInfo),
                "old",
                "new");

            _testHelper.VerifyAll();
        }
Ejemplo n.º 6
0
        public void Test_AccessGranted_WithNonPublicAccessor_DowsNotThrow()
        {
            var propertyInfo =
                typeof(SecurableObject).GetProperty("NonPublicPropertyWithCustomPermission", BindingFlags.NonPublic | BindingFlags.Instance);
            var             setMethodInformation = MethodInfoAdapter.Create(propertyInfo.GetSetMethod(true));
            SecurableObject securableObject      = _testHelper.CreateSecurableObject();

            _testHelper.ExpectPermissionReflectorGetRequiredMethodPermissions(setMethodInformation, TestAccessTypes.First);
            _testHelper.ExpectObjectSecurityStrategyHasAccess(securableObject, TestAccessTypes.First, true);
            _testHelper.ReplayAll();

            _extension.PropertyValueChanging(
                _testHelper.Transaction,
                securableObject,
                PropertyDefinitionObjectMother.CreatePropertyDefinition(propertyInfo),
                "old",
                "new");

            _testHelper.VerifyAll();
        }