상속: System.Security.Policy.EvidenceBase, System.Security.Policy.IIdentityPermissionFactory
예제 #1
0
        /// <summary>
        /// Construct an application domain for running a test package
        /// </summary>
        /// <param name="package">The TestPackage to be run</param>
        public AppDomain CreateDomain( TestPackage package )
        {
            AppDomainSetup setup = CreateAppDomainSetup(package);

            string domainName = "test-domain-" + package.Name;
            // Setup the Evidence
            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
            if (evidence.Count == 0)
            {
                Zone zone = new Zone(SecurityZone.MyComputer);
                evidence.AddHost(zone);
                Assembly assembly = Assembly.GetExecutingAssembly();
                Url url = new Url(assembly.CodeBase);
                evidence.AddHost(url);
                Hash hash = new Hash(assembly);
                evidence.AddHost(hash);
            }

            log.Info("Creating AppDomain " + domainName);

            AppDomain runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);

            // Set PrincipalPolicy for the domain if called for in the settings
            if (_settingsService != null && _settingsService.GetSetting("Options.TestLoader.SetPrincipalPolicy", false))
            {
                runnerDomain.SetPrincipalPolicy(_settingsService.GetSetting(
                    "Options.TestLoader.PrincipalPolicy", 
                    PrincipalPolicy.UnauthenticatedPrincipal));
            }

            return runnerDomain;
        }
예제 #2
0
 public SecurityException(string message, AssemblyName assemblyName, PermissionSet grant, PermissionSet refused, MethodInfo method, SecurityAction action, object demanded, IPermission permThatFailed, Evidence evidence)
     : base(message)
 {
     PermissionSet.s_fullTrust.Assert();
     this.SetErrorCode(-2146233078);
     this.Action = action;
     if (permThatFailed != null)
     {
         this.m_typeOfPermissionThatFailed = permThatFailed.GetType();
     }
     this.FirstPermissionThatFailed = permThatFailed;
     this.Demanded       = demanded;
     this.m_granted      = grant == null ? "" : grant.ToXml().ToString();
     this.m_refused      = refused == null ? "" : refused.ToXml().ToString();
     this.m_denied       = "";
     this.m_permitOnly   = "";
     this.m_assemblyName = assemblyName;
     this.Method         = method;
     this.m_url          = "";
     this.m_zone         = SecurityZone.NoZone;
     if (evidence != null)
     {
         System.Security.Policy.Url hostEvidence1 = evidence.GetHostEvidence <System.Security.Policy.Url>();
         if (hostEvidence1 != null)
         {
             this.m_url = hostEvidence1.GetURLString().ToString();
         }
         System.Security.Policy.Zone hostEvidence2 = evidence.GetHostEvidence <System.Security.Policy.Zone>();
         if (hostEvidence2 != null)
         {
             this.m_zone = hostEvidence2.SecurityZone;
         }
     }
     this.m_debugString = this.ToString(true, false);
 }
예제 #3
0
파일: Zone.cs 프로젝트: ChuangYang/coreclr
        private Zone(Zone zone)
        {
            Contract.Assert(zone != null);

#if FEATURE_CAS_POLICY
            m_url = zone.m_url;
#endif // FEATURE_CAS_POLICY
            m_zone = zone.m_zone;
        }
