AddAssembly() private method

private AddAssembly ( object id ) : void
id object
return void
		public void Check ()
		{
			ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
			Evidence e = null;
			Assert.IsFalse (ad.Check (e), "Check (null)");
			e = new Evidence ();
			Assert.IsFalse (ad.Check (e), "Check (empty)");
			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (ad.Check (e), "Check (zone)");

			string codebase = Assembly.GetExecutingAssembly ().CodeBase;
			Url u = new Url (codebase);
			ApplicationDirectory adir = new ApplicationDirectory (codebase);

			e.AddHost (u);
			Assert.IsFalse (ad.Check (e), "Check (url-host)"); // not enough
			e.AddAssembly (adir);
			Assert.IsFalse (ad.Check (e), "Check (url-host+adir-assembly)");

			e = new Evidence ();
			e.AddHost (adir);
			Assert.IsFalse (ad.Check (e), "Check (adir-host)"); // not enough
			e.AddAssembly (u);
			Assert.IsFalse (ad.Check (e), "Check (url-assembly+adir-host)");

			e = new Evidence ();
			e.AddHost (u);
			e.AddHost (adir);
			Assert.IsTrue (ad.Check (e), "Check (url+adir host)"); // both!!
		}
		public void Check ()
		{
			GacMembershipCondition gac = new GacMembershipCondition ();
			Evidence e = null;
			Assert.IsFalse (gac.Check (e), "Check (null)");
			e = new Evidence ();
			Assert.IsFalse (gac.Check (e), "Check (empty)");
			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (gac.Check (e), "Check (zone)");
			GacInstalled g = new GacInstalled ();
			e.AddAssembly (g);
			Assert.IsFalse (gac.Check (e), "Check (gac-assembly)");
			e.AddHost (g);
			Assert.IsTrue (gac.Check (e), "Check (gac-host)");
		}
		public void Check ()
		{
			AllMembershipCondition all = new AllMembershipCondition ();
			Evidence e = null;
			Assert.IsTrue (all.Check (e), "Check (null)");
			e = new Evidence ();
			Assert.IsTrue (all.Check (e), "Check (empty)");
			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsTrue (all.Check (e), "Check (zone)");
			Url u = new Url ("http://www.go-mono.com/");
			e.AddAssembly (u);
			Assert.IsTrue (all.Check (e), "Check (all-assembly)");
			Site s = new Site ("www.go-mono.com");
			e.AddHost (s);
			Assert.IsTrue (all.Check (e), "Check (all-host)");
		}
示例#4
0
        internal Evidence ShallowCopy()
        {
            Evidence evidence = new Evidence();

            IEnumerator enumerator;

            enumerator = this.GetHostEnumerator();

            while (enumerator.MoveNext())
            {
                evidence.AddHost(enumerator.Current);
            }

            enumerator = this.GetAssemblyEnumerator();

            while (enumerator.MoveNext())
            {
                evidence.AddAssembly(enumerator.Current);
            }

            return(evidence);
        }
示例#5
0
        private void DecodeSerializedEvidence( Evidence evidence,
                                               byte[] serializedEvidence )
        {
            MemoryStream ms = new MemoryStream( serializedEvidence );
            BinaryFormatter formatter = new BinaryFormatter();
                
            Evidence asmEvidence = null;
                
            PermissionSet permSet = new PermissionSet( false );
            permSet.SetPermission( new SecurityPermission( SecurityPermissionFlag.SerializationFormatter ) );
            permSet.PermitOnly();
            permSet.Assert();

            try
            {
                asmEvidence = (Evidence)formatter.Deserialize( ms );
            }
            catch (Exception)
            {
            }
                
            if (asmEvidence != null)
            {
                // Any evidence from the serialized input must:
                // 1. be placed in the assembly list since it is unverifiable.
                // 2. not be a built in class used as evidence (e.g. Zone, Site, URL, etc.)
                    
                IEnumerator enumerator = asmEvidence.GetAssemblyEnumerator();
                    
                while (enumerator.MoveNext())
                {
                    Object obj = enumerator.Current;

                    if (!(obj is Zone || obj is Site || obj is Url || obj is StrongName || obj is PermissionRequestEvidence))
                        evidence.AddAssembly( obj );
                }
            }
        }       
		public void Equals_GetHashCode () 
		{
			Evidence e1 = new Evidence ();
			Evidence e2 = new Evidence ();
			AssertEquals ("GetHashCode-1", e1.GetHashCode (), e2.GetHashCode ());
			Assert ("e1.Equals(e2)", e1.Equals (e2));
			e1.AddAssembly (String.Empty);
			e2.AddAssembly (String.Empty);
			AssertEquals ("GetHashCode-2", e1.GetHashCode (), e2.GetHashCode ());
			e1.AddHost (String.Empty);
			e2.AddHost (String.Empty);
			AssertEquals ("GetHashCode-3", e1.GetHashCode (), e2.GetHashCode ());
			Assert ("e2.Equals(e1)", e2.Equals (e1));
		}
		public void Check () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");

			Evidence e = null;
			Assert.IsFalse (smc.Check (e), "Check(null)");
			e = new Evidence ();
			Assert.IsFalse (smc.Check (e), "Check (empty)");
			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (smc.Check (e), "Check (zone)");
			
			Site s = new Site ("*.go-mono.com");
			e.AddAssembly (s);
			Assert.IsFalse (smc.Check (e), "Check (site-assembly)");
			e.AddHost (s);
			Assert.IsTrue (smc.Check (e), "Check (site-host)");

			e = new Evidence ();
			e.AddHost (new Site ("www.go-mono.com"));
			Assert.IsTrue (smc.Check (e), "Check(+-)");

			e = new Evidence ();
			e.AddHost (new Site ("*.go-mono.org"));
			Assert.IsFalse (smc.Check (e), "Check(-)");
		}
