Inheritance: CodeAccessPermission, IBuiltInPermission
コード例 #1
0
		public void PermissionState_None ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			// that cause a NullReferenceException before 2.0
			Assert.AreEqual (String.Empty, uip.Url, "Url");
			SecurityElement se = uip.ToXml ();
			// only class and version are present
			Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes");
			Assert.IsNull (se.Children, "Xml-Children");
			UrlIdentityPermission copy = (UrlIdentityPermission)uip.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (uip, copy), "ReferenceEquals");
		}
コード例 #2
0
		public void PermissionStateUnrestricted ()
		{
			// In 2.0 Unrestricted are permitted for identity permissions
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.Unrestricted);
			Assert.AreEqual (String.Empty, uip.Url, "Url");
			SecurityElement se = uip.ToXml ();
			// only class and version are present
			Assert.AreEqual (3, se.Attributes.Count, "Xml-Attributes");
			Assert.IsNull (se.Children, "Xml-Children");
			// and they aren't equals to None
			Assert.IsFalse (uip.Equals (new UrlIdentityPermission (PermissionState.None)));
		}
 public override IPermission Copy()
 {
     UrlIdentityPermission permission = new UrlIdentityPermission(PermissionState.None) {
         m_unrestricted = this.m_unrestricted
     };
     if (this.m_urls != null)
     {
         permission.m_urls = new URLString[this.m_urls.Length];
         for (int i = 0; i < this.m_urls.Length; i++)
         {
             permission.m_urls[i] = (URLString) this.m_urls[i].Copy();
         }
     }
     return permission;
 }
 private void AppendZoneOrigin(ZoneIdentityPermission z, UrlIdentityPermission u)
 {
     if (z != null)
     {
         if (this.m_zoneList == null)
         {
             this.m_zoneList = new ArrayList();
         }
         z.AppendZones(this.m_zoneList);
     }
     if (u != null)
     {
         if (this.m_originList == null)
         {
             this.m_originList = new ArrayList();
         }
         u.AppendOrigin(this.m_originList);
     }
 }
コード例 #5
0
		public void FromXml_NoClass ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", se.Attribute ("version"));
			uip.FromXml (w);
			// doesn't even care of the class attribute presence
		}
コード例 #6
0
		public void FromXml_WrongTagCase ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();
			se.Tag = "IPERMISSION"; // instead of IPermission
			uip.FromXml (se);
		}
コード例 #7
0
		public void FromXml_WrongClass ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
			w.AddAttribute ("version", se.Attribute ("version"));
			uip.FromXml (w);
			// doesn't care of the class name at that stage
			// anyway the class has already be created so...
		}
コード例 #8
0
		public void Intersect_Null ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			// No intersection with null
			foreach (string s in GoodUrls) {
				uip.Url = s;
				Assert.IsNull (uip.Intersect (null), s);
			}
		}
コード例 #9
0
		public void FromXml_WrongTag ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();
			se.Tag = "IMono";
			uip.FromXml (se);
		}
コード例 #10
0
		public void Copy_None ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			UrlIdentityPermission copy = (UrlIdentityPermission)uip.Copy ();
		}
コード例 #11
0
		public void Intersect_Self ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			foreach (string s in GoodUrls) {
				uip.Url = s;
				UrlIdentityPermission result = (UrlIdentityPermission)uip.Intersect (uip);
				// Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
				// so we only compare the start of the url
				Assert.IsTrue (result.Url.StartsWith (uip.Url), s);
			}
		}
コード例 #12
0
		public void Union_Null ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			// Union with null is a simple copy
			foreach (string s in GoodUrls) {
				uip.Url = s;
				UrlIdentityPermission union = (UrlIdentityPermission)uip.Union (null);
				// Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
				// so we only compare the start of the url
				Assert.IsTrue (union.Url.StartsWith (uip.Url), s);
			}
		}
コード例 #13
0
		public void PermissionState_Bad ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission ((PermissionState)Int32.MinValue);
		}
コード例 #14
0
		public void IsSubset_Self ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			Assert.IsTrue (uip.IsSubsetOf (uip), "None");
			foreach (string s in GoodUrls) {
				uip.Url = s;
				Assert.IsTrue (uip.IsSubsetOf (uip), s);
			}
		}
コード例 #15
0
		public void IsSubset_Different ()
		{
			UrlIdentityPermission uip1 = new UrlIdentityPermission (GoodUrls [0]);
			UrlIdentityPermission uip2 = new UrlIdentityPermission (GoodUrls [1]);
			Assert.IsFalse (uip1.IsSubsetOf (uip2), "Mono subset Novell");
			Assert.IsFalse (uip2.IsSubsetOf (uip1), "Novell subset Mono");
		}