예제 #4
0
        /// <summary>
        /// Construct an application domain for running a test package
        /// </summary>
        /// <param name="package">The TestPackage to be run</param>
        public AppDomain CreateDomain( TestPackage package )
        {
            AppDomainSetup setup = CreateAppDomainSetup(package);

            string domainName = "test-domain-" + package.Name;
            // Setup the Evidence
            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
            if (evidence.Count == 0)
            {
                Zone zone = new Zone(SecurityZone.MyComputer);
                evidence.AddHost(zone);
                Assembly assembly = Assembly.GetExecutingAssembly();
                Url url = new Url(assembly.CodeBase);
                evidence.AddHost(url);
                Hash hash = new Hash(assembly);
                evidence.AddHost(hash);
            }

            log.Info("Creating AppDomain " + domainName);

            AppDomain runnerDomain;
            
            // TODO: Find an approach that works across all platforms
          
            //// TODO: Try to eliminate this test. Currently, running on
            //// Linux with the permission set specified causes an
            //// unexplained crash when unloading the domain.
            //if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            //{
            //    PermissionSet permissionSet = new PermissionSet( PermissionState.Unrestricted );	
            //    runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup, permissionSet, null);
            //}
            //else
                runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);
            
            // Set PrincipalPolicy for the domain if called for in the settings
                if (ServiceContext.UserSettings.GetSetting("Options.TestLoader.SetPrincipalPolicy", false))
                    runnerDomain.SetPrincipalPolicy((PrincipalPolicy)ServiceContext.UserSettings.GetSetting(
                    "Options.TestLoader.PrincipalPolicy", PrincipalPolicy.UnauthenticatedPrincipal));

            //// HACK: Only pass down our AddinRegistry one level so that tests of NUnit
            //// itself start without any addins defined.
            //if ( !IsTestDomain( AppDomain.CurrentDomain ) )
            //    runnerDomain.SetData("AddinRegistry", Services.AddinRegistry);

            //// Inject DomainInitializer into the remote domain - there are other
            //// approaches, but this works for all CLR versions.
            //DomainInitializer initializer = DomainInitializer.CreateInstance(runnerDomain);

            //// HACK: Under nunit-console, direct use of the enum fails
            //int traceLevel = IsTestDomain(AppDomain.CurrentDomain)
            //    ? (int)InternalTraceLevel.Off : (int)InternalTrace.Level;

            //initializer.InitializeDomain(traceLevel);

            return runnerDomain;
        }
예제 #5
0
		public void Trusted () 
		{
			Zone z = new Zone (SecurityZone.Trusted);
			AssertEquals ("Trusted.SecurityZone", SecurityZone.Trusted, z.SecurityZone);
			Assert ("Trusted.ToString", (z.ToString ().IndexOf ("<Zone>Trusted</Zone>") >= 0));
			Zone zc = (Zone) z.Copy ();
			Assert ("Trusted.Copy.Equals", z.Equals (zc));
			IPermission p = z.CreateIdentityPermission (null);
			AssertNotNull ("Trusted.CreateIdentityPermission", p);

			Assert ("Trusted.MyComputer.Equals", !z.Equals (new Zone (SecurityZone.MyComputer)));
			Assert ("Trusted.Intranet.Equals", !z.Equals (new Zone (SecurityZone.Intranet)));
			Assert ("Trusted.Trusted.Equals", z.Equals (new Zone (SecurityZone.Trusted)));
			Assert ("Trusted.Internet.Equals", !z.Equals (new Zone (SecurityZone.Internet)));
			Assert ("Trusted.Untrusted.Equals", !z.Equals (new Zone (SecurityZone.Untrusted)));
			Assert ("Trusted.NoZone.Equals", !z.Equals (new Zone (SecurityZone.NoZone)));
			Assert ("Trusted.Null.Equals", !z.Equals (null));
		}