示例#8
0
		public void AddAssembly ()
		{
			Evidence evidence = new Evidence ();
			object[] comparray = new object[100];
			string obj;

			for (int i=0; i<100; i++) {
				obj = String.Format ("asmb-{0}", i+1);
				comparray[i] = obj;
				evidence.AddAssembly (obj);
				Assert.AreEqual (evidence.Count, i+1);
			}
			
			int index = 0;
			foreach (object compobj in evidence) {
				Assert.AreEqual (comparray[index++], compobj, "Comparison object does not equal evidence assembly object");
			}
		}
示例#9
0
		public void RemoveType ()
		{
			Evidence e = new Evidence ();
			Assert.AreEqual (0, e.Count, "Count-Empty");
			e.AddAssembly (new object ());
			e.AddHost (new object ());
			Assert.AreEqual (2, e.Count, "Count");
			e.RemoveType (typeof (object));
			Assert.AreEqual (0, e.Count, "Count-RemoveType(object)");
		}
示例#10
0
		public void Clear () 
		{
			Evidence e = new Evidence ();
			Assert.AreEqual (0, e.Count, "Count-Empty");
			e.AddAssembly (new object ());
			Assert.AreEqual (1, e.Count, "Count+Assembly");
			e.AddHost (new object ());
			Assert.AreEqual (2, e.Count, "Count+Host");
			e.Clear ();
			Assert.AreEqual (0, e.Count, "Count-Cleared");
		}
示例#11
0
		public void Equals_GetHashCode () 
		{
			Evidence e1 = new Evidence ();
			Evidence e2 = new Evidence ();
			Assert.AreEqual (e1.GetHashCode (), e2.GetHashCode (), "GetHashCode-1");
			Assert.IsTrue (e1.Equals (e2), "e1.Equals(e2)");
			e1.AddAssembly (String.Empty);
			e2.AddAssembly (String.Empty);
			Assert.AreEqual (e1.GetHashCode (), e2.GetHashCode (), "GetHashCode-2");
			e1.AddHost (String.Empty);
			e2.AddHost (String.Empty);
			Assert.AreEqual (e1.GetHashCode (), e2.GetHashCode (), "GetHashCode-3");
			Assert.IsTrue (e2.Equals (e1), "e2.Equals(e1)");
		}
示例#12
0
        private static void DecodeSerializedEvidence( Evidence evidence,
                                               byte[] serializedEvidence )
        {
            BinaryFormatter formatter = new BinaryFormatter();
                
            Evidence asmEvidence = null;
                
            PermissionSet permSet = new PermissionSet( false );
            permSet.SetPermission( new SecurityPermission( SecurityPermissionFlag.SerializationFormatter ) );
            permSet.PermitOnly();
            permSet.Assert();

            try {
                using(MemoryStream ms = new MemoryStream( serializedEvidence ))
                    asmEvidence = (Evidence)formatter.Deserialize( ms );
            }
            catch
            {
            }
                
            if (asmEvidence != null)
            {
                IEnumerator enumerator = asmEvidence.GetAssemblyEnumerator();
                    
                while (enumerator.MoveNext())
                {
                    Object obj = enumerator.Current;
                    evidence.AddAssembly( obj );
                }
            }
        }       
		private static Evidence GetDefaultDomainIdentity()
		{
			Evidence evidence = new Evidence();
			bool zoneEvidence = false;
			IEnumerator hostEnumerator = AppDomain.CurrentDomain.Evidence.GetHostEnumerator();
			while (hostEnumerator.MoveNext())
			{
				if (hostEnumerator.Current is Zone)
					zoneEvidence = true;
				evidence.AddHost(hostEnumerator.Current);
			}
			hostEnumerator = AppDomain.CurrentDomain.Evidence.GetAssemblyEnumerator();
			while (hostEnumerator.MoveNext())
			{
				evidence.AddAssembly(hostEnumerator.Current);
			}
			if (!zoneEvidence)
				evidence.AddHost(new Zone(SecurityZone.MyComputer));
			return evidence;
		}
