Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2004-08-04 22:53:52 +0400
committerSebastien Pouliot <sebastien@ximian.com>2004-08-04 22:53:52 +0400
commit6a0c3b591a329c54520216feaf426e664b74c4f7 (patch)
tree2446f02225bdce5c83d61995e9e657951dcf7076 /mcs
parent0b64d850d321e96f50c8a9b53922370d703f8957 (diff)
2004-08-03 Sebastien Pouliot <sebastien@ximian.com>
* ZoneMembershipConditionTest.cs: New. Unit tests in NUnit 2.2 format. svn path=/trunk/mcs/; revision=31878
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/corlib/Test/System.Security.Policy/ChangeLog8
-rw-r--r--mcs/class/corlib/Test/System.Security.Policy/ZoneMembershipConditionTest.cs294
2 files changed, 300 insertions, 2 deletions
diff --git a/mcs/class/corlib/Test/System.Security.Policy/ChangeLog b/mcs/class/corlib/Test/System.Security.Policy/ChangeLog
index eb54c00e09d..8e9475bec7b 100644
--- a/mcs/class/corlib/Test/System.Security.Policy/ChangeLog
+++ b/mcs/class/corlib/Test/System.Security.Policy/ChangeLog
@@ -1,8 +1,12 @@
-2003-08-02 Sebastien Pouliot <sebastien@ximian.com>
+2004-08-03 Sebastien Pouliot <sebastien@ximian.com>
+
+ * ZoneMembershipConditionTest.cs: New. Unit tests in NUnit 2.2 format.
+
+2004-08-02 Sebastien Pouliot <sebastien@ximian.com>
* UnionCodeGroupTest.cs: Added tests for ResolveMatchingCodeGroups.
-2003-05-20 Sebastien Pouliot <sebastien@ximian.com>
+2004-05-20 Sebastien Pouliot <sebastien@ximian.com>
* PolicyLevelTest.cs, StrongNameTest.cs: SetUp is now public (required
for new nunit).
diff --git a/mcs/class/corlib/Test/System.Security.Policy/ZoneMembershipConditionTest.cs b/mcs/class/corlib/Test/System.Security.Policy/ZoneMembershipConditionTest.cs
new file mode 100644
index 00000000000..072965841c1
--- /dev/null
+++ b/mcs/class/corlib/Test/System.Security.Policy/ZoneMembershipConditionTest.cs
@@ -0,0 +1,294 @@
+//
+// ZoneMembershipConditionTest.cs - NUnit Test Cases for ZoneMembershipCondition
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.Collections;
+using System.Security;
+using System.Security.Permissions;
+using System.Security.Policy;
+
+namespace MonoTests.System.Security.Policy {
+
+ [TestFixture]
+ public class ZoneMembershipConditionTest {
+
+ static Evidence allEmpty;
+ static Evidence hostInternet;
+ static Evidence hostIntranet;
+ static Evidence hostMyComputer;
+ static Evidence hostNoZone;
+ static Evidence hostTrusted;
+ static Evidence hostUntrusted;
+ static Evidence hostOther;
+ static Evidence assemblyInternet;
+ static Evidence assemblyIntranet;
+ static Evidence assemblyMyComputer;
+ static Evidence assemblyNoZone;
+ static Evidence assemblyTrusted;
+ static Evidence assemblyUntrusted;
+ static Evidence assemblyOther;
+ static object wrongEvidence;
+
+ private Evidence CreateHostEvidence (object o)
+ {
+ Evidence e = new Evidence ();
+ e.AddHost (o);
+ return e;
+ }
+
+ private Evidence CreateAssemblyEvidence (object o)
+ {
+ Evidence e = new Evidence ();
+ e.AddAssembly (o);
+ return e;
+ }
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ wrongEvidence = new Site ("test");
+ allEmpty = new Evidence ();
+ hostInternet = CreateHostEvidence (new Zone (SecurityZone.Internet));
+ hostIntranet = CreateHostEvidence (new Zone (SecurityZone.Intranet));
+ hostMyComputer = CreateHostEvidence (new Zone (SecurityZone.MyComputer));
+ hostNoZone = CreateHostEvidence (new Zone (SecurityZone.NoZone));
+ hostTrusted = CreateHostEvidence (new Zone (SecurityZone.Trusted));
+ hostUntrusted = CreateHostEvidence (new Zone (SecurityZone.Untrusted));
+ hostOther = CreateHostEvidence (wrongEvidence);
+ assemblyInternet = CreateAssemblyEvidence (new Zone (SecurityZone.Internet));
+ assemblyIntranet = CreateAssemblyEvidence (new Zone (SecurityZone.Intranet));
+ assemblyMyComputer = CreateAssemblyEvidence (new Zone (SecurityZone.MyComputer));
+ assemblyNoZone = CreateAssemblyEvidence (new Zone (SecurityZone.NoZone));
+ assemblyTrusted = CreateAssemblyEvidence (new Zone (SecurityZone.Trusted));
+ assemblyUntrusted = CreateAssemblyEvidence (new Zone (SecurityZone.Untrusted));
+ assemblyOther = CreateAssemblyEvidence (wrongEvidence);
+ }
+
+ private ZoneMembershipCondition BasicTest (SecurityZone zone)
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition (zone);
+ Assert.AreEqual (zone, zmc.SecurityZone, "SecurityZone");
+ Assert.IsFalse (zmc.Check (null), "Check(null)");
+ Assert.IsFalse (zmc.Check (allEmpty), "Check(empty)");
+ Assert.IsFalse (zmc.Check (hostOther), "Check(hostOther)");
+ Assert.IsFalse (zmc.Check (assemblyOther), "Check(assemblyOther)");
+
+ ZoneMembershipCondition copy = (ZoneMembershipCondition) zmc.Copy ();
+ Assert.IsTrue (zmc.Equals (copy), "Equals-1");
+ Assert.IsTrue (copy.Equals (zmc), "Equals-2");
+ Assert.IsFalse (Object.ReferenceEquals (zmc, copy), "!ReferenceEquals");
+ Assert.IsFalse (zmc.Equals (null), "Equals-3");
+ Assert.IsFalse (zmc.Equals (wrongEvidence), "Equals-4");
+
+ SecurityElement se = zmc.ToXml ();
+ copy.FromXml (se);
+ Assert.IsTrue (zmc.Equals (copy), "Equals-5");
+ Assert.AreEqual (se.ToString (), zmc.ToXml (null).ToString (), "Equals-6");
+
+ Assert.IsTrue (zmc.ToString ().StartsWith ("Zone - "), "ToString-1");
+ Assert.IsTrue (zmc.ToString ().EndsWith (zmc.SecurityZone.ToString ()), "ToString-2");
+
+ Assert.AreEqual (zmc.SecurityZone.GetHashCode (), zmc.GetHashCode (), "GetHashCode");
+
+ return zmc; // for further tests
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ZoneMembershipCondition_Invalid ()
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition ((SecurityZone)128);
+ }
+
+ [Test]
+ public void ZoneMembershipCondition_Internet ()
+ {
+ ZoneMembershipCondition zmc = BasicTest (SecurityZone.Internet);
+ Assert.IsTrue (zmc.Check (hostInternet), "Check(hostInternet)");
+ Assert.IsFalse (zmc.Check (hostIntranet), "Check(hostIntranet)");
+ Assert.IsFalse (zmc.Check (hostMyComputer), "Check(hostMyComputer)");
+ Assert.IsFalse (zmc.Check (hostNoZone), "Check(hostNoZone)");
+ Assert.IsFalse (zmc.Check (hostTrusted), "Check(hostTrusted)");
+ Assert.IsFalse (zmc.Check (hostUntrusted), "Check(hostUntrusted)");
+ Assert.IsFalse (zmc.Check (assemblyInternet), "Check(assemblyInternet)");
+ Assert.IsFalse (zmc.Check (assemblyIntranet), "Check(assemblyIntranet)");
+ Assert.IsFalse (zmc.Check (assemblyMyComputer), "Check(assemblyMyComputer)");
+ Assert.IsFalse (zmc.Check (assemblyNoZone), "Check(assemblyNoZone)");
+ Assert.IsFalse (zmc.Check (assemblyTrusted), "Check(assemblyTrusted)");
+ Assert.IsFalse (zmc.Check (assemblyUntrusted), "Check(assemblyUntrusted)");
+ }
+
+ [Test]
+ public void ZoneMembershipCondition_Intranet ()
+ {
+ ZoneMembershipCondition zmc = BasicTest (SecurityZone.Intranet);
+ Assert.IsFalse (zmc.Check (hostInternet), "Check(hostInternet)");
+ Assert.IsTrue (zmc.Check (hostIntranet), "Check(hostIntranet)");
+ Assert.IsFalse (zmc.Check (hostMyComputer), "Check(hostMyComputer)");
+ Assert.IsFalse (zmc.Check (hostNoZone), "Check(hostNoZone)");
+ Assert.IsFalse (zmc.Check (hostTrusted), "Check(hostTrusted)");
+ Assert.IsFalse (zmc.Check (hostUntrusted), "Check(hostUntrusted)");
+ Assert.IsFalse (zmc.Check (assemblyInternet), "Check(assemblyInternet)");
+ Assert.IsFalse (zmc.Check (assemblyIntranet), "Check(assemblyIntranet)");
+ Assert.IsFalse (zmc.Check (assemblyMyComputer), "Check(assemblyMyComputer)");
+ Assert.IsFalse (zmc.Check (assemblyNoZone), "Check(assemblyNoZone)");
+ Assert.IsFalse (zmc.Check (assemblyTrusted), "Check(assemblyTrusted)");
+ Assert.IsFalse (zmc.Check (assemblyUntrusted), "Check(assemblyUntrusted)");
+ }
+
+ [Test]
+ public void ZoneMembershipCondition_MyComputer ()
+ {
+ ZoneMembershipCondition zmc = BasicTest (SecurityZone.MyComputer);
+ Assert.IsFalse (zmc.Check (hostInternet), "Check(hostInternet)");
+ Assert.IsFalse (zmc.Check (hostIntranet), "Check(hostIntranet)");
+ Assert.IsTrue (zmc.Check (hostMyComputer), "Check(hostMyComputer)");
+ Assert.IsFalse (zmc.Check (hostNoZone), "Check(hostNoZone)");
+ Assert.IsFalse (zmc.Check (hostTrusted), "Check(hostTrusted)");
+ Assert.IsFalse (zmc.Check (hostUntrusted), "Check(hostUntrusted)");
+ Assert.IsFalse (zmc.Check (assemblyInternet), "Check(assemblyInternet)");
+ Assert.IsFalse (zmc.Check (assemblyIntranet), "Check(assemblyIntranet)");
+ Assert.IsFalse (zmc.Check (assemblyMyComputer), "Check(assemblyMyComputer)");
+
+ Assert.IsFalse (zmc.Check (assemblyNoZone), "Check(assemblyNoZone)");
+ Assert.IsFalse (zmc.Check (assemblyTrusted), "Check(assemblyTrusted)");
+ Assert.IsFalse (zmc.Check (assemblyUntrusted), "Check(assemblyUntrusted)");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void ZoneMembershipCondition_NoZone ()
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition (SecurityZone.NoZone);
+ }
+
+ [Test]
+ public void ZoneMembershipCondition_Trusted ()
+ {
+ ZoneMembershipCondition zmc = BasicTest (SecurityZone.Trusted);
+ Assert.IsFalse (zmc.Check (hostInternet), "Check(hostInternet)");
+ Assert.IsFalse (zmc.Check (hostIntranet), "Check(hostIntranet)");
+ Assert.IsFalse (zmc.Check (hostMyComputer), "Check(hostMyComputer)");
+ Assert.IsFalse (zmc.Check (hostNoZone), "Check(hostNoZone)");
+ Assert.IsTrue (zmc.Check (hostTrusted), "Check(hostTrusted)");
+ Assert.IsFalse (zmc.Check (hostUntrusted), "Check(hostUntrusted)");
+ Assert.IsFalse (zmc.Check (assemblyInternet), "Check(assemblyInternet)");
+ Assert.IsFalse (zmc.Check (assemblyIntranet), "Check(assemblyIntranet)");
+ Assert.IsFalse (zmc.Check (assemblyMyComputer), "Check(assemblyMyComputer)");
+ Assert.IsFalse (zmc.Check (assemblyNoZone), "Check(assemblyNoZone)");
+ Assert.IsFalse (zmc.Check (assemblyTrusted), "Check(assemblyTrusted)");
+ Assert.IsFalse (zmc.Check (assemblyUntrusted), "Check(assemblyUntrusted)");
+ }
+
+ [Test]
+ public void ZoneMembershipCondition_Untrusted ()
+ {
+ ZoneMembershipCondition zmc = BasicTest (SecurityZone.Untrusted);
+ Assert.IsFalse (zmc.Check (hostInternet), "Check(hostInternet)");
+ Assert.IsFalse (zmc.Check (hostIntranet), "Check(hostIntranet)");
+ Assert.IsFalse (zmc.Check (hostMyComputer), "Check(hostMyComputer)");
+ Assert.IsFalse (zmc.Check (hostNoZone), "Check(hostNoZone)");
+ Assert.IsFalse (zmc.Check (hostTrusted), "Check(hostTrusted)");
+ Assert.IsTrue (zmc.Check (hostUntrusted), "Check(hostUntrusted)");
+ Assert.IsFalse (zmc.Check (assemblyInternet), "Check(assemblyInternet)");
+ Assert.IsFalse (zmc.Check (assemblyIntranet), "Check(assemblyIntranet)");
+ Assert.IsFalse (zmc.Check (assemblyMyComputer), "Check(assemblyMyComputer)");
+ Assert.IsFalse (zmc.Check (assemblyNoZone), "Check(assemblyNoZone)");
+ Assert.IsFalse (zmc.Check (assemblyTrusted), "Check(assemblyTrusted)");
+ Assert.IsFalse (zmc.Check (assemblyUntrusted), "Check(assemblyUntrusted)");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void SecurityZone_NoZone ()
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition (SecurityZone.NoZone);
+ zmc.SecurityZone = SecurityZone.NoZone;
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void SecurityZone_Invalid ()
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition (SecurityZone.NoZone);
+ zmc.SecurityZone = (SecurityZone)128;
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void FromXmlNull ()
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition (SecurityZone.NoZone);
+ zmc.FromXml (null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void FromXmlInvalid ()
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition (SecurityZone.NoZone);
+ SecurityElement se = zmc.ToXml ();
+ se.Tag = "IMonoship";
+ zmc.FromXml (se);
+ }
+
+ [Test]
+ public void FromXmlPolicyLevel ()
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition (SecurityZone.MyComputer);
+ SecurityElement se = zmc.ToXml ();
+ // is it accepted for all policy levels ?
+ IEnumerator e = SecurityManager.PolicyHierarchy ();
+ while (e.MoveNext ()) {
+ PolicyLevel pl = e.Current as PolicyLevel;
+ ZoneMembershipCondition spl = new ZoneMembershipCondition (SecurityZone.Internet);
+ spl.FromXml (se, pl);
+ Assert.IsTrue (spl.Equals (zmc), "FromXml(PolicyLevel='" + pl.Label + "')");
+ }
+ // yes!
+ }
+
+ [Test]
+ public void ToXmlPolicyLevel ()
+ {
+ ZoneMembershipCondition zmc = new ZoneMembershipCondition (SecurityZone.MyComputer);
+ SecurityElement se = zmc.ToXml ();
+ string s = zmc.ToXml ().ToString ();
+ // is it accepted for all policy levels ?
+ IEnumerator e = SecurityManager.PolicyHierarchy ();
+ while (e.MoveNext ()) {
+ PolicyLevel pl = e.Current as PolicyLevel;
+ ZoneMembershipCondition spl = new ZoneMembershipCondition (SecurityZone.Internet);
+ spl.FromXml (se, pl);
+ Assert.AreEqual (s, spl.ToXml (pl).ToString (), "ToXml(PolicyLevel='" + pl.Label + "')");
+ }
+ // yes!
+ }
+ }
+}