예제 #6
0
		public void Trusted () 
		{
			Zone z = new Zone (SecurityZone.Trusted);
			Assert.AreEqual (SecurityZone.Trusted, z.SecurityZone, "Trusted.SecurityZone");
			Assert.IsTrue ((z.ToString ().IndexOf ("<Zone>Trusted</Zone>") >= 0), "Trusted.ToString");
			Zone zc = (Zone) z.Copy ();
			Assert.IsTrue (z.Equals (zc), "Trusted.Copy.Equals");
			IPermission p = z.CreateIdentityPermission (null);
			Assert.IsNotNull (p, "Trusted.CreateIdentityPermission");

			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.MyComputer)), "Trusted.MyComputer.Equals");
			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.Intranet)), "Trusted.Intranet.Equals");
			Assert.IsTrue (z.Equals (new Zone (SecurityZone.Trusted)), "Trusted.Trusted.Equals");
			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.Internet)), "Trusted.Internet.Equals");
			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.Untrusted)), "Trusted.Untrusted.Equals");
			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.NoZone)), "Trusted.NoZone.Equals");
			Assert.IsTrue (!z.Equals (null), "Trusted.Null.Equals");
		}
 private void GenerateLocationEvidence()
 {
     if (!this.m_generatedLocationEvidence)
     {
         SecurityZone noZone = SecurityZone.NoZone;
         string s = null;
         GetLocationEvidence(this.m_peFile, out noZone, JitHelpers.GetStringHandleOnStack(ref s));
         if (noZone != SecurityZone.NoZone)
         {
             this.m_zoneEvidence = new Zone(noZone);
         }
         if (!string.IsNullOrEmpty(s))
         {
             this.m_urlEvidence = new Url(s, true);
             if (!s.StartsWith("file:", StringComparison.OrdinalIgnoreCase))
             {
                 this.m_siteEvidence = Site.CreateFromUrl(s);
             }
         }
         this.m_generatedLocationEvidence = true;
     }
 }
 private Zone(Zone zone)
 {
     this.m_url = zone.m_url;
     this.m_zone = zone.m_zone;
 }
        private void GenerateLocationEvidence()
        {
            if (!m_generatedLocationEvidence)
            {
                SecurityZone securityZone = SecurityZone.NoZone;
                string url = null;
                GetLocationEvidence(m_peFile, out securityZone, JitHelpers.GetStringHandleOnStack(ref url));

                if (securityZone != SecurityZone.NoZone)
                {
                    m_zoneEvidence = new Zone(securityZone);
                }

                if (!String.IsNullOrEmpty(url))
                {
                    m_urlEvidence = new Url(url, true);

                    // We only create site evidence if the URL does not with file:
                    if (!url.StartsWith("file:", StringComparison.OrdinalIgnoreCase))
                    {
                        m_siteEvidence = Site.CreateFromUrl(url);
                    }
                }

                m_generatedLocationEvidence = true;
            }
        }
예제 #10
0
		public void NoZone () 
		{
			Zone z = new Zone (SecurityZone.NoZone);
			Assert.AreEqual (SecurityZone.NoZone, z.SecurityZone, "NoZone.SecurityZone");
			Assert.IsTrue ((z.ToString ().IndexOf ("<Zone>NoZone</Zone>") >= 0), "NoZone.ToString");
			Zone zc = (Zone) z.Copy ();
			Assert.IsTrue (z.Equals (zc), "NoZone.Copy.Equals");
			IPermission p = z.CreateIdentityPermission (null);
			Assert.IsNotNull (p, "NoZone.CreateIdentityPermission");
			// NoZone isn't added to the XML / string of permissions
			Assert.IsTrue (p.ToString ().IndexOf ("NoZone") < 0, "ToString!=NoZone");

			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.MyComputer)), "NoZone.MyComputer.Equals");
			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.Intranet)), "NoZone.Intranet.Equals");
			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.Trusted)), "NoZone.Trusted.Equals");
			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.Internet)), "NoZone.Internet.Equals");
			Assert.IsTrue (!z.Equals (new Zone (SecurityZone.Untrusted)), "NoZone.Untrusted.Equals");
			Assert.IsTrue (z.Equals (new Zone (SecurityZone.NoZone)), "NoZone.NoZone.Equals");
			Assert.IsTrue (!z.Equals (null), "NoZone.Null.Equals");
		}
예제 #11
0
파일: Dummy.cs 프로젝트: kumpera/mono
		public static void AddHostEvidence (this Evidence evidence, Zone zone)
		{
			throw new NotImplementedException ();
		}