示例#14
0
		private void ResolveEvidenceAssembly (SecurityZone zone)
		{
			string prefix = zone.ToString () + "-";
			Evidence e = new Evidence ();
			e.AddAssembly (new Zone (zone));
			PermissionSet ps = SecurityManager.ResolvePolicy (e);
			Assert.AreEqual (0, ps.Count, prefix + "Count");
			Assert.IsTrue (ps.IsEmpty (), prefix + "IsEmpty");
			Assert.IsFalse (ps.IsUnrestricted (), prefix + "IsUnrestricted");
		}
		public void Check ()
		{
			HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
			Evidence e = null;
			Assert.IsFalse (hash.Check (e), "Check (null)");
			e = new Evidence ();
			Assert.IsFalse (hash.Check (e), "Check (empty)");
			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (hash.Check (e), "Check (zone)");
			e.AddAssembly (hashEvidence);
			Assert.IsFalse (hash.Check (e), "Check (hash-assembly)");

			e = new Evidence ();
			e.AddHost (hashEvidence);
			Assert.IsTrue (hash.Check (e), "Check (MD5-host)");

			hash = new HashMembershipCondition (sha1, digestSha1);
			Assert.IsTrue (hash.Check (e), "Check (SHA1-host)");
		}
		public void Check () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");

			Evidence e = null;
			Assert.IsFalse (umc.Check (e), "Check(null)");

			e = new Evidence ();
			Assert.IsFalse (umc.Check (e), "Check(empty)");

			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (umc.Check (e), "Check(zone)");

			Url u = new Url ("http://www.go-mono.com");
			e.AddAssembly (u);
			Assert.IsFalse (umc.Check (e), "Check(url-assembly)");
			e.AddHost (u);
			Assert.IsTrue (umc.Check (e), "Check(url-host)");
		}
示例#17
0
        internal static void MakeResourceAssemblyEvidence( Evidence input, out Evidence output, out StrongName outputSn )
        {
            IEnumerator eviEnumerator = input.GetHostEnumerator();

            output = new Evidence();
            outputSn = null;

            while (eviEnumerator.MoveNext())
            {
                if (eviEnumerator.Current is StrongName)
                {
                    StrongName inputSn = (StrongName)eviEnumerator.Current;

                    outputSn = new StrongName( inputSn.PublicKey, inputSn.Name + ".resource", inputSn.Version );

                    output.AddHost( outputSn );
                }
                else
                {
                    output.AddHost( eviEnumerator.Current );
                }
            }

            eviEnumerator = input.GetAssemblyEnumerator();

            while (eviEnumerator.MoveNext())
            {
                output.AddAssembly( eviEnumerator.Current );
            }
        }
		public void RemoveType ()
		{
			Evidence e = new Evidence ();
			AssertEquals ("Count-Empty", 0, e.Count);
			e.AddAssembly (new object ());
			e.AddHost (new object ());
			AssertEquals ("Count", 2, e.Count);
			e.RemoveType (typeof (object));
			AssertEquals ("Count-RemoveType(object)", 0, e.Count);
		}
		public void Clear () 
		{
			Evidence e = new Evidence ();
			AssertEquals ("Count-Empty", 0, e.Count);
			e.AddAssembly (new object ());
			AssertEquals ("Count+Assembly", 1, e.Count);
			e.AddHost (new object ());
			AssertEquals ("Count+Host", 2, e.Count);
			e.Clear ();
			AssertEquals ("Count-Cleared", 0, e.Count);
		}
		public void Check () 
		{
			PublisherMembershipCondition pmc = new PublisherMembershipCondition (x509);
			Publisher p = new Publisher (x509);

			Evidence e = null;
			Assert.IsFalse (pmc.Check (e), "Check (null)");
			e = new Evidence ();
			Assert.IsFalse (pmc.Check (e), "Check (empty)");
			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (pmc.Check (e), "Check (zone)");
			e.AddAssembly (p);
			Assert.IsFalse (pmc.Check (e), "Check (x509-assembly)");

			e = new Evidence ();
			e.AddHost (p);
			Assert.IsTrue (pmc.Check (e), "Check (x509-host)");
		}
示例#21
0
		public void Count ()
		{
			object[] hostarray = { "host-1", "host-2", "host-3", "host-4" };
			object[] asmbarray = { "asmb-1", "asmb-2", "asmb-3", "asmb-4" };
			Evidence evidence = new Evidence (hostarray, asmbarray);
			Assert.AreEqual (evidence.Count, 8);

			for( int i=0; i<100; i++ ) {
				if ( 0 == i%2 ) {
					evidence.AddHost (String.Format ("host-{0}", i + 5) );
				} else {
					evidence.AddAssembly (String.Format ("asmb-{0}", i + 5));
				}
				Assert.AreEqual (evidence.Count, 9 + i);
			}
		}
		private Evidence CreateAssemblyEvidence (object o)
		{
			Evidence e = new Evidence ();
			e.AddAssembly (o);
			return e;
		}
示例#23
0
 internal Evidence ShallowCopy()
 {
     Evidence evidence = new Evidence();
     
     IEnumerator enumerator;
     
     enumerator = this.GetHostEnumerator();
     
     while (enumerator.MoveNext())
     {
         evidence.AddHost( enumerator.Current );
     }
     
     enumerator = this.GetAssemblyEnumerator();
     
     while (enumerator.MoveNext())
     {
         evidence.AddAssembly( enumerator.Current );
     }
     
     return evidence;
 }