상속: ISerializable, IBuiltInEvidence
예제 #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 static void HashCallMethods()
 {
     Hash hash = new Hash(Reflection.Assembly.Load(new Reflection.AssemblyName("System.Reflection")));
     byte[] barr = hash.GenerateHash(Cryptography.SHA1.Create());
     string str = hash.ToString();
     hash = Hash.CreateMD5(new byte[1]);
     hash = Hash.CreateSHA1(new byte[1]);
 }
		public void FixtureSetUp () 
		{
			Assembly a = Assembly.GetExecutingAssembly ();
			hashEvidence = new Hash (a);

			md5 = MD5.Create ();
			digestMd5 = hashEvidence.GenerateHash (md5);

			sha1 = SHA1.Create ();
			digestSha1 = hashEvidence.GenerateHash (sha1);
		}
예제 #4
0
파일: HashTest.cs 프로젝트: nlhepler/mono
		[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
		public void GenerateHash_SHA512 ()
		{
			Hash h = new Hash (wellKnownAssembly);
			byte[] result = h.GenerateHash (SHA512.Create ());
			Assert.AreEqual ("C0-05-76-29-F9-E7-32-A9-8D-73-4B-90-12-6A-85-3F-5C-D3-5B-EF-A6-F2-A6-15-38-9C-22-FA-7E-72-CA-10-B0-21-E0-B6-0B-B8-AB-9E-0E-9F-64-0E-C6-F3-48-96-01-7B-A6-20-07-2F-03-6A-51-03-0F-3F-C4-70-B3-0F", BitConverter.ToString (result));
		}
예제 #5
0
파일: HashTest.cs 프로젝트: nlhepler/mono
		[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
		public void GenerateHash_SHA384 ()
		{
			Hash h = new Hash (wellKnownAssembly);
			byte[] result = h.GenerateHash (SHA384.Create ());
			Assert.AreEqual ("23-58-E8-A2-61-B0-9E-0D-86-B1-C7-69-55-D4-52-18-5F-F8-8E-41-C1-94-B6-9B-2D-6A-6D-7F-86-9A-7F-BB-86-55-D4-BF-04-0C-B9-84-A5-52-35-9E-BC-CA-62-BC", BitConverter.ToString (result));
		}
예제 #6
0
파일: HashTest.cs 프로젝트: nlhepler/mono
		[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
		public void GenerateHash_SHA256 ()
		{
			Hash h = new Hash (wellKnownAssembly);
			byte[] result = h.GenerateHash (SHA256.Create ());
			Assert.AreEqual ("A1-3E-D6-44-BF-1D-B2-22-5D-34-53-14-E5-26-94-78-0A-4E-D0-C2-0F-9D-BA-3D-7C-67-61-3B-3A-17-CD-B0", BitConverter.ToString (result));
		}
예제 #7
0
파일: HashTest.cs 프로젝트: nlhepler/mono
		[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
		public void GenerateHash_SHA1 ()
		{
			Hash h = new Hash (wellKnownAssembly);
			byte[] result = h.GenerateHash (SHA1.Create ());
			Assert.AreEqual ("68-28-89-F6-D8-D4-9F-AF-FD-00-90-EF-5A-BA-C9-ED-2C-08-A6-F5", BitConverter.ToString (result));
		}
예제 #8
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;
        }
예제 #9
0
파일: caspol.cs 프로젝트: Anjoli/mono
		// -hash algo -hex hash
		// -hash algo -file assemblyname
		static IMembershipCondition ProcessHashMembership (string[] args, ref int i)
		{
			HashAlgorithm ha = HashAlgorithm.Create (args [++i]);
			byte [] value = null;
			switch (args [++i]) {
				case "-hex":
					value = CryptoConvert.FromHex (args [++i]);
					break;
				case "-file":
					Hash hash = new Hash (GetAssembly (args [++i]));
					value = hash.GenerateHash (ha);
					break;
				default:
					return null;
			}
			return new HashMembershipCondition (ha, value);
		}
예제 #10
0
파일: Hash.cs 프로젝트: runefs/Marvin
	static public Hash CreateSHA1 (byte[] sha1)
	{
		if (sha1 == null)
			throw new ArgumentNullException ("sha1");
		Hash h = new Hash ();
		h._sha1 = sha1;
		return h;
	}
예제 #11
0
        /// <summary>
        ///     Create a copy of some hash evidence
        /// </summary>
        private Hash(Hash hash)
        {
            Contract.Assert(hash != null);

            m_assembly = hash.m_assembly;
            m_rawData = hash.m_rawData;
            m_hashes = new Dictionary<Type, byte[]>(hash.m_hashes);
        }
 private Hash(Hash hash)
 {
     this.m_assembly = hash.m_assembly;
     this.m_rawData = hash.m_rawData;
     this.m_hashes = new Dictionary<Type, byte[]>(hash.m_hashes);
 }
예제 #13
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;
		}
예제 #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
파일: HashTest.cs 프로젝트: nlhepler/mono
		public void GenerateHash_RIPEMD160 ()
		{
			Hash h = new Hash (wellKnownAssembly);
			byte[] result = h.GenerateHash (RIPEMD160.Create ());
			Assert.AreEqual ("29-5A-21-11-BC-CA-1B-26-A2-46-F2-48-B4-61-96-1C-A5-2C-9A-9A", BitConverter.ToString (result));
		}
예제 #16
0
파일: HashTest.cs 프로젝트: nlhepler/mono
		[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
		public void MD5_Property ()
		{
			Hash h = new Hash (wellKnownAssembly);
			Assert.AreEqual ("D0-C6-1F-66-C8-49-9F-C8-BE-63-89-9D-C5-FC-4F-D4", BitConverter.ToString (h.MD5), "MD5");
		}
예제 #17
0
파일: Hash.cs 프로젝트: runefs/Marvin
	static public Hash CreateMD5 (byte[] md5)
	{
		if (md5 == null)
			throw new ArgumentNullException ("md5");
		Hash h = new Hash ();
		h._md5 = md5;
		return h;
	}
예제 #18
0
파일: HashTest.cs 프로젝트: nlhepler/mono
		[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
		public void SHA1_Property ()
		{
			Hash h = new Hash (wellKnownAssembly);
			Assert.AreEqual ("68-28-89-F6-D8-D4-9F-AF-FD-00-90-EF-5A-BA-C9-ED-2C-08-A6-F5", BitConverter.ToString (h.SHA1), "SHA1");
		}
예제 #19
0
		public void Hash_GetRequiredSize ()
		{
			Hash h = new Hash (Assembly.GetExecutingAssembly ());
			Assert.AreEqual (5, GetRequiredSize (h, true), "GetRequiredSize-true");
			Assert.AreEqual (0, GetRequiredSize (h, false), "GetRequiredSize-false");
		}
예제 #20
0
파일: HashTest.cs 프로젝트: nlhepler/mono
		[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
		public void GenerateHash_MD5 ()
		{
			Hash h = new Hash (wellKnownAssembly);
			byte[] result = h.GenerateHash (MD5.Create ());
			Assert.AreEqual ("D0-C6-1F-66-C8-49-9F-C8-BE-63-89-9D-C5-FC-4F-D4", BitConverter.ToString (result), "GenerateHash");
		}
예제 #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
        /// <summary>
        /// Generates a unique ETag which changes when the assembly changes
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        protected override object GetMetaData(out bool isHash)
        {
            if (this.Assembly == null)
            {
                throw new NullReferenceException("ETag cannot be created for null Assembly");
            }

            if (String.IsNullOrEmpty(this.ResourceName))
            {
                throw new NullReferenceException("ETag cannot be created for empty ResourceName");
            }

            isHash = true;
            Hash hash = new Hash(this.Assembly);
            return hash.SHA1;
        }