예제 #12
0
파일: evidence.cs 프로젝트: ArildF/masters
        internal Evidence(char[] buffer)
        {
            int position = 0;
            while (position < buffer.Length)
            {
                switch (buffer[position++])
                {
                    case BuiltInEvidenceHelper.idApplicationDirectory:
                    {
                        IBuiltInEvidence ad = new ApplicationDirectory();
                        position = ad.InitFromBuffer(buffer, position);
                        AddAssembly(ad);
                        break;
                    }
                    case BuiltInEvidenceHelper.idStrongName:
                    {
                        IBuiltInEvidence sn = new StrongName();
                        position = sn.InitFromBuffer(buffer, position);
                        AddHost(sn);
                        break;
                    }
                    case BuiltInEvidenceHelper.idZone:
                    {
                        IBuiltInEvidence z = new Zone();
                        position = z.InitFromBuffer(buffer, position);
                        AddHost(z);
                        break;
                    }
                    case BuiltInEvidenceHelper.idUrl:
                    {
                        IBuiltInEvidence u = new Url();
                        position = u.InitFromBuffer(buffer, position);
                        AddHost(u);
                        break;
                    }
                    case BuiltInEvidenceHelper.idSite:
                    {
                        IBuiltInEvidence s = new Site();
                        position = s.InitFromBuffer(buffer, position);
                        AddHost(s);
                        break;
                    }
                    case BuiltInEvidenceHelper.idPermissionRequestEvidence:
                    {
                        IBuiltInEvidence pre = new PermissionRequestEvidence();
                        position = pre.InitFromBuffer(buffer, position);
                        AddHost(pre);
                        break;
                    }
                    default:
                        throw new SerializationException(Environment.GetResourceString("Serialization_UnableToFixup"));

                } // switch
            } // while
        }
예제 #13
0
파일: Zone.cs 프로젝트: shrah/coreclr
 private Zone(Zone zone)
 {
     Debug.Assert(zone != null);
     m_zone = zone.m_zone;
 }
예제 #14
0
        public AppDomain CreateDomain(TestPackage package)
        {
            AppDomainSetup info = new AppDomainSetup();
            info.ApplicationName = "Tests_" + Environment.TickCount;
            FileInfo fileInfo = string.IsNullOrEmpty(package.FullName) ? null : new FileInfo(package.FullName);
            string str = package.BasePath;
            string path2 = package.ConfigurationFile;
            string privateBinPath = package.PrivateBinPath;
            if (fileInfo != null)
            {
                if (string.IsNullOrEmpty(str))
                    str = fileInfo.DirectoryName;
                if (string.IsNullOrEmpty(path2))
                    path2 = this.CanLoadProject(fileInfo.Name) ? Path.GetFileNameWithoutExtension(fileInfo.Name) + ".config" : fileInfo.Name + ".config";
            }
            else if (string.IsNullOrEmpty(str))
                str = DomainManager.GetCommonAppBase(package.Assemblies);
            char ch = str[str.Length - 1];
            if (ch != Path.DirectorySeparatorChar && ch != Path.AltDirectorySeparatorChar)
                str = str + Path.DirectorySeparatorChar;
            info.ApplicationBase = str;
            info.ConfigurationFile = path2 == null ? null : Path.Combine(str, path2);
            if (package.AutoBinPath)
                privateBinPath = DomainManager.GetPrivateBinPath(str, package.Assemblies);
            info.PrivateBinPath = privateBinPath;
            if (package.GetSetting("ShadowCopyFiles", true))
            {
                info.ShadowCopyFiles = "true";
                info.ShadowCopyDirectories = str;
                info.CachePath = this.GetCachePath();
            }
            else
                info.ShadowCopyFiles = "false";
            string friendlyName = "test-domain-" + package.Name;
            Evidence securityInfo = new Evidence(AppDomain.CurrentDomain.Evidence);
            if (securityInfo.Count == 0)
            {
                Zone zone = new Zone(SecurityZone.MyComputer);
                securityInfo.AddHost(zone);
                Assembly executingAssembly = Assembly.GetExecutingAssembly();
                Url url = new Url(executingAssembly.CodeBase);
                securityInfo.AddHost(url);
                Hash hash = new Hash(executingAssembly);
                securityInfo.AddHost(hash);
            }

            AppDomain domain;
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                PermissionSet grantSet = new PermissionSet(PermissionState.Unrestricted);
                domain = AppDomain.CreateDomain(friendlyName, securityInfo, info, grantSet, null);
            }
            else
                domain = AppDomain.CreateDomain(friendlyName, securityInfo, info);
            if (Services.UserSettings.GetSetting("Options.TestLoader.SetPrincipalPolicy", false))
                domain.SetPrincipalPolicy((PrincipalPolicy)Services.UserSettings.GetSetting("Options.TestLoader.PrincipalPolicy", PrincipalPolicy.UnauthenticatedPrincipal));
            if (!this.IsTestDomain(AppDomain.CurrentDomain))
                domain.SetData("AddinRegistry", Services.AddinRegistry);
            DomainInitializer.CreateInstance(domain).InitializeDomain(this.IsTestDomain(AppDomain.CurrentDomain) ? 1 : (int)InternalTrace.Level);
            return domain;
        }