コード例 #16
0
		public void IsSubset_None ()
		{
			// IsSubset with none
			// a. source (this) is none -> target is never a subset
			UrlIdentityPermission uip1 = new UrlIdentityPermission (PermissionState.None);
			UrlIdentityPermission uip2 = new UrlIdentityPermission (PermissionState.None);
			foreach (string s in GoodUrls) {
				uip1.Url = s;
				Assert.IsFalse (uip1.IsSubsetOf (uip2), "target " + s);
			}
			uip1 = new UrlIdentityPermission (PermissionState.None);
			// b. destination (target) is none -> target is always a subset
			foreach (string s in GoodUrls) {
				uip2.Url = s;
				Assert.IsFalse (uip2.IsSubsetOf (uip1), "source " + s);
			}
		}
コード例 #17
0
		public void IsSubset_Null ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			Assert.IsTrue (uip.IsSubsetOf (null), "Empty");
			foreach (string s in GoodUrls) {
				uip.Url = s;
				Assert.IsFalse (uip.IsSubsetOf (null), s);
			}
		}
コード例 #18
0
		public void Intersect_Different ()
		{
			UrlIdentityPermission uip1 = new UrlIdentityPermission (GoodUrls [0]);
			UrlIdentityPermission uip2 = new UrlIdentityPermission (GoodUrls [1]);
			UrlIdentityPermission result = (UrlIdentityPermission)uip1.Intersect (uip2);
			Assert.IsNull (result, "Mono N Novell");
		}
コード例 #19
0
		public void FromXml_WrongVersion ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();
			se.Attributes.Remove ("version");
			se.Attributes.Add ("version", "2");
			uip.FromXml (se);
		}
コード例 #20
0
		public void Url ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			foreach (string s in GoodUrls) {
				uip.Url = s;
				Assert.AreEqual (s, uip.Url, s);
			}
		}
コード例 #21
0
		public void FromXml_NoVersion ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			SecurityElement se = uip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			uip.FromXml (w);
		}
コード例 #22
0
 public override IPermission Intersect(IPermission target)
 {
     if (target == null)
         return null;
     UrlIdentityPermission that = target as UrlIdentityPermission;
     if(that == null)
         throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
     if(this.m_unrestricted && that.m_unrestricted)
     {
         UrlIdentityPermission res = new UrlIdentityPermission(PermissionState.None);
         res.m_unrestricted = true;
         return res;
     }
     if(this.m_unrestricted)
         return that.Copy();
     if(that.m_unrestricted)
         return this.Copy();
     if(this.m_urls == null || that.m_urls == null || this.m_urls.Length == 0 || that.m_urls.Length == 0)
         return null;
     List<URLString> alUrls = new List<URLString>();
     foreach(URLString usThis in this.m_urls)
     {
         foreach(URLString usThat in that.m_urls)
         {
             URLString usInt = (URLString)usThis.Intersect(usThat);
             if(usInt != null)
                 alUrls.Add(usInt);
         }
     }
     if(alUrls.Count == 0)
         return null;
     UrlIdentityPermission result = new UrlIdentityPermission(PermissionState.None);
     result.m_urls = alUrls.ToArray();
     return result;
 }
コード例 #23
0
		public void Union_None ()
		{
			// Union with none is same
			UrlIdentityPermission uip1 = new UrlIdentityPermission (PermissionState.None);
			UrlIdentityPermission uip2 = new UrlIdentityPermission (PermissionState.None);
			// a. source (this) is none
			foreach (string s in GoodUrls) {
				uip1.Url = s;
				UrlIdentityPermission union = (UrlIdentityPermission)uip1.Union (uip2);
				// Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
				// so we only compare the start of the url
				Assert.IsTrue (union.Url.StartsWith (uip1.Url), s);
			}
			uip1 = new UrlIdentityPermission (PermissionState.None);
			// b. destination (target) is none
			foreach (string s in GoodUrls) {
				uip2.Url = s;
				UrlIdentityPermission union = (UrlIdentityPermission)uip2.Union (uip1);
				// Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
				// so we only compare the start of the url
				Assert.IsTrue (union.Url.StartsWith (uip2.Url), s);
			}
		}
