Наследование: System.Security.Permissions.CodeAccessSecurityAttribute
Пример #1
0
        internal static TypeConverter GetConverter(Type type) { 
            HostProtectionAttribute protAttrib = new HostProtectionAttribute();
            protAttrib.SharedState = true;

            CodeAccessPermission permission = (CodeAccessPermission)protAttrib.CreatePermission();
            permission.Assert(); 
            try {
                return TypeDescriptor.GetConverter(type);
            }
            finally {
                CodeAccessPermission.RevertAssert(); 
            }
        }
 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;
 }
Пример #3
0
		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");
		}
Пример #4
0
		public void HostProtection ()
		{
			HostProtectionAttribute hpa = new HostProtectionAttribute ();
			// internal permission
			IPermission p = hpa.CreatePermission ();
			Assert.AreEqual (9, GetTokenIndex (p));
		}
Пример #5
0
		public void HostProtectionAttribute_Empty ()
		{
			// note: normally security attributes don't have an empty constructor
			HostProtectionAttribute hpa = new HostProtectionAttribute ();
			DefaultTests (hpa);
		}
Пример #6
0
		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");
		}
Пример #7
0
		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;
		}
Пример #8
0
		public void HostProtectionAttribute_LinkDemand ()
		{
			HostProtectionAttribute hpa = new HostProtectionAttribute (SecurityAction.LinkDemand);
			DefaultTests (hpa);
		}