IsUnrestricted() public method

public IsUnrestricted ( ) : bool
return bool
Beispiel #1
0
		public void PermissionState_Unrestricted ()
		{
			PermissionState ps = PermissionState.Unrestricted;
			SmtpPermission sp = new SmtpPermission (ps);
			Assert.IsTrue (sp.IsUnrestricted (), "IsUnrestricted");
			Assert.AreEqual (SmtpAccess.ConnectToUnrestrictedPort, sp.Access, "Access");

			SecurityElement se = sp.ToXml ();
			Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "Xml-Unrestricted");
			Assert.AreEqual (3, se.Attributes.Count, "Xml-Attributes#");
			Assert.IsNull (se.Children, "Xml-Children");

			SmtpPermission copy = (SmtpPermission) sp.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
			Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
			Assert.AreEqual (sp.Access, copy.Access, "copy.Access");
		}
Beispiel #2
0
		public void PermissionState_Bad ()
		{
			PermissionState ps = (PermissionState) Int32.MinValue;
			SmtpPermission sp = new SmtpPermission (ps);
			// no ArgumentException here
			Assert.IsFalse (sp.IsUnrestricted ());
			Assert.AreEqual (SmtpAccess.None, sp.Access, "Access");
		}
Beispiel #3
0
		public void PermissionState_None ()
		{
			PermissionState ps = PermissionState.None;
			SmtpPermission sp = new SmtpPermission (ps);
			Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
			Assert.AreEqual (SmtpAccess.None, sp.Access, "Access");

			SecurityElement se = sp.ToXml ();
			// only class and version are present
			Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes#");
			Assert.IsNull (se.Children, "Xml-Children");

			SmtpPermission copy = (SmtpPermission) sp.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
			Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
			Assert.AreEqual (sp.Access, copy.Access, "copy.Access");
		}
Beispiel #4
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            SmtpPermission permission = target as SmtpPermission;

            if (permission == null)
            {
                throw new ArgumentException(SR.GetString("net_perm_target"), "target");
            }
            if (this.unrestricted || permission.IsUnrestricted())
            {
                return(new SmtpPermission(true));
            }
            return(new SmtpPermission((this.access > permission.access) ? this.access : permission.access));
        }
Beispiel #5
0
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.access == SmtpAccess.None);
            }
            SmtpPermission permission = target as SmtpPermission;

            if (permission == null)
            {
                throw new ArgumentException(SR.GetString("net_perm_target"), "target");
            }
            if (this.unrestricted && !permission.IsUnrestricted())
            {
                return(false);
            }
            return(permission.access >= this.access);
        }
        /// <include file='doc\SmtpPermission.uex' path='docs/doc[@for="SmtpPermission.Union"]/*' />
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            SmtpPermission other = target as SmtpPermission;

            if (other == null)
            {
                throw new ArgumentException(SR.GetString(SR.net_perm_target), "target");
            }

            if (unrestricted || other.IsUnrestricted())
            {
                return(new SmtpPermission(true));
            }

            return(new SmtpPermission(this.access > other.access ? this.access : other.access));
        }
Beispiel #7
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(Copy());
            }
            SmtpPermission other = target as SmtpPermission;

            if (other == null)
            {
                throw new ArgumentException(SR.Format(SR.net_perm_target), nameof(target));
            }

            if (_unrestricted || other.IsUnrestricted())
            {
                return(new SmtpPermission(true));
            }

            return(new SmtpPermission(_access > other._access ? _access : other._access));
        }
        /// <include file='doc\SmtpPermission.uex' path='docs/doc[@for="SmtpPermission.IsSubsetOf"]/*' />
        public override bool IsSubsetOf(IPermission target)
        {
            // Pattern suggested by security engine
            if (target == null)
            {
                return(access == SmtpAccess.None);
            }

            SmtpPermission other = target as SmtpPermission;

            if (other == null)
            {
                throw new ArgumentException(SR.GetString(SR.net_perm_target), "target");
            }

            if (unrestricted && !other.IsUnrestricted())
            {
                return(false);
            }

            return(other.access >= access);
        }
Beispiel #9
0
		public void Ctor_Boolean_True ()
		{
			SmtpPermission sp = new SmtpPermission (true);
			Assert.IsTrue (sp.IsUnrestricted (), "IsUnrestricted");
			Assert.AreEqual (SmtpAccess.ConnectToUnrestrictedPort, sp.Access, "Access");

			SecurityElement se = sp.ToXml ();
			Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "Xml-Unrestricted");
			Assert.AreEqual (3, se.Attributes.Count, "Xml-Attributes#");
			Assert.IsNull (se.Children, "Xml-Children");
		}
Beispiel #10
0
		public void Ctor_SmtpAccess_Invalid ()
		{
			SmtpAccess sa = (SmtpAccess)Int32.MinValue;
			SmtpPermission sp = new SmtpPermission (sa);
			// no exception
			Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
			Assert.AreEqual (sa, sp.Access, "Access");

			// invalid access doesn't get serialized to XML
			SecurityElement se = sp.ToXml ();
			Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes#");
			Assert.IsNull (se.Children, "Xml-Children");

			// but it doesn't roundtrip
			SmtpPermission copy = (SmtpPermission) sp.Copy ();
			Assert.AreEqual (sp.Access, copy.Access, "copy.Access");
		}
Beispiel #11
0
		public void Ctor_SmtpAccess_ConnectToUnrestrictedPort ()
		{
			SmtpPermission sp = new SmtpPermission (SmtpAccess.ConnectToUnrestrictedPort);
			Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
			Assert.AreEqual (SmtpAccess.ConnectToUnrestrictedPort, sp.Access, "Access");

			SecurityElement se = sp.ToXml ();
			// only class and version are present
			Assert.AreEqual (3, se.Attributes.Count, "Xml-Attributes#");
			Assert.AreEqual ("ConnectToUnrestrictedPort", se.Attribute ("Access"), "Xml-Access");
			Assert.IsNull (se.Children, "Xml-Children");
		}
Beispiel #12
0
		public void Ctor_Boolean_False ()
		{
			SmtpPermission sp = new SmtpPermission (false);
			Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
			Assert.AreEqual (SmtpAccess.None, sp.Access, "Access");

			SecurityElement se = sp.ToXml ();
			// only class and version are present
			Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes#");
			Assert.IsNull (se.Children, "Xml-Children");
		}