Exemplo n.º 1
0
		public void ToXml () 
		{
			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
			SecurityElement se = cg.ToXml ();
			string s = se.ToString ();
			Assert.IsTrue (s.StartsWith ("<CodeGroup class=\"MonoTests.System.Security.Policy.MyCodeGroup,"), "ToXml-Starts");
			Assert.IsTrue (s.EndsWith ("version=\"1\"/>" + Environment.NewLine + "</CodeGroup>" + Environment.NewLine), "ToXml-Ends");

			cg.AddChild (new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.Unrestricted))));
			se = cg.ToXml ();
			s = se.ToString ();
			Assert.IsTrue (s.IndexOf ("<CodeGroup class=\"MonoTests.System.Security.Policy.MyCodeGroup,", 1) > 0, "ToXml-Child");
		}
        public void FromXml_Bad()
        {
            MyCodeGroup     cg = new MyCodeGroup(new AllMembershipCondition(), new PolicyStatement(new PermissionSet(PermissionState.None)));
            SecurityElement se = cg.ToXml();

            se.Tag = "Mono";
            // strangely this works :(
            cg.FromXml(se);
            // let's get weirder :)
            foreach (SecurityElement child in se.Children)
            {
                child.Tag = "Mono";
            }
            cg.FromXml(se);
            // it's not enough :(( - very relax parsing
            se.Attributes = new Hashtable();
            cg.FromXml(se);
            // arghh - I will prevail!
            foreach (SecurityElement child in se.Children)
            {
                child.Attributes = new Hashtable();
            }
            cg.FromXml(se);
            // huh ? well maybe not (but this is both cruel and injust)
        }
Exemplo n.º 3
0
		public void ToFromXmlRoundtrip () 
		{
			PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));
			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
			cg.Name = "SomeName";
			cg.Description = "Some Description";
			Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
			SecurityElement se = cg.ToXml ();

			MyCodeGroup cg2 = new MyCodeGroup (new AllMembershipCondition(), ps);
			cg2.Name = "SomeOtherName";
			cg2.Description = "Some Other Description";
			Assert.IsTrue (!cg.Equals (cg2), "Equals (another)");

			cg2.FromXml (se);
			Assert.IsTrue (cg.Equals (cg2), "Equals (FromXml)");
		}
Exemplo n.º 4
0
		public void ToFromXmlRoundtrip_WithChildren_Second () 
		{
			PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));

			// only the child is MySecondCodeGroup
			MySecondCodeGroup cgChild = new MySecondCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
			cgChild.Name = "ChildName";
			cgChild.Description = "Child Descripiton";

			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
			cg.Name = "SomeName";
			cg.Description = "Some Description";
			cg.AddChild (cgChild);
			Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
			SecurityElement se = cg.ToXml ();

			MyCodeGroup cg2 = (MyCodeGroup) cg.Copy ();
			cg2.FromXml (se);
			Assert.IsTrue (cg.Equals (cg2, true), "Equals (FromXml)");
		}
Exemplo n.º 5
0
		public void ToFromXmlRoundtrip_WithChildren () 
		{
			PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));

			MyCodeGroup cgChild = new MyCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
			cgChild.Name = "ChildName";
			cgChild.Description = "Child Descripiton";

			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
			cg.Name = "SomeName";
			cg.Description = "Some Description";
			cg.AddChild (cgChild);
			cg.AddChild (cgChild);
			Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
			SecurityElement se = cg.ToXml ();

			MyCodeGroup cg2 = (MyCodeGroup) cg.Copy ();
			cg2.FromXml (se);
			// MissingMethodException down here (stangely not up here ?!? delayed ?)
			Assert.IsTrue (cg.Equals (cg2, true), "Equals (FromXml)");
		}
Exemplo n.º 6
0
		public void FromXml_Bad () 
		{
			MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
			SecurityElement se = cg.ToXml ();
			se.Tag = "Mono";
			// strangely this works :(
			cg.FromXml (se);
			// let's get weirder :)
			foreach (SecurityElement child in se.Children) {
				child.Tag = "Mono";
			}
			cg.FromXml (se);
			// it's not enough :(( - very relax parsing
			se.Attributes = new Hashtable ();
			cg.FromXml (se);
			// arghh - I will prevail!
			foreach (SecurityElement child in se.Children) {
				child.Attributes = new Hashtable ();
			}
			cg.FromXml (se);
			// huh ? well maybe not (but this is both cruel and injust)
		}