예제 #15
0
파일: Evidence.cs 프로젝트: weeble/mono
        static internal Evidence GetDefaultHostEvidence(Assembly a)
        {
            Evidence e     = new Evidence();
            string   aname = a.EscapedCodeBase;

            // by default all assembly have the Zone, Url and Hash evidences
            e.AddHost(Zone.CreateFromUrl(aname));
            e.AddHost(new Url(aname));
            e.AddHost(new Hash(a));

            // non local files (e.g. http://) also get a Site evidence
            if (String.Compare("FILE://", 0, aname, 0, 7, true, CultureInfo.InvariantCulture) != 0)
            {
                e.AddHost(Site.CreateFromUrl(aname));
            }

            // strongnamed assemblies gets a StrongName evidence
            AssemblyName an = a.UnprotectedGetName();

            byte[] pk = an.GetPublicKey();
            if ((pk != null) && (pk.Length > 0))
            {
                StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(pk);
                e.AddHost(new StrongName(blob, an.Name, an.Version));
            }

            // Authenticode(r) signed assemblies get a Publisher evidence
            if (IsAuthenticodePresent(a))
            {
                // Note: The certificate is part of the evidences even if it is not trusted!
                // so we can't call X509Certificate.CreateFromSignedFile
                AuthenticodeDeformatter ad = new AuthenticodeDeformatter(a.Location);
                if (ad.SigningCertificate != null)
                {
                    X509Certificate x509 = new X509Certificate(ad.SigningCertificate.RawData);
                    if (x509.GetHashCode() != 0)
                    {
                        e.AddHost(new Publisher(x509));
                    }
                }
            }
            // assemblies loaded from the GAC also get a Gac evidence (new in Fx 2.0)
            if (a.GlobalAssemblyCache)
            {
                e.AddHost(new GacInstalled());
            }

            // the current HostSecurityManager may add/remove some evidence
            AppDomainManager dommgr = AppDomain.CurrentDomain.DomainManager;

            if (dommgr != null)
            {
                if ((dommgr.HostSecurityManager.Flags & HostSecurityManagerOptions.HostAssemblyEvidence) ==
                    HostSecurityManagerOptions.HostAssemblyEvidence)
                {
                    e = dommgr.HostSecurityManager.ProvideAssemblyEvidence(a, e);
                }
            }

            return(e);
        }
예제 #16
0
        public Object Copy()
        {
            Zone z = new Zone();

            z.m_zone = m_zone;
            z.m_url = m_url;

            return z;
        }
예제 #17
0
		static Evidence CreateAssemblyEvidence(string fileName)
		{
			//HACK: I am unsure whether 'Hash' evidence is required - since this will be difficult to obtain, we will not supply it...
 
			Evidence newEvidence = new Evidence();

			//We must have zone evidence, or we will get a policy exception
			Zone zone = new Zone(SecurityZone.MyComputer);
			newEvidence.AddHost(zone);

			//If the assembly is strong-named, we must supply this evidence
			//for StrongNameIdentityPermission demands
			AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileName);
			byte[] pk = assemblyName.GetPublicKey();
			if (pk!=null && pk.Length != 0)
			{
				StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(pk);
				StrongName strongName = new StrongName(blob, assemblyName.Name, assemblyName.Version);
				newEvidence.AddHost(strongName);
			}

			return newEvidence;
		}
