Example #1
0
        public void TestFromFunctionWithoutParameters()
        {
            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithoutParameters),
                _attribute);

            helper.GetTypeOfSecurableObject();
        }
Example #2
0
        public void TestWithDefaultParameter()
        {
            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObject),
                _attribute);

            Assert.That(helper.GetTypeOfSecurableObject(), Is.SameAs(typeof(SecurableObject)));
        }
        public void TestWithInvalidFunctionType()
        {
            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObject),
                _attribute);

            helper.GetSecurableObject(new TestFunctionWithoutPermissions());
        }
Example #4
0
        public void TestWithParameterTypeIsBaseType()
        {
            WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute("ShowSpecial", typeof(DerivedSecurableObject));
            WxeDemandMethodPermissionAttributeHelper helper    = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObject),
                attribute);

            Assert.That(helper.GetTypeOfSecurableObject(), Is.SameAs(typeof(DerivedSecurableObject)));
        }
Example #5
0
        public void TestWithValidParameterName()
        {
            _attribute.ParameterName = "ThisObject";

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObjectAsSecondParameter),
                _attribute);

            Assert.That(helper.GetTypeOfSecurableObject(), Is.SameAs(typeof(SecurableObject)));
        }
Example #6
0
        public void TestWithInvalidParameterName()
        {
            _attribute.ParameterName = "Invalid";

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObjectAsSecondParameter),
                _attribute);

            helper.GetTypeOfSecurableObject();
        }
Example #7
0
        public void TestWithParameterNotImplementingISecurableObject()
        {
            _attribute.ParameterName = "SomeObject";

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObjectAsSecondParameter),
                _attribute);

            helper.GetTypeOfSecurableObject();
        }
        public void TestWithParameterNull()
        {
            _attribute.ParameterName = "ThisObject";
            TestFunctionWithThisObject function = new TestFunctionWithThisObject(null, null);

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                function.GetType(),
                _attribute);

            helper.GetSecurableObject(function);
        }
Example #9
0
        public void TestWithParameterNotOfNotMatchingType()
        {
            WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute("Show", typeof(OtherSecurableObject));

            attribute.ParameterName = "ThisObject";
            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObjectAsSecondParameter),
                attribute);

            helper.GetTypeOfSecurableObject();
        }
Example #10
0
        public void TestWithHandle_PointingToSecurableObjectBase_ShouldReturnTypeDeclaredInInterface()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(DerivedSecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);

            var result = helper.GetTypeOfSecurableObject();

            Assert.That(result, Is.SameAs(typeof(DerivedSecurableObject)));
        }
Example #11
0
        public void TestWithHandle_InheritingHandleAttribute()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(SecurableObject))
            {
                ParameterName = "HandleInheritingAttribute"
            };
            var helper = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);

            var result = helper.GetTypeOfSecurableObject();

            Assert.That(result, Is.SameAs(typeof(SecurableObject)));
        }
Example #12
0
        public void InitializeWithMethodTypeStaticAndMethodEnum()
        {
            WxeDemandTargetStaticMethodPermissionAttribute attribute = new WxeDemandTargetStaticMethodPermissionAttribute(SecurableObject.Method.Search);

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObject),
                attribute);

            Assert.That(helper.FunctionType, Is.SameAs(typeof(TestFunctionWithThisObject)));
            Assert.That(helper.MethodType, Is.EqualTo(MethodType.Static));
            Assert.That(helper.SecurableClass, Is.SameAs(typeof(SecurableObject)));
            Assert.That(helper.MethodName, Is.EqualTo("Search"));
        }
Example #13
0
        public void InitializeWithMethodTypeConstructor()
        {
            WxeDemandTargetPermissionAttribute attribute = new WxeDemandCreatePermissionAttribute(typeof(SecurableObject));

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObject),
                attribute);

            Assert.That(helper.FunctionType, Is.SameAs(typeof(TestFunctionWithThisObject)));
            Assert.That(helper.MethodType, Is.EqualTo(MethodType.Constructor));
            Assert.That(helper.SecurableClass, Is.SameAs(typeof(SecurableObject)));
            Assert.That(helper.MethodName, Is.Null);
        }
Example #14
0
        public void InitializeWithMethodTypeInstanceAndSecurableClass()
        {
            WxeDemandTargetMethodPermissionAttribute attribute = new WxeDemandTargetMethodPermissionAttribute("ShowSpecial", typeof(DerivedSecurableObject));

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                typeof(TestFunctionWithThisObject),
                attribute);

            Assert.That(helper.FunctionType, Is.SameAs(typeof(TestFunctionWithThisObject)));
            Assert.That(helper.MethodType, Is.EqualTo(MethodType.Instance));
            Assert.That(helper.SecurableClass, Is.SameAs(typeof(DerivedSecurableObject)));
            Assert.That(helper.MethodName, Is.EqualTo("ShowSpecial"));
        }
        public void TestWithDefaultParameter()
        {
            TestFunctionWithThisObject function = new TestFunctionWithThisObject(_securableObject, null);

            function.ThisObject = _securableObject; // Required because in this test the WxeFunction has not started executing.

            _attribute.ParameterName = null;

            WxeDemandMethodPermissionAttributeHelper helper = new WxeDemandMethodPermissionAttributeHelper(
                function.GetType(),
                _attribute);

            Assert.That(helper.GetSecurableObject(function), Is.SameAs(function.ThisObject));
        }
Example #16
0
        public void TestWithHandle_PointingToNonSecurableObject_ShouldThrow()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(SecurableObject))
            {
                ParameterName = "HandleWithNonSecurableObject"
            };
            var helper = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);

            Assert.That(
                () => helper.GetTypeOfSecurableObject(),
                Throws.TypeOf <WxeException>().With.Message.EqualTo(
                    "The parameter 'HandleWithNonSecurableObject' specified by the WxeDemandTargetMethodPermissionAttribute applied to WxeFunction "
                    + "'Remotion.Web.UnitTests.Core.Security.ExecutionEngine.TestFunctionWithHandleParameter' does not implement interface "
                    + "'Remotion.Security.ISecurableObject'."));
        }
        public void TestWithHandle_PointingToSecurableObject_ShouldReturnValue()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(SecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper   = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);
            var function = new TestFunctionWithHandleParameter {
                HandleWithSecurableObject = new Handle <SecurableObject> (_securableObject)
            };

            var result = helper.GetSecurableObject(function);

            Assert.That(result, Is.SameAs(_securableObject));
        }
Example #18
0
        public void TestWithHandle_ReferencedTypeNotMatchingSecurableClass_ShouldThrow()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(OtherSecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);

            Assert.That(
                () => helper.GetTypeOfSecurableObject(),
                Throws.TypeOf <WxeException> ().With.Message.EqualTo(
                    "The parameter 'HandleWithSecurableObject' specified by the WxeDemandTargetMethodPermissionAttribute applied to WxeFunction "
                    + "'Remotion.Web.UnitTests.Core.Security.ExecutionEngine.TestFunctionWithHandleParameter' is of type "
                    + "'Remotion.Web.UnitTests.Core.Security.Domain.SecurableObject', which is not a base type of type "
                    + "'Remotion.Web.UnitTests.Core.Security.Domain.OtherSecurableObject'."));
        }
        public void TestWithHandle_NullHandle_ShouldThrow()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(SecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper   = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);
            var function = new TestFunctionWithHandleParameter {
                HandleWithSecurableObject = null
            };

            Assert.That(
                () => helper.GetSecurableObject(function),
                Throws.TypeOf <WxeException> ().With.Message.EqualTo(
                    "The parameter 'HandleWithSecurableObject' specified by the WxeDemandTargetMethodPermissionAttribute applied to WxeFunction "
                    + "'Remotion.Web.UnitTests.Core.Security.ExecutionEngine.TestFunctionWithHandleParameter' is null."));
        }
        public void TestWithHandle_PointingToSecurableObject_ButIncompatibleParameterDeclaration_ShouldThrow()
        {
            var attribute = new WxeDemandTargetMethodPermissionAttribute("Some method", typeof(OtherSecurableObject))
            {
                ParameterName = "HandleWithSecurableObject"
            };
            var helper   = new WxeDemandMethodPermissionAttributeHelper(typeof(TestFunctionWithHandleParameter), attribute);
            var function = new TestFunctionWithHandleParameter {
                HandleWithSecurableObject = new Handle <SecurableObject> (_securableObject)
            };

            Assert.That(
                () => helper.GetSecurableObject(function),
                Throws.TypeOf <WxeException>().With.Message.EqualTo(
                    "The parameter 'HandleWithSecurableObject' specified by the WxeDemandTargetMethodPermissionAttribute applied to WxeFunction "
                    + "'Remotion.Web.UnitTests.Core.Security.ExecutionEngine.TestFunctionWithHandleParameter' is of type "
                    + "'Remotion.Web.UnitTests.Core.Security.Domain.SecurableObject', which is not a base type of type "
                    + "'Remotion.Web.UnitTests.Core.Security.Domain.OtherSecurableObject'."));
        }