Esempio n. 1
0
        public void IntersectWithUnrestricted()
        {
            ReflectionPermission p1 = new ReflectionPermission(PermissionState.Unrestricted);
            ReflectionPermission p2 = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
            ReflectionPermission p3 = (ReflectionPermission)p1.Intersect(p2);

            Assert.IsTrue(!p3.IsUnrestricted(), "Unrestricted N P2 == P2");
            Assert.AreEqual(p2.ToXml().ToString(), p3.ToXml().ToString(), "Unrestricted N EP2 == EP2");
            p3 = (ReflectionPermission)p2.Intersect(p1);
            Assert.IsTrue(!p3.IsUnrestricted(), "P2 N Unrestricted == P2");
            Assert.AreEqual(p2.ToXml().ToString(), p3.ToXml().ToString(), "P2 N Unrestricted == P2");

            p2 = new ReflectionPermission(ReflectionPermissionFlag.NoFlags);
            p3 = (ReflectionPermission)p1.Intersect(p2);
            Assert.IsNull(p3, "Unrestricted N None == null");
        }
Esempio n. 2
0
        public void UnionWithNull()
        {
            ReflectionPermission p1 = new ReflectionPermission(ReflectionPermissionFlag.NoFlags);
            ReflectionPermission p2 = null;
            ReflectionPermission p3 = (ReflectionPermission)p1.Union(p2);

            Assert.AreEqual(p1.ToXml().ToString(), p3.ToXml().ToString(), "P1 U null == P1");
        }
Esempio n. 3
0
        public void ReflectionEmit()
        {
            ReflectionPermission p = new ReflectionPermission(ReflectionPermissionFlag.ReflectionEmit);

            Assert.IsTrue(!p.IsUnrestricted(), "IsUnrestricted");
            SecurityElement se = p.ToXml();

            Assert.AreEqual("ReflectionEmit", (se.Attributes ["Flags"] as string), "ToXml-Flags=ReflectionEmit");
        }
Esempio n. 4
0
        public void MemberAccess()
        {
            ReflectionPermission p = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);

            Assert.IsTrue(!p.IsUnrestricted(), "IsUnrestricted");
            SecurityElement se = p.ToXml();

            Assert.AreEqual("MemberAccess", (se.Attributes ["Flags"] as string), "ToXml-Flags=MemberAccess");
        }
Esempio n. 5
0
        public void TypeInformation()
        {
            ReflectionPermission p = new ReflectionPermission(ReflectionPermissionFlag.TypeInformation);

            Assert.IsTrue(!p.IsUnrestricted(), "IsUnrestricted");
            SecurityElement se = p.ToXml();

            Assert.AreEqual("TypeInformation", (se.Attributes ["Flags"] as string), "ToXml-Flags=TypeInformation");
        }