예제 #18
0
		/// <summary>
		/// Construct an application domain for running a test package
		/// </summary>
		/// <param name="package">The TestPackage to be run</param>
		public AppDomain CreateDomain( TestPackage package )
		{
			FileInfo testFile = new FileInfo( package.FullName );

			AppDomainSetup setup = new AppDomainSetup();
			 
			//For paralell tests, we need to use distinct application name
        	setup.ApplicationName = "Tests" + "_" + Environment.TickCount;
            //setup.ApplicationName = package.Name;

			string appBase = package.BasePath;
			if ( appBase == null || appBase == string.Empty )
				appBase = testFile.DirectoryName;
			setup.ApplicationBase = appBase;

			string configFile = package.ConfigurationFile;
			if ( configFile == null || configFile == string.Empty )
				configFile = NUnitProject.IsProjectFile(testFile.Name) 
					? Path.GetFileNameWithoutExtension( testFile.Name ) + ".config"
					: testFile.Name + ".config";
			// Note: Mono needs full path to config file...
			setup.ConfigurationFile =  Path.Combine( appBase, configFile );

			string binPath = package.PrivateBinPath;
			if ( package.AutoBinPath )
				binPath = GetPrivateBinPath( appBase, package.Assemblies );

			setup.PrivateBinPath = binPath;

            if (package.GetSetting("ShadowCopyFiles", true))
            {
                setup.ShadowCopyFiles = "true";
                setup.ShadowCopyDirectories = appBase;
                setup.CachePath = GetCachePath();
            }
            else
                setup.ShadowCopyFiles = "false";

			string domainName = "test-domain-" + package.Name;
            // Setup the Evidence
            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
            if (evidence.Count == 0)
            {
                Zone zone = new Zone(SecurityZone.MyComputer);
                evidence.AddHost(zone);
                Assembly assembly = Assembly.GetExecutingAssembly();
                Url url = new Url(assembly.CodeBase);
                evidence.AddHost(url);
                Hash hash = new Hash(assembly);
                evidence.AddHost(hash);
            }

            log.Info("Creating AppDomain " + domainName);

            AppDomain runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);

			// HACK: Only pass down our AddinRegistry one level so that tests of NUnit
			// itself start without any addins defined.
			if ( !IsTestDomain( AppDomain.CurrentDomain ) )
				runnerDomain.SetData("AddinRegistry", Services.AddinRegistry);

            // Inject DomainInitializer into the remote domain - there are other
            // approaches, but this works for all CLR versions.
            DomainInitializer initializer = DomainInitializer.CreateInstance(runnerDomain);
            initializer.InitializeDomain( IsTestDomain(AppDomain.CurrentDomain)
                ? TraceLevel.Off : InternalTrace.Level );

			return runnerDomain;
		}
예제 #19
0
		public void Zone_GetRequiredSize ()
		{
			Zone z = new Zone (SecurityZone.MyComputer);
			Assert.AreEqual (3, GetRequiredSize (z, true), "GetRequiredSize-true");
			Assert.AreEqual (3, GetRequiredSize (z, false), "GetRequiredSize-false");
		}
예제 #20
0
파일: Zone.cs 프로젝트: kouvel/coreclr
 private Zone(Zone zone)
 {
     Debug.Assert(zone != null);
     m_zone = zone.m_zone;
 }