コード例 #24
0
		public void Intersect_None ()
		{
			UrlIdentityPermission uip1 = new UrlIdentityPermission (PermissionState.None);
			UrlIdentityPermission uip2 = new UrlIdentityPermission (PermissionState.None);
			UrlIdentityPermission result = (UrlIdentityPermission)uip1.Intersect (uip2);
			Assert.IsNull (result, "None N None");
			foreach (string s in GoodUrls) {
				uip1.Url = s;
				// 1. Intersect None with Url
				result = (UrlIdentityPermission)uip1.Intersect (uip2);
				Assert.IsNull (result, "None N " + s);
				// 2. Intersect Url with None
				result = (UrlIdentityPermission)uip2.Intersect (uip1);
				Assert.IsNull (result, s + "N None");
			}
		}
コード例 #25
0
		public void UrlIdentityPermission_NullUrl ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (null);
		}
コード例 #26
0
		public void Union_Self ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			UrlIdentityPermission union = (UrlIdentityPermission)uip.Union (uip);
			Assert.IsNull (union, "None U None"); 
			foreach (string s in GoodUrls) {
				uip.Url = s;
				union = (UrlIdentityPermission)uip.Union (uip);
				// Fx 1.0/1.1 adds a '/' at the end, while 2.0 keeps the original format
				// so we only compare the start of the url
				Assert.IsTrue (union.Url.StartsWith (uip.Url), s);
			}
		}
コード例 #27
0
        //------------------------------------------------------
        //
        // PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS
        //
        //------------------------------------------------------

        //------------------------------------------------------
        //
        // CODEACCESSPERMISSION IMPLEMENTATION
        //
        //------------------------------------------------------

        //------------------------------------------------------
        //
        // IPERMISSION IMPLEMENTATION
        //
        //------------------------------------------------------


        public override IPermission Copy()
        {
            UrlIdentityPermission perm = new UrlIdentityPermission( PermissionState.None );
            perm.m_unrestricted = this.m_unrestricted;
            if (this.m_urls != null)
            {
                perm.m_urls = new URLString[this.m_urls.Length];
                int n;
                for(n = 0; n < this.m_urls.Length; n++)
                    perm.m_urls[n] = (URLString)this.m_urls[n].Copy();
            }
            return perm;
        }
コード例 #28
0
		public void Union_Different ()
		{
			UrlIdentityPermission uip1 = new UrlIdentityPermission (GoodUrls [0]);
			UrlIdentityPermission uip2 = new UrlIdentityPermission (GoodUrls [1]);
			UrlIdentityPermission result = (UrlIdentityPermission)uip1.Union (uip2);
			Assert.IsNotNull (result, "Mono U Novell");
			// new XML format is used to contain more than one site
			SecurityElement se = result.ToXml ();
			Assert.AreEqual (2, se.Children.Count, "Childs");
			Assert.AreEqual (GoodUrls [0], (se.Children [0] as SecurityElement).Attribute ("Url"), "Url#1");
			Assert.AreEqual (GoodUrls [1], (se.Children [1] as SecurityElement).Attribute ("Url"), "Url#2");
			// strangely it is still versioned as 'version="1"'.
			Assert.AreEqual ("1", se.Attribute ("version"), "Version");
		}
コード例 #29
0
 public override IPermission Union(IPermission target)
 {
     if (target == null)
     {
         if((this.m_urls == null || this.m_urls.Length == 0) && !this.m_unrestricted)
             return null;
         return this.Copy();
     }
     UrlIdentityPermission that = target as UrlIdentityPermission;
     if(that == null)
         throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
     if(this.m_unrestricted || that.m_unrestricted)
     {
         UrlIdentityPermission res = new UrlIdentityPermission(PermissionState.None);
         res.m_unrestricted = true;
         return res;
     }
     if (this.m_urls == null || this.m_urls.Length == 0)
     {
         if(that.m_urls == null || that.m_urls.Length == 0)
             return null;
         return that.Copy();
     }
     if(that.m_urls == null || that.m_urls.Length == 0)
         return this.Copy();
     List<URLString> alUrls = new List<URLString>();
     foreach(URLString usThis in this.m_urls)
         alUrls.Add(usThis);
     foreach(URLString usThat in that.m_urls)
     {
         bool bDupe = false;
         foreach(URLString us in alUrls)
         {
             if(usThat.Equals(us))
             {
                 bDupe = true;
                 break;
             }
         }
         if(!bDupe)
             alUrls.Add(usThat);
     }
     UrlIdentityPermission result = new UrlIdentityPermission(PermissionState.None);
     result.m_urls = alUrls.ToArray();
     return result;
 }
コード例 #30
0
		public void FromXml_Null ()
		{
			UrlIdentityPermission uip = new UrlIdentityPermission (PermissionState.None);
			uip.FromXml (null);
		}