Esempio n. 6
0
        public void AllFlags()
        {
            ReflectionPermission p = new ReflectionPermission(ReflectionPermissionFlag.AllFlags);

            Assert.IsTrue(p.IsUnrestricted(), "IsUnrestricted");
            SecurityElement se = p.ToXml();

            Assert.AreEqual("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
        }
Esempio n. 7
0
        public void FromXml()
        {
            ReflectionPermission p  = new ReflectionPermission(PermissionState.None);
            SecurityElement      se = p.ToXml();

            Assert.IsNotNull(se, "ToXml()");

            ReflectionPermission p2 = (ReflectionPermission)p.Copy();

            p2.FromXml(se);
            Assert.AreEqual(ReflectionPermissionFlag.NoFlags, p2.Flags, "FromXml-None");

            string className = (string)se.Attributes ["class"];
            string version   = (string)se.Attributes ["version"];

            SecurityElement se2 = new SecurityElement(se.Tag);

            se2.AddAttribute("class", className);
            se2.AddAttribute("version", version);
            se2.AddAttribute("Flags", "TypeInformation");
            p2.FromXml(se2);
            Assert.AreEqual(ReflectionPermissionFlag.TypeInformation, p2.Flags, "FromXml-TypeInformation");

            se2 = new SecurityElement(se.Tag);
            se2.AddAttribute("class", className);
            se2.AddAttribute("version", version);
            se2.AddAttribute("Flags", "MemberAccess");
            p2.FromXml(se2);
            Assert.AreEqual(ReflectionPermissionFlag.MemberAccess, p2.Flags, "FromXml-MemberAccess");

            se2 = new SecurityElement(se.Tag);
            se2.AddAttribute("class", className);
            se2.AddAttribute("version", version);
            se2.AddAttribute("Flags", "ReflectionEmit");
            p2.FromXml(se2);
            Assert.AreEqual(ReflectionPermissionFlag.ReflectionEmit, p2.Flags, "FromXml-ReflectionEmit");

            se = p.ToXml();
            se.AddAttribute("Unrestricted", "true");
            p2.FromXml(se);
            Assert.IsTrue(p2.IsUnrestricted(), "FromXml-Unrestricted");
            Assert.AreEqual(ReflectionPermissionFlag.AllFlags, p2.Flags, "FromXml-AllFlags");
        }
Esempio n. 8
0
    //</Snippet5>
    // ToXml creates an XML encoding of the permission and its current state;
    // FromXml reconstructs a permission with the specified state from the XML encoding.
    //<Snippet6>
    private static void ToFromXmlDemo()
    {
        ReflectionPermission memberAccessPerm = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
        //<Snippet7>
        ReflectionPermission restrictedMemberAccessPerm = new ReflectionPermission(PermissionState.None);

        //</Snippet7>
        restrictedMemberAccessPerm.FromXml(memberAccessPerm.ToXml());
        Console.WriteLine("Result of ToFromXml = " +
                          restrictedMemberAccessPerm.ToString());
    }
Esempio n. 9
0
        public void FromXmlWrongVersion()
        {
            ReflectionPermission p  = new ReflectionPermission(PermissionState.None);
            SecurityElement      se = p.ToXml();
            // can't modify - so we create our own
            SecurityElement se2 = new SecurityElement(se.Tag, se.Text);

            se2.AddAttribute("class", se.Attribute("class"));
            se2.AddAttribute("version", "2");
            p.FromXml(se2);
        }
Esempio n. 10
0
        public void PermissionStateUnrestricted()
        {
            ReflectionPermission p = new ReflectionPermission(PermissionState.Unrestricted);

            Assert.IsNotNull(p, "ReflectionPermission(PermissionState.Unrestricted)");
            Assert.IsTrue(p.IsUnrestricted(), "IsUnrestricted");
            ReflectionPermission copy = (ReflectionPermission)p.Copy();

            Assert.AreEqual(p.IsUnrestricted(), copy.IsUnrestricted(), "Copy.IsUnrestricted");
            SecurityElement se = p.ToXml();

            Assert.AreEqual("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
        }
Esempio n. 11
0
        public void PermissionStateNone()
        {
            ReflectionPermission p = new ReflectionPermission(PermissionState.None);

            Assert.IsNotNull(p, "ReflectionPermission(PermissionState.None)");
            Assert.IsTrue(!p.IsUnrestricted(), "IsUnrestricted");
            ReflectionPermission copy = (ReflectionPermission)p.Copy();

            Assert.AreEqual(p.IsUnrestricted(), copy.IsUnrestricted(), "Copy.IsUnrestricted");
            SecurityElement se = p.ToXml();

            Assert.IsTrue((se.Attributes ["class"] as string).StartsWith(className), "ToXml-class");
            Assert.AreEqual("1", (se.Attributes ["version"] as string), "ToXml-version");
        }
Esempio n. 12
0
        public static void ReflectionPermissionCallMethods()
        {
            ReflectionPermission rp  = new ReflectionPermission(new Permissions.PermissionState());
            ReflectionPermission rp2 = new ReflectionPermission(new Permissions.ReflectionPermissionFlag());
            IPermission          ip  = rp.Copy();
            IPermission          ip2 = rp.Intersect(ip);
            bool testbool            = rp.IsSubsetOf(ip);

            testbool = rp.IsUnrestricted();
            ip2      = rp.Union(ip);
            SecurityElement se = new SecurityElement("");

            rp.FromXml(se);
            se = rp.ToXml();
        }
Esempio n. 13
0
 public static void ReflectionPermissionCallMethods()
 {
     ReflectionPermission rp = new ReflectionPermission(new Permissions.PermissionState());
     ReflectionPermission rp2 = new ReflectionPermission(new Permissions.ReflectionPermissionFlag());
     IPermission ip = rp.Copy();
     IPermission ip2 = rp.Intersect(ip);
     bool testbool = rp.IsSubsetOf(ip);
     testbool = rp.IsUnrestricted();
     ip2 = rp.Union(ip);
     SecurityElement se = new SecurityElement("");
     rp.FromXml(se);
     se = rp.ToXml();
 }