예제 #21
0
		/// <summary>
		/// Construct an application domain for running a test package
		/// </summary>
		/// <param name="package">The TestPackage to be run</param>
		public AppDomain CreateDomain( TestPackage package )
		{
			AppDomainSetup setup = new AppDomainSetup();
			 
			//For paralell tests, we need to use distinct application name
        	setup.ApplicationName = "Tests" + "_" + Environment.TickCount;

            FileInfo testFile = package.FullName != null && package.FullName != string.Empty
                ? new FileInfo(package.FullName)
                : null;

            string appBase = package.BasePath;
            string configFile = package.ConfigurationFile;
            string binPath = package.PrivateBinPath;

            if (testFile != null)
            {
                if (appBase == null || appBase == string.Empty)
                    appBase = testFile.DirectoryName;

                if (configFile == null || configFile == string.Empty)
                    configFile = Services.ProjectService.CanLoadProject(testFile.Name)
                        ? Path.GetFileNameWithoutExtension(testFile.Name) + ".config"
                        : testFile.Name + ".config";
            }
            else if (appBase == null || appBase == string.Empty)
                appBase = GetCommonAppBase(package.Assemblies);

            setup.ApplicationBase = appBase;
            // TODO: Check whether Mono still needs full path to config file...
            setup.ConfigurationFile = appBase != null && configFile != null
                ? Path.Combine(appBase, configFile)
                : configFile;

            if (package.AutoBinPath)
				binPath = GetPrivateBinPath( appBase, package.Assemblies );

			setup.PrivateBinPath = binPath;

            if (package.GetSetting("ShadowCopyFiles", true))
            {
                setup.ShadowCopyFiles = "true";
                setup.ShadowCopyDirectories = appBase;
                setup.CachePath = GetCachePath();
            }
            else
                setup.ShadowCopyFiles = "false";

			string domainName = "test-domain-" + package.Name;
            // Setup the Evidence
            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
            if (evidence.Count == 0)
            {
                Zone zone = new Zone(SecurityZone.MyComputer);
                evidence.AddHost(zone);
                Assembly assembly = Assembly.GetExecutingAssembly();
                Url url = new Url(assembly.CodeBase);
                evidence.AddHost(url);
                Hash hash = new Hash(assembly);
                evidence.AddHost(hash);
            }

            log.Info("Creating AppDomain " + domainName);

			AppDomain runnerDomain;
			
			// TODO: Try to eliminate this test. Currently, running on
			// Linux with the permission set specified causes an
			// unexplained crash when unloading the domain.
#if NET_2_0
			if (Environment.OSVersion.Platform == PlatformID.Win32NT)
			{
            	PermissionSet permissionSet = new PermissionSet( PermissionState.Unrestricted );	
           		runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup, permissionSet, null);
			}
			else
#endif
            	runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);

			// HACK: Only pass down our AddinRegistry one level so that tests of NUnit
			// itself start without any addins defined.
			if ( !IsTestDomain( AppDomain.CurrentDomain ) )
				runnerDomain.SetData("AddinRegistry", Services.AddinRegistry);

            // Inject DomainInitializer into the remote domain - there are other
            // approaches, but this works for all CLR versions.
            DomainInitializer initializer = DomainInitializer.CreateInstance(runnerDomain);

            // HACK: Under nunit-console, direct use of the enum fails
            int traceLevel = IsTestDomain(AppDomain.CurrentDomain)
                ? (int)InternalTraceLevel.Off : (int)InternalTrace.Level;

            initializer.InitializeDomain(traceLevel);

			return runnerDomain;
		}
예제 #22
0
		public void NoZone () 
		{
			Zone z = new Zone (SecurityZone.NoZone);
			AssertEquals ("NoZone.SecurityZone", SecurityZone.NoZone, z.SecurityZone);
			Assert ("NoZone.ToString", (z.ToString ().IndexOf ("<Zone>NoZone</Zone>") >= 0));
			Zone zc = (Zone) z.Copy ();
			Assert ("NoZone.Copy.Equals", z.Equals (zc));
			IPermission p = z.CreateIdentityPermission (null);
			AssertNotNull ("NoZone.CreateIdentityPermission", p);
			// NoZone isn't added to the XML / string of permissions
			Assert ("ToString!=NoZone", p.ToString ().IndexOf ("NoZone") < 0);

			Assert ("NoZone.MyComputer.Equals", !z.Equals (new Zone (SecurityZone.MyComputer)));
			Assert ("NoZone.Intranet.Equals", !z.Equals (new Zone (SecurityZone.Intranet)));
			Assert ("NoZone.Trusted.Equals", !z.Equals (new Zone (SecurityZone.Trusted)));
			Assert ("NoZone.Internet.Equals", !z.Equals (new Zone (SecurityZone.Internet)));
			Assert ("NoZone.Untrusted.Equals", !z.Equals (new Zone (SecurityZone.Untrusted)));
			Assert ("NoZone.NoZone.Equals", z.Equals (new Zone (SecurityZone.NoZone)));
			Assert ("NoZone.Null.Equals", !z.Equals (null));
		}