public void HostProtectionAttribute_Empty()
        {
            // note: normally security attributes don't have an empty constructor
            HostProtectionAttribute hpa = new HostProtectionAttribute();

            DefaultTests(hpa);
        }
        public void HostProtection()
        {
            HostProtectionAttribute hpa = new HostProtectionAttribute();
            // internal permission
            IPermission p = hpa.CreatePermission();

            Assert.AreEqual(9, GetTokenIndex(p));
        }
        public void MayLeakOnAbort()
        {
            HostProtectionAttribute a = Empty();

            a.MayLeakOnAbort = true;
            Assert.AreEqual(HostProtectionResource.MayLeakOnAbort, a.Resources, "Resources=MayLeakOnAbort");
            a.MayLeakOnAbort = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        public void UI()
        {
            HostProtectionAttribute a = Empty();

            a.UI = true;
            Assert.AreEqual(HostProtectionResource.UI, a.Resources, "Resources=UI");
            a.UI = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        public void SecurityInfrastructure()
        {
            HostProtectionAttribute a = Empty();

            a.SecurityInfrastructure = true;
            Assert.AreEqual(HostProtectionResource.SecurityInfrastructure, a.Resources, "Resources=SecurityInfrastructure");
            a.SecurityInfrastructure = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        public void SelfAffectingThreading()
        {
            HostProtectionAttribute a = Empty();

            a.SelfAffectingThreading = true;
            Assert.AreEqual(HostProtectionResource.SelfAffectingThreading, a.Resources, "Resources=SelfAffectingThreading");
            a.SelfAffectingThreading = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        public void SelfAffectingProcessMgmt()
        {
            HostProtectionAttribute a = Empty();

            a.SelfAffectingProcessMgmt = true;
            Assert.AreEqual(HostProtectionResource.SelfAffectingProcessMgmt, a.Resources, "Resources=SelfAffectingProcessMgmt");
            a.SelfAffectingProcessMgmt = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        public void ExternalProcessMgmt()
        {
            HostProtectionAttribute a = Empty();

            a.ExternalProcessMgmt = true;
            Assert.AreEqual(HostProtectionResource.ExternalProcessMgmt, a.Resources, "Resources=ExternalProcessMgmt");
            a.ExternalProcessMgmt = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        public void SharedState()
        {
            HostProtectionAttribute a = Empty();

            a.SharedState = true;
            Assert.AreEqual(HostProtectionResource.SharedState, a.Resources, "Resources=SharedState");
            a.SharedState = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        public void Synchronization()
        {
            HostProtectionAttribute a = Empty();

            a.Synchronization = true;
            Assert.AreEqual(HostProtectionResource.Synchronization, a.Resources, "Resources=Synchronization");
            a.Synchronization = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        public void ExternalThreading()
        {
            HostProtectionAttribute a = Empty();

            a.ExternalThreading = true;
            Assert.AreEqual(HostProtectionResource.ExternalThreading, a.Resources, "Resources=ExternalThreading");
            a.ExternalThreading = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
        }
        private HostProtectionAttribute Empty()
        {
            HostProtectionAttribute a = new HostProtectionAttribute();

            a.Synchronization          = false;
            a.SharedState              = false;
            a.ExternalProcessMgmt      = false;
            a.SelfAffectingProcessMgmt = false;
            a.ExternalThreading        = false;
            a.SelfAffectingThreading   = false;
            a.SecurityInfrastructure   = false;
            a.UI             = false;
            a.MayLeakOnAbort = false;
            Assert.AreEqual(HostProtectionResource.None, a.Resources, "Resources=None");
            return(a);
        }
Пример #13
0
        internal static TypeConverter GetConverter(Type type)
        {
            TypeConverter           converter;
            HostProtectionAttribute attribute = new HostProtectionAttribute {
                SharedState = true
            };

            ((CodeAccessPermission)attribute.CreatePermission()).Assert();
            try
            {
                converter = TypeDescriptor.GetConverter(type);
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            return(converter);
        }
        private void DefaultTests(HostProtectionAttribute hpa)
        {
            Assert.AreEqual(SecurityAction.LinkDemand, hpa.Action, "Action");
            Assert.AreEqual(HostProtectionResource.None, hpa.Resources, "Resources");
            Assert.IsFalse(hpa.ExternalProcessMgmt, "ExternalProcessMgmt");
            Assert.IsFalse(hpa.ExternalThreading, "ExternalThreading");
            Assert.IsFalse(hpa.MayLeakOnAbort, "MayLeakOnAbort");
            Assert.IsFalse(hpa.SecurityInfrastructure, "SecurityInfrastructure");
            Assert.IsFalse(hpa.SelfAffectingProcessMgmt, "SelfAffectingProcessMgmt");
            Assert.IsFalse(hpa.SelfAffectingThreading, "SelfAffectingThreading");
            Assert.IsFalse(hpa.SharedState, "SharedState");
            Assert.IsFalse(hpa.Synchronization, "Synchronization");
            Assert.IsFalse(hpa.UI, "UI");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted");
            IPermission p = hpa.CreatePermission();

            Assert.AreEqual("System.Security.Permissions.HostProtectionPermission", p.GetType().ToString(), "CreatePermission");
            Assert.IsTrue((p is IUnrestrictedPermission), "IUnrestrictedPermission");
        }
        public void Properties()
        {
            HostProtectionAttribute hpa      = new HostProtectionAttribute(SecurityAction.LinkDemand);
            HostProtectionResource  expected = HostProtectionResource.None;

            Assert.AreEqual(expected, hpa.Resources, "None");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-1");

            hpa.ExternalProcessMgmt = true;
            expected |= HostProtectionResource.ExternalProcessMgmt;
            Assert.AreEqual(expected, hpa.Resources, "+ExternalProcessMgmt");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-2");

            hpa.ExternalThreading = true;
            expected |= HostProtectionResource.ExternalThreading;
            Assert.AreEqual(expected, hpa.Resources, "+ExternalThreading");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-3");

            hpa.MayLeakOnAbort = true;
            expected          |= HostProtectionResource.MayLeakOnAbort;
            Assert.AreEqual(expected, hpa.Resources, "+MayLeakOnAbort");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-4");

            hpa.SecurityInfrastructure = true;
            expected |= HostProtectionResource.SecurityInfrastructure;
            Assert.AreEqual(expected, hpa.Resources, "+SecurityInfrastructure");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-5");

            hpa.SelfAffectingProcessMgmt = true;
            expected |= HostProtectionResource.SelfAffectingProcessMgmt;
            Assert.AreEqual(expected, hpa.Resources, "+SelfAffectingProcessMgmt");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-6");

            hpa.SelfAffectingThreading = true;
            expected |= HostProtectionResource.SelfAffectingThreading;
            Assert.AreEqual(expected, hpa.Resources, "+SelfAffectingThreading");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-7");

            hpa.SharedState = true;
            expected       |= HostProtectionResource.SharedState;
            Assert.AreEqual(expected, hpa.Resources, "+SharedState");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-8");

            hpa.Synchronization = true;
            expected           |= HostProtectionResource.Synchronization;
            Assert.AreEqual(expected, hpa.Resources, "+Synchronization");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-9");

            hpa.UI    = true;
            expected |= HostProtectionResource.UI;
            Assert.AreEqual(expected, hpa.Resources, "+UI");

            Assert.IsFalse(hpa.Unrestricted, "Unrestricted");

            hpa.ExternalProcessMgmt = false;
            expected &= ~HostProtectionResource.ExternalProcessMgmt;
            Assert.AreEqual(expected, hpa.Resources, "-ExternalProcessMgmt");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-10");

            hpa.ExternalThreading = false;
            expected &= ~HostProtectionResource.ExternalThreading;
            Assert.AreEqual(expected, hpa.Resources, "+ExternalThreading");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-11");

            hpa.MayLeakOnAbort = false;
            expected          &= ~HostProtectionResource.MayLeakOnAbort;
            Assert.AreEqual(expected, hpa.Resources, "+MayLeakOnAbort");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-12");

            hpa.SecurityInfrastructure = false;
            expected &= ~HostProtectionResource.SecurityInfrastructure;
            Assert.AreEqual(expected, hpa.Resources, "+SecurityInfrastructure");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-13");

            hpa.SelfAffectingProcessMgmt = false;
            expected &= ~HostProtectionResource.SelfAffectingProcessMgmt;
            Assert.AreEqual(expected, hpa.Resources, "+SelfAffectingProcessMgmt");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-14");

            hpa.SelfAffectingThreading = false;
            expected &= ~HostProtectionResource.SelfAffectingThreading;
            Assert.AreEqual(expected, hpa.Resources, "+SelfAffectingThreading");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-15");

            hpa.SharedState = false;
            expected       &= ~HostProtectionResource.SharedState;
            Assert.AreEqual(expected, hpa.Resources, "+SharedState");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-16");

            hpa.Synchronization = false;
            expected           &= ~HostProtectionResource.Synchronization;
            Assert.AreEqual(expected, hpa.Resources, "+Synchronization");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-17");

            hpa.UI    = false;
            expected &= ~HostProtectionResource.UI;
            Assert.AreEqual(expected, hpa.Resources, "+UI");
            Assert.IsFalse(hpa.Unrestricted, "Unrestricted-18");
        }
        public void HostProtectionAttribute_LinkDemand()
        {
            HostProtectionAttribute hpa = new HostProtectionAttribute(SecurityAction.LinkDemand);

            DefaultTests(hpa);
        }
Пример #17
0
 public static void HostProtectionAttributeCallMethods()
 {
     HostProtectionAttribute hpa = new HostProtectionAttribute();
     IPermission ip = hpa.CreatePermission();
 }
Пример #18
0
 public static void HostProtectionAttributeCallMethods()
 {
     HostProtectionAttribute hpa = new HostProtectionAttribute();
     IPermission             ip  = hpa.CreatePermission();
 }