Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,214 @@
//
// AllMembershipConditionTest.cs - NUnit Test Cases for AllMembershipCondition
//
// 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.Security;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class AllMembershipConditionTest {
[Test]
public void Constructor ()
{
AllMembershipCondition all = new AllMembershipCondition ();
Assert.IsNotNull (all);
}
[Test]
public void Check ()
{
AllMembershipCondition all = new AllMembershipCondition ();
Evidence e = null;
Assert.IsTrue (all.Check (e), "Check (null)");
e = new Evidence ();
Assert.IsTrue (all.Check (e), "Check (empty)");
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsTrue (all.Check (e), "Check (zone)");
Url u = new Url ("http://www.go-mono.com/");
e.AddAssembly (u);
Assert.IsTrue (all.Check (e), "Check (all-assembly)");
Site s = new Site ("www.go-mono.com");
e.AddHost (s);
Assert.IsTrue (all.Check (e), "Check (all-host)");
}
[Test]
public void Copy ()
{
AllMembershipCondition all = new AllMembershipCondition ();
AllMembershipCondition copy = (AllMembershipCondition)all.Copy ();
Assert.AreEqual (all, copy, "Equals");
Assert.IsFalse (Object.ReferenceEquals (all, copy), "ReferenceEquals");
}
[Test]
public void Equals ()
{
AllMembershipCondition all = new AllMembershipCondition ();
Assert.IsFalse (all.Equals (null), "Equals(null)");
AllMembershipCondition g2 = new AllMembershipCondition ();
Assert.IsTrue (all.Equals (g2), "Equals(g2)");
Assert.IsTrue (g2.Equals (all), "Equals(all)");
Assert.IsFalse (all.Equals (new object ()), "Equals (object)");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
AllMembershipCondition all = new AllMembershipCondition ();
all.FromXml (null);
}
[Test]
public void FromXml ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
all.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_InvalidTag ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
se.Tag = "IMonoship";
all.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongTagCase ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
se.Tag = "IMEMBERSHIPCONDITION"; // instead of IMembershipCondition
all.FromXml (se);
}
[Test]
public void FromXml_InvalidClass ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
se.Attributes ["class"] = "Hello world";
all.FromXml (se);
}
[Test]
public void FromXml_NoClass ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
all.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
public void FromXml_InvalidVersion ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("version", "2");
all.FromXml (w);
// doesn't seems to care about the version number!
}
[Test]
public void FromXml_NoVersion ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
all.FromXml (w);
}
[Test]
#if MOBILE
[Ignore]
#endif
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_SecurityElementNull ()
{
AllMembershipCondition all = new AllMembershipCondition ();
all.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
}
[Test]
public void FromXml_PolicyLevelNull ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
all.FromXml (se, null);
}
[Test]
public void GetHashCode_ ()
{
AllMembershipCondition all = new AllMembershipCondition ();
AllMembershipCondition copy = (AllMembershipCondition)all.Copy ();
Assert.AreEqual (all.GetHashCode (), copy.GetHashCode ());
}
[Test]
public void ToString_ ()
{
AllMembershipCondition all = new AllMembershipCondition ();
Assert.AreEqual ("All code", all.ToString ());
}
[Test]
#if MOBILE
[Ignore]
#endif
public void ToXml ()
{
AllMembershipCondition all = new AllMembershipCondition ();
SecurityElement se = all.ToXml ();
Assert.AreEqual ("IMembershipCondition", se.Tag, "Tag");
Assert.IsTrue (se.Attribute ("class").StartsWith ("System.Security.Policy.AllMembershipCondition"), "class");
Assert.AreEqual ("1", se.Attribute ("version"), "version");
Assert.AreEqual (se.ToString (), all.ToXml (null).ToString (), "ToXml(null)");
Assert.AreEqual (se.ToString (), all.ToXml (PolicyLevel.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");
}
}
}

View File

@ -0,0 +1,230 @@
//
// ApplicationDirectoryMembershipConditionTest.cs -
// NUnit Test Cases for ApplicationDirectoryMembershipCondition
//
// 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.Reflection;
using System.Security;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class ApplicationDirectoryMembershipConditionTest {
[Test]
public void Constructor ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
Assert.IsNotNull (ad);
}
[Test]
public void Check ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
Evidence e = null;
Assert.IsFalse (ad.Check (e), "Check (null)");
e = new Evidence ();
Assert.IsFalse (ad.Check (e), "Check (empty)");
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsFalse (ad.Check (e), "Check (zone)");
string codebase = Assembly.GetExecutingAssembly ().CodeBase;
Url u = new Url (codebase);
ApplicationDirectory adir = new ApplicationDirectory (codebase);
e.AddHost (u);
Assert.IsFalse (ad.Check (e), "Check (url-host)"); // not enough
e.AddAssembly (adir);
Assert.IsFalse (ad.Check (e), "Check (url-host+adir-assembly)");
e = new Evidence ();
e.AddHost (adir);
Assert.IsFalse (ad.Check (e), "Check (adir-host)"); // not enough
e.AddAssembly (u);
Assert.IsFalse (ad.Check (e), "Check (url-assembly+adir-host)");
e = new Evidence ();
e.AddHost (u);
e.AddHost (adir);
Assert.IsTrue (ad.Check (e), "Check (url+adir host)"); // both!!
}
[Test]
public void Copy ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
ApplicationDirectoryMembershipCondition copy = (ApplicationDirectoryMembershipCondition)ad.Copy ();
Assert.AreEqual (ad, copy, "Equals");
Assert.IsFalse (Object.ReferenceEquals (ad, copy), "ReferenceEquals");
}
[Test]
public void Equals ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
Assert.IsFalse (ad.Equals (null), "Equals(null)");
ApplicationDirectoryMembershipCondition g2 = new ApplicationDirectoryMembershipCondition ();
Assert.IsTrue (ad.Equals (g2), "Equals(g2)");
Assert.IsTrue (g2.Equals (ad), "Equals(ad)");
Assert.IsFalse (ad.Equals (new object ()), "Equals (object)");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
ad.FromXml (null);
}
[Test]
public void FromXml ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
ad.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_InvalidTag ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
se.Tag = "IMonoship";
ad.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongTagCase ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
se.Tag = "IMEMBERSHIPCONDITION"; // instead of IMembershipCondition
ad.FromXml (se);
}
[Test]
public void FromXml_InvalidClass ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
se.Attributes ["class"] = "Hello world";
ad.FromXml (se);
}
[Test]
public void FromXml_NoClass ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
ad.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
public void FromXml_InvalidVersion ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("version", "2");
ad.FromXml (w);
// doesn't seems to care about the version number!
}
[Test]
public void FromXml_NoVersion ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
ad.FromXml (w);
}
[Test]
#if MOBILE
[Ignore]
#endif
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_SecurityElementNull ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
ad.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
}
[Test]
public void FromXml_PolicyLevelNull ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
ad.FromXml (se, null);
}
[Test]
public void GetHashCode_ ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
ApplicationDirectoryMembershipCondition copy = (ApplicationDirectoryMembershipCondition)ad.Copy ();
Assert.AreEqual (ad.GetHashCode (), copy.GetHashCode ());
}
[Test]
public void ToString_ ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
Assert.AreEqual ("ApplicationDirectory", ad.ToString ());
}
[Test]
#if MOBILE
[Ignore]
#endif
public void ToXml ()
{
ApplicationDirectoryMembershipCondition ad = new ApplicationDirectoryMembershipCondition ();
SecurityElement se = ad.ToXml ();
Assert.AreEqual ("IMembershipCondition", se.Tag, "Tag");
Assert.IsTrue (se.Attribute ("class").StartsWith ("System.Security.Policy.ApplicationDirectoryMembershipCondition"), "class");
Assert.AreEqual ("1", se.Attribute ("version"), "version");
Assert.AreEqual (se.ToString (), ad.ToXml (null).ToString (), "ToXml(null)");
Assert.AreEqual (se.ToString (), ad.ToXml (PolicyLevel.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");
}
}
}

View File

@ -0,0 +1,191 @@
//
// ApplicationDirectoryTest.cs - NUnit Test Cases for ApplicationDirectory
//
// 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.IO;
using System.Security.Policy;
using System.Text;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class ApplicationDirectoryTest {
private string Invalid (bool exception)
{
StringBuilder sb = new StringBuilder ();
foreach (char c in Path.InvalidPathChars)
sb.Append (c);
if ((exception) && (sb.Length < 1))
throw new ArgumentException ("no invalid chars");
return sb.ToString ();
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ApplicationDirectory_Null ()
{
new ApplicationDirectory (null);
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ApplicationDirectory_Empty ()
{
new ApplicationDirectory (String.Empty);
}
[Test]
#if !NET_2_0
[ExpectedException (typeof (ArgumentException))]
#endif
public void ApplicationDirectory_Invalid ()
{
new ApplicationDirectory (Invalid (false));
}
[Test]
public void ApplicationDirectory_String ()
{
ApplicationDirectory ad = new ApplicationDirectory ("mono");
#if NET_2_0
Assert.AreEqual ("mono", ad.Directory, "Directory");
#else
Assert.AreEqual ("file://MONO", ad.Directory, "Directory");
#endif
}
[Test]
public void ApplicationDirectory_FileUrl ()
{
ApplicationDirectory ad = new ApplicationDirectory ("file://MONO");
Assert.AreEqual ("file://MONO", ad.Directory, "Directory");
}
[Test]
public void ApplicationDirectory_HttpUrl ()
{
ApplicationDirectory ad = new ApplicationDirectory ("http://www.go-mono.com/");
Assert.AreEqual ("http://www.go-mono.com/", ad.Directory, "Directory");
}
[Test]
public void Copy ()
{
ApplicationDirectory ad = new ApplicationDirectory ("novell");
#if NET_2_0
Assert.AreEqual ("novell", ad.Directory, "Directory");
#else
Assert.AreEqual ("file://NOVELL", ad.Directory, "Directory");
#endif
ApplicationDirectory copy = (ApplicationDirectory)ad.Copy ();
Assert.IsTrue (ad.Equals (copy), "ad.Equals(copy)");
Assert.IsTrue (copy.Equals (ad), "copy.Equals(ad)");
Assert.IsFalse (Object.ReferenceEquals (ad, copy), "Copy");
Assert.AreEqual (ad.GetHashCode (), copy.GetHashCode (), "GetHashCode");
Assert.AreEqual (ad.ToString (), copy.ToString (), "ToString");
}
[Test]
public void Equals ()
{
ApplicationDirectory ad1 = new ApplicationDirectory ("mono");
Assert.IsFalse (ad1.Equals (null), "Equals(null)");
Assert.IsFalse (ad1.Equals (String.Empty), "Equals(String.Empty)");
Assert.IsFalse (ad1.Equals ("mono"), "Equals(mono)");
Assert.IsTrue (ad1.Equals (ad1), "Equals(self)");
ApplicationDirectory ad2 = new ApplicationDirectory (ad1.Directory);
Assert.IsTrue (ad1.Equals (ad2), "Equals(ad2)");
Assert.IsTrue (ad2.Equals (ad1), "Equals(ad2)");
ApplicationDirectory ad3 = new ApplicationDirectory ("..");
Assert.IsFalse (ad2.Equals (ad3), "Equals(ad3)");
}
[Test]
public void GetHashCode_ ()
{
string linux = "/unix/path/mono";
ApplicationDirectory ad1 = new ApplicationDirectory (linux);
#if NET_2_0
Assert.AreEqual (linux, ad1.Directory);
Assert.AreEqual (linux.GetHashCode (), ad1.GetHashCode (), "GetHashCode-Linux");
#else
Assert.AreEqual ("file://UNIX/PATH/mono", ad1.Directory);
Assert.AreEqual ("file://UNIX/PATH/mono".GetHashCode (), ad1.GetHashCode (), "GetHashCode-Linux");
#endif
string windows = "\\windows\\path\\mono";
ApplicationDirectory ad2 = new ApplicationDirectory (windows);
#if NET_2_0
Assert.AreEqual (windows, ad2.Directory);
Assert.AreEqual (windows.GetHashCode (), ad2.GetHashCode (), "GetHashCode-Windows");
#else
Assert.AreEqual ("file://WINDOWS/PATH/mono", ad2.Directory);
Assert.AreEqual ("file://WINDOWS/PATH/mono".GetHashCode (), ad2.GetHashCode (), "GetHashCode-Windows");
#endif
}
[Test]
public void ToString_ ()
{
ApplicationDirectory ad = new ApplicationDirectory ("file://MONO");
string ts = ad.ToString ();
Assert.IsTrue (ts.StartsWith ("<System.Security.Policy.ApplicationDirectory"), "Tag");
Assert.IsTrue (ts.IndexOf ("version=\"1\"") > 0, "Directory");
Assert.IsTrue (ts.IndexOf ("<Directory>file://MONO</Directory>") > 0, "Directory");
}
#if NET_2_0
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Equals_Invalid ()
{
// funny one
string appdir = Invalid (true);
// constructor is ok with an invalid path...
ApplicationDirectory ad = new ApplicationDirectory (appdir);
// we can copy it...
ApplicationDirectory copy = (ApplicationDirectory)ad.Copy ();
// we can't get it's hash code
Assert.AreEqual (appdir.GetHashCode (), ad.GetHashCode (), "GetHashCode");
// we can convert it to string...
Assert.IsTrue (ad.ToString ().IndexOf (appdir) > 0, "ToString");
// ... but it throws in Equals - with self!
Assert.IsTrue (ad.Equals (ad), "Equals(self)");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ToString_Invalid ()
{
new ApplicationDirectory (Invalid (true)).ToString ();
}
#endif
}
}

View File

@ -0,0 +1,162 @@
//
// ApplicationSecurityManagerCas.cs -
// CAS unit tests for System.Security.Policy.ApplicationSecurityManager
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Collections;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoCasTests.System.Security.Policy {
[TestFixture]
[Category ("CAS")]
public class ApplicationSecurityManagerCas {
private string defaultTrustManagerTypeName;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
defaultTrustManagerTypeName = ApplicationSecurityManager.ApplicationTrustManager.GetType ().AssemblyQualifiedName;
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void ApplicationTrustManager_DenyControlPolicy ()
{
Assert.IsNotNull (ApplicationSecurityManager.ApplicationTrustManager);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlPolicy = true)]
public void ApplicationTrustManager_PermitOnlyControlPolicy ()
{
Assert.IsNotNull (ApplicationSecurityManager.ApplicationTrustManager);
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void UserApplicationTrusts_DenyControlPolicy ()
{
// no security requirements documented
Assert.AreEqual (0, ApplicationSecurityManager.UserApplicationTrusts.Count);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlPolicy = true)]
public void UserApplicationTrusts_PermitOnlyControlPolicy ()
{
// no security requirements documented
Assert.IsNotNull (ApplicationSecurityManager.UserApplicationTrusts);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NullReferenceException))]
public void DetermineApplicationTrust_DenyUnrestricted ()
{
// documented as requiring ControlPolicy and ControlEvidence
// possibly a linkdemand as only ControlPolicy seems check by the default
// IApplicationTrustManager
ApplicationSecurityManager.DetermineApplicationTrust (null, null);
}
// default trust manager
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void DefaultTrustManager_DetermineApplicationTrust_DenyControlPolicy ()
{
ApplicationSecurityManager.ApplicationTrustManager.DetermineApplicationTrust (null, null);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlPolicy = true)]
[ExpectedException (typeof (ArgumentNullException))]
public void DefaultTrustManager_DetermineApplicationTrust_PermitOnlyControlPolicy ()
{
ApplicationSecurityManager.ApplicationTrustManager.DetermineApplicationTrust (null, null);
}
private void CheckXml (SecurityElement se)
{
Assert.AreEqual (defaultTrustManagerTypeName, se.Attribute ("class"), "class");
Assert.AreEqual ("1", se.Attribute ("version"), "version");
Assert.AreEqual (2, se.Attributes.Count, "Count");
Assert.IsNull (se.Children, "Children");
}
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
private void CheckFromXml (IApplicationTrustManager atm)
{
SecurityElement se = new SecurityElement ("IApplicationTrustManager");
se.AddAttribute ("class", defaultTrustManagerTypeName);
se.AddAttribute ("version", "1");
atm.FromXml (se);
// accepted
CheckXml (atm.ToXml ());
}
[Test]
public void DefaultTrustManager_FromXml ()
{
CheckFromXml (ApplicationSecurityManager.ApplicationTrustManager);
}
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void CheckToXml (IApplicationTrustManager atm)
{
CheckXml (atm.ToXml ());
}
[Test]
public void DefaultTrustManager_ToXml ()
{
CheckToXml (ApplicationSecurityManager.ApplicationTrustManager);
}
}
}
#endif

View File

@ -0,0 +1,172 @@
//
// ApplicationSecurityManagerTest.cs -
// NUnit Test Cases for ApplicationSecurityManager
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Collections;
using System.Security;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class ApplicationSecurityManagerTest {
private string defaultTrustManagerTypeName;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
defaultTrustManagerTypeName = ApplicationSecurityManager.ApplicationTrustManager.GetType ().AssemblyQualifiedName;
}
[Test]
public void ApplicationTrustManager ()
{
Assert.IsNotNull (ApplicationSecurityManager.ApplicationTrustManager);
}
[Test]
public void UserApplicationTrusts ()
{
Assert.AreEqual (0, ApplicationSecurityManager.UserApplicationTrusts.Count);
}
// FIXME: creating an ActivationContext here seems not easy
[Test]
// [ExpectedException (typeof (ArgumentNullException))]
[ExpectedException (typeof (NullReferenceException))]
public void DetermineApplicationTrust_Null_Null ()
{
ApplicationSecurityManager.DetermineApplicationTrust (null, null);
}
[Test]
// [ExpectedException (typeof (ArgumentNullException))]
[ExpectedException (typeof (NullReferenceException))]
public void DetermineApplicationTrust_Null_TrustManagerContext ()
{
ApplicationSecurityManager.DetermineApplicationTrust (null, new TrustManagerContext ());
}
// testing the default application security manager here
// FIXME: creating an ActivationContext here seems not easy
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void DefaultTrustManager_DetermineApplicationTrust_Null_Null ()
{
ApplicationSecurityManager.ApplicationTrustManager.DetermineApplicationTrust (null, null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void DefaultTrustManager_DetermineApplicationTrust_Null_TrustManagerContext ()
{
ApplicationSecurityManager.ApplicationTrustManager.DetermineApplicationTrust (null, new TrustManagerContext ());
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void DefaultTrustManager_FromXml_Null ()
{
ApplicationSecurityManager.ApplicationTrustManager.FromXml (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DefaultTrustManager_FromXml_BadTag ()
{
SecurityElement se = new SecurityElement (String.Empty);
ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
}
private void CheckXml (SecurityElement se)
{
Assert.AreEqual (defaultTrustManagerTypeName, se.Attribute ("class"), "class");
Assert.AreEqual ("1", se.Attribute ("version"), "version");
Assert.AreEqual (2, se.Attributes.Count, "Count");
Assert.IsNull (se.Children, "Children");
}
[Test]
public void DefaultTrustManager_FromXml_NoAttributes ()
{
SecurityElement se = new SecurityElement ("IApplicationTrustManager");
ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
// accepted
CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
}
[Test]
public void DefaultTrustManager_FromXml_BadClass ()
{
SecurityElement se = new SecurityElement ("IApplicationTrustManager");
se.AddAttribute ("class", "System.DoesntExist");
se.AddAttribute ("version", "1");
ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
// accepted
CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
}
[Test]
public void DefaultTrustManager_FromXml_BadVersion ()
{
SecurityElement se = new SecurityElement ("IApplicationTrustManager");
se.AddAttribute ("class", defaultTrustManagerTypeName);
se.AddAttribute ("version", "42");
ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
// accepted
CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
}
[Test]
public void DefaultTrustManager_FromXml ()
{
SecurityElement se = new SecurityElement ("IApplicationTrustManager");
se.AddAttribute ("class", defaultTrustManagerTypeName);
se.AddAttribute ("version", "1");
ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
// accepted
CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
}
[Test]
public void DefaultTrustManager_ToXml ()
{
CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
}
}
}
#endif

View File

@ -0,0 +1,258 @@
//
// ApplicationTrustTest.cs - NUnit tests for ApplicationTrust
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class ApplicationTrustTest {
private string AdjustLineEnds (string s)
{
return s.Replace ("\r\n", "\n");
}
[Test]
public void Constructor_Empty ()
{
ApplicationTrust at = new ApplicationTrust ();
Assert.IsNull (at.ApplicationIdentity, "ApplicationIdentity");
Assert.AreEqual (PolicyStatementAttribute.Nothing, at.DefaultGrantSet.Attributes, "DefaultGrantSet.Attributes");
Assert.AreEqual (String.Empty, at.DefaultGrantSet.AttributeString, "DefaultGrantSet.AttributeString");
Assert.IsTrue (at.DefaultGrantSet.PermissionSet.IsEmpty (), "DefaultGrantSet.PermissionSet.IsEmpty");
Assert.IsFalse (at.DefaultGrantSet.PermissionSet.IsUnrestricted (), "DefaultGrantSet.PermissionSet.IsUnrestricted");
Assert.IsNull (at.ExtraInfo, "ExtraInfo");
Assert.IsFalse (at.IsApplicationTrustedToRun, "IsApplicationTrustedToRun");
Assert.IsFalse (at.Persist, "Persist");
string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_Null ()
{
ApplicationTrust at = new ApplicationTrust (null);
}
[Test]
public void ApplicationIdentity ()
{
ApplicationTrust at = new ApplicationTrust ();
at.ApplicationIdentity = new ApplicationIdentity ("Mono Unit Test");
Assert.IsNotNull (at.ApplicationIdentity, "not null");
string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\"\r\nFullName=\"Mono Unit Test, Culture=neutral\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ApplicationIdentity_Null ()
{
ApplicationTrust at = new ApplicationTrust ();
at.ApplicationIdentity = new ApplicationIdentity ("Mono Unit Test");
// once set it cannot be "unset" ...
at.ApplicationIdentity = null;
}
[Test]
public void ApplicationIdentity_Change ()
{
ApplicationTrust at = new ApplicationTrust ();
at.ApplicationIdentity = new ApplicationIdentity ("Mono Unit Test");
// ... but it can be changed
at.ApplicationIdentity = new ApplicationIdentity ("Mono Unit Test Too");
}
[Test]
public void DefaultGrantSet ()
{
ApplicationTrust at = new ApplicationTrust ();
at.DefaultGrantSet = new PolicyStatement (new PermissionSet (PermissionState.Unrestricted));
Assert.IsNotNull (at.DefaultGrantSet, "not null");
string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"\r\nUnrestricted=\"true\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
at.DefaultGrantSet = null;
// returns to defaults
Assert.IsNotNull (at.DefaultGrantSet, "null");
Assert.AreEqual (PolicyStatementAttribute.Nothing, at.DefaultGrantSet.Attributes, "DefaultGrantSet.Attributes");
Assert.AreEqual (String.Empty, at.DefaultGrantSet.AttributeString, "DefaultGrantSet.AttributeString");
Assert.IsTrue (at.DefaultGrantSet.PermissionSet.IsEmpty (), "DefaultGrantSet.PermissionSet.IsEmpty");
Assert.IsFalse (at.DefaultGrantSet.PermissionSet.IsUnrestricted (), "DefaultGrantSet.PermissionSet.IsUnrestricted");
}
[Test]
public void ExtraInfo ()
{
ApplicationTrust at = new ApplicationTrust ();
at.ExtraInfo = "Mono";
Assert.IsNotNull (at.ExtraInfo, "not null");
string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n<ExtraInfo Data=\"0001000000FFFFFFFF01000000000000000601000000044D6F6E6F0B\"/>\r\n</ApplicationTrust>\r\n");
Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
at.ExtraInfo = null;
Assert.IsNull (at.ExtraInfo, "null");
}
[Test]
[ExpectedException (typeof (SerializationException))]
public void ExtraInfo_NotSerializable ()
{
ApplicationTrust at = new ApplicationTrust ();
at.ExtraInfo = this;
SecurityElement se = at.ToXml ();
}
[Test]
public void IsApplicationTrustedToRun ()
{
ApplicationTrust at = new ApplicationTrust ();
at.IsApplicationTrustedToRun = true;
Assert.IsTrue (at.IsApplicationTrustedToRun);
string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\"\r\nTrustedToRun=\"true\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
at.IsApplicationTrustedToRun = false;
Assert.IsFalse (at.IsApplicationTrustedToRun);
}
[Test]
public void Persist ()
{
ApplicationTrust at = new ApplicationTrust ();
at.Persist = true;
Assert.IsTrue (at.Persist, "true");
string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\"\r\nPersist=\"true\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n</ApplicationTrust>\r\n");
Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
at.Persist = false;
Assert.IsFalse (at.Persist, "false");
}
[Test]
public void ToFromXmlRoundtrip ()
{
ApplicationTrust at = new ApplicationTrust ();
at.ApplicationIdentity = new ApplicationIdentity ("Mono Unit Test");
at.DefaultGrantSet = new PolicyStatement (new PermissionSet (PermissionState.Unrestricted));
at.ExtraInfo = "Mono";
at.IsApplicationTrustedToRun = true;
at.Persist = true;
SecurityElement se = at.ToXml ();
string expected = AdjustLineEnds ("<ApplicationTrust version=\"1\"\r\nFullName=\"Mono Unit Test, Culture=neutral\"\r\nTrustedToRun=\"true\"\r\nPersist=\"true\">\r\n<DefaultGrant>\r\n<PolicyStatement version=\"1\">\r\n<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\"\r\nUnrestricted=\"true\"/>\r\n</PolicyStatement>\r\n</DefaultGrant>\r\n<ExtraInfo Data=\"0001000000FFFFFFFF01000000000000000601000000044D6F6E6F0B\"/>\r\n</ApplicationTrust>\r\n");
Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "XML");
ApplicationTrust copy = new ApplicationTrust ();
copy.FromXml (se);
se = copy.ToXml ();
Assert.AreEqual (expected, AdjustLineEnds (at.ToXml ().ToString ()), "Copy");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
ApplicationTrust at = new ApplicationTrust ();
at.FromXml (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_InvalidTag ()
{
ApplicationTrust at = new ApplicationTrust ();
SecurityElement se = at.ToXml ();
se.Tag = "MonoTrust";
at.FromXml (se);
}
[Test]
public void FromXml_InvalidVersion ()
{
ApplicationTrust at = new ApplicationTrust ();
SecurityElement se = at.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", "2");
foreach (SecurityElement child in se.Children)
w.AddChild (child);
at.FromXml (w);
}
[Test]
public void FromXml_NoVersion ()
{
ApplicationTrust at = new ApplicationTrust ();
SecurityElement se = at.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
foreach (SecurityElement child in se.Children)
w.AddChild (child);
at.FromXml (w);
}
[Test]
public void FromXml_NoChild ()
{
ApplicationTrust at = new ApplicationTrust ();
SecurityElement se = at.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", "1");
at.FromXml (w);
Assert.IsNull (at.ApplicationIdentity, "ApplicationIdentity");
Assert.AreEqual (PolicyStatementAttribute.Nothing, at.DefaultGrantSet.Attributes, "DefaultGrantSet.Attributes");
Assert.AreEqual (String.Empty, at.DefaultGrantSet.AttributeString, "DefaultGrantSet.AttributeString");
Assert.IsTrue (at.DefaultGrantSet.PermissionSet.IsEmpty (), "DefaultGrantSet.PermissionSet.IsEmpty");
Assert.IsFalse (at.DefaultGrantSet.PermissionSet.IsUnrestricted (), "DefaultGrantSet.PermissionSet.IsUnrestricted");
Assert.IsNull (at.ExtraInfo, "ExtraInfo");
Assert.IsFalse (at.IsApplicationTrustedToRun, "IsApplicationTrustedToRun");
Assert.IsFalse (at.Persist, "Persist");
}
}
}
#endif

View File

@ -0,0 +1,315 @@
2009-06-26 Zoltan Varga <vargaz@gmail.com>
* *.cs: Convert all tests to new-style nunit classes/methods.
2006-01-09 Raja R Harinath <rharinath@novell.com>
* HashMembershipConditionTest.cs (HashValue): Remove 1/256 chance
of false negative.
2005-06-23 Sebastien Pouliot <sebastien@ximian.com>
* ApplicationSecurityManagerCas.cs: New. CAS unit tests (2.0).
* ApplicationSecurityManagerTest.cs: New. Unit tests (2.0).
2005-06-20 Sebastien Pouliot <sebastien@ximian.com>
* EvidenceTest.cs: Ensure that PermissionRequestEvidence doesn't
show in Assembly and AppDomain evidences.
2005-06-16 Sebastien Pouliot <sebastien@ximian.com>
* StrongNameTest.cs: Empty names are only verified in NET_2_0.
2005-06-10 Sebastien Pouliot <sebastien@ximian.com>
* StrongNameMembershipConditionTest.cs: New. Unit tests for
StrongNameMembershipCondition.
* StrongNameTest.cs: Added test case for empty name.
2005-05-26 Sebastien Pouliot <sebastien@ximian.com>
* PolicyLevelTest.cs: Added unit tests for RemovePermissionSet and
Recover methods.
2005-05-16 Sebastien Pouliot <sebastien@ximian.com>
* PolicyStatementTest.cs: New. Unit tests for PolicyStatement.
2005-04-26 Sebastien Pouliot <sebastien@ximian.com>
* ApplicationTrustTest.cs: New. Unit tests for ApplicationTrust (2.0).
2005-04-25 Sebastien Pouliot <sebastien@ximian.com>
* FileCodeGroupTest.cs: Revoved tests for Scope property (2.0).
* GacMembershipConditionTest.cs: Renamed Gac to GacInstalled (new name
* GacTest.cs: Renamed Gac to GacInstalled (new name in beta2).
in beta2).
* IBuiltInEvidenceTest.cs: Renamed Gac to GacInstalled (new name in
beta2).
* SiteTest.cs: Removed [Catogery("NotWorking")] from some 2.0 tests.
* UrlTest.cs: Removed [Catogery("NotWorking")] from some 2.0 tests.
* UrlMembershipConditionTest.cs: Removed [Catogery("NotWorking")] from
some 2.0 tests.
2005-03-18 Sebastien Pouliot <sebastien@ximian.com>
* PolicyLevelTest.cs: Remove non-corlib permission classes from the
policy XML string as this can fail for "make distcheck".
2005-02-16 Sebastien Pouliot <sebastien@ximian.com>
* PolicyLevelTest.cs: Renamed the file created by the StoreLocation
test case to include the username. This way multiple users sharing
/tmp cannot block the test execution (e.g. buildbot). Also tries to
remove the file after the test.
2005-01-31 Sebastien Pouliot <sebastien@ximian.com>
* HashTest.cs: Oops, changed "NotWorking" to "NotDotNet".
2005-01-30 Sebastien Pouliot <sebastien@ximian.com>
* HashTest.cs: Changed [Ignore] to [Category("NotWorking")] to reduce
nunit logs.
2005-01-10 Sebastien Pouliot <sebastien@ximian.com>
* PolicyLevelTest.cs: Removed [Ignore] from tests as they now execute
properly on 2.0. For 1.x the tests are added to the NotDotNet category.
2004-09-19 Alexis Christoforides <alexis@thenull.net>
* UnionCodeGroupTest.cs: Added ResolveWithChildren test.
2004-09-01 Sebastien Pouliot <sebastien@ximian.com>
* HashTest.cs: Fixed tests so they execute without errors on both
Fx 1.1 and Fx 2.0 (beta 1).
* PublisherTest.cs: Fixed tests so they execute without errors on both
Fx 1.1 and Fx 2.0 (beta 1). Converted tests to NUnit 2.2 format.
* SiteTest.cs: Fixed tests so they execute without errors on both Fx
1.1 and Fx 2.0 (beta 1).
* StrongNameTest.cs: Fixed tests so they execute without errors on
both Fx 1.1 and Fx 2.0 (beta 1). Converted tests to NUnit 2.2 format.
* UrlTest.cs: Fixed tests so they execute without errors on both Fx
1.1 and Fx 2.0 (beta 1). Converted tests to NUnit 2.2 format.
2004-09-01 Sebastien Pouliot <sebastien@ximian.com>
* ZoneTest.cs: Added test to check that NoZone isn't included in the
permission XML (returned by CreateIdentityPermission).
2004-08-30 Sebastien Pouliot <sebastien@ximian.com>
* SiteTest.cs: Added tests for CreateFromUrl. Updated AllChars for the
differences in Fx 2.0.
* UrlTest.cs: Unignore Url_InvalidSite and started changes to be
compatible with NET_2_0.
* ZoneTest.cs: Added tests for CreateFromUrl and ToString.
2004-08-26 Sebastien Pouliot <sebastien@ximian.com>
* ApplicationDirectoryTest.cs: New. For NET_2_0 profile.
* EvidenceTest.cs: Added more tests for 1.1 and new tests for 2.0.
* FileCodeGroupTest.cs: Added more tests for Resolve,
ResolveMatchingCodeGroups and new Fx 2.0 Scope property.
* HashMembershipConditionTest.cs: New. Unit tests for hash membership.
* HashTest.cs: New. Unit tests for hash.
* IBuiltInEvidenceTest.cs: New. Unit tests for the internal
IBuiltInEvidence interface. All tests are [Ignore]d for the
* NetCodeGroupTest.cs: Ajusted PermissionSetName for Fx 2.0.
* PermissionRequestEvidenceTest.cs: Ajusted existing tests for 2.0.
Converted tests to NUnit 2.2 format. Converted to UNIX line endings.
Added test to see that the original permission sets are copied but
the instance copy can be changed (not copied on output).
* PolicyLevelTest.cs: Added more tests for Resolve and
ResolveMatchingCodeGroups.
* UnionCodeGroupTest.cs: Added more properties validation in tests.
2004-08-24 Sebastien Pouliot <sebastien@ximian.com>
* AllMembershipConditionTest.cs: Renamed GetHashCode and
ToString tests to remove compiler warnings.
* ApplicationDirectoryMembershipConditionTest.cs: Renamed GetHashCode
and ToString tests to remove compiler warnings.
* ApplicationMembershipConditionTest.cs: Renamed GetHashCode and
ToString tests to remove compiler warnings.
* DomainApplicationMembershipConditionTest.cs: Renamed GetHashCode and
ToString tests to remove compiler warnings.
* GacMembershipConditionTest.cs: Added some new unit tests for
FromXml to match other *MembershipCondition classes.
* PublisherMembershipConditionTest.cs: Renamed GetHashCode and
ToString tests to remove compiler warnings.
* SiteMembershipConditionTest.cs: Completed. Converted existing unit
tests to NUnit 2.2 format.
* UrlMembershipConditionTest.cs: Completed. Converted existing unit
tests to NUnit 2.2 format.
* ZoneMembershipConditionTest.cs: Added some new unit tests to match
other *MembershipCondition classes.
2004-08-23 Sebastien Pouliot <sebastien@ximian.com>
* AllMembershipConditionTest.cs: New. Unit tests in NUnit 2.2 format.
* ApplicationDirectoryMembershipConditionTest.cs: New. Unit tests in
NUnit 2.2 format.
* ApplicationMembershipConditionTest.cs: New. Unit tests in NUnit 2.2
format.
* DomainApplicationMembershipConditionTest.cs: New. Unit tests in
NUnit 2.2 format.
* PublisherMembershipConditionTest.cs: Completed. Converted
existing unit tests to NUnit 2.2 format.
2004-08-12 Sebastien Pouliot <sebastien@ximian.com>
* ZoneMembershipConditionTest.cs: Fixed tests that where failing too
soon, i.e. not where I expected them to ;).
* ZoneTest.cs: Added tests for Zone.Equals (null).
2004-08-11 Sebastien Pouliot <sebastien@ximian.com>
* UnionCodeGroupTest.cs: Added unit tests for Resolve. Converted
existing unit tests to NUnit 2.2 format.
2004-08-10 Sebastien Pouliot <sebastien@ximian.com>
* PolicyLevelTest.cs: Added new policy resolution tests (related to
Zone). Converted existing unit tests to NUnit 2.2 format.
2004-08-04 Sebastien Pouliot <sebastien@ximian.com>
* GacMembershipConditionTest.cs: New. Unit tests in NUnit 2.2 format.
* GacTest.cs: New. Unit tests in NUnit 2.2 format.
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.
2004-05-20 Sebastien Pouliot <sebastien@ximian.com>
* PolicyLevelTest.cs, StrongNameTest.cs: SetUp is now public (required
for new nunit).
2004-02-09 Sebastien Pouliot <sebastien@ximian.com>
* PolicyLevelTest.cs: Ignored test Reset as the functionality isn't
yet present in Mono.
* UrlMembershipConditionTest.cs: Ignored the site related test as the
functionality isn't yet present in Mono.
* UrlTest.cs: Ignored the site related test as the functionality isn't
yet present in Mono.
2004-01-28 Sebastien Pouliot <spouliot@videotron.ca>
* PermissionRequestEvidenceTest.cs: Added ToString () assertions
to existing tests.
* PublisherMembershipConditionTest.cs: Replaced "\r\n" with
Environment.NewLine.
* StrongNameTest.cs: Replaced "\r\n" with Environment.NewLine.
2004-01-26 Sebastien Pouliot <spouliot@videotron.ca>
* CodeGroupTest.cs: Replaced "\r\n" with Environment.NewLine.
2004-01-25 David Sheldon <dave-mono@earth.li>
* UrlTest.cs: Changed "\r\n" in strings to use
Environment.NewLine.
2004-01-25 David Sheldon <dave-mono@earth.li>
* PublisherTest.cs, SiteTest.cs: Changed "\r\n" in strings to use
Environment.NewLine.
2004-01-14 Sebastien Pouliot <spouliot@videotron.ca>
* UrlTest.cs: New. Unit tests for Url. Site test still fails.
* UrlMembershipConditionTest.cs: New. Unit tests for
UrlMembershipCondition. Site test still fails.
2004-01-05 Sebastien Pouliot <spouliot@videotron.ca>
* CodeGroupTest.cs: Updated to NUnit2. Added new tests for exceptions
and for ToXml/FromXml methods.
* FileCodeGroupTest.cs: New. Unit tests for FileCodeGroup. Missing
Resolve unit tests.
* FirstMatchCodeGroupTest.cs: New. Unit tests for FirstMatchCodeGroup.
Missing Resolve unit tests.
* NetCodeGroupTest.cs: New. Unit tests for NetCodeGroup. Missing
Resolve unit tests.
* UnionCodeGroupTest.cs: New. Unit tests for NetCodeGroup. Missing
Resolve unit tests.
* PolicyLevelTest.cs: New. Unit tests for PolicyLevel. Missing Resolve
unit tests.
2004-01-03 Sebastien Pouliot <spouliot@videotron.ca>
* SiteTest.cs: New. Unit tests for Site.
* SiteMembershipConditionTest.cs: New. Implemented.
2004-01-02 Sebastien Pouliot <spouliot@videotron.ca>
* EvidenceTest.cs: Upgraded tests to NUnit2. Added new tests.
* StrongNameTest.cs: Class now inherits from Assertion.
2004-01-01 Nick Drochak <ndrochak@gol.com>
* PermissionRequestEvidenceTest.cs: New File
2003-12-15 Sebastien Pouliot <spouliot@videotron.ca>
* PublisherMembershipConditionTest.cs: Added new unit tests for the
newly implemented methods.
2003-07-03 Sebastien Pouliot <spouliot@videotron.ca>
* ZoneTest.cs: New. Test everything except the unimplemented static
CreateFromUrl method.
2003-04-23 Sebastien Pouliot <spouliot@videotron.ca>
* PublisherTest.cs: Updated to NUnit2 style.
* PublisherMembershipConditionTest.cs: Updated to NUnit2 style.
* StrongNameTest.cs: Updated to NUnit2 style.
2002-12-21 Nick Drochak <ndrochak@gol.com>
* all: make tests build and run under nunit2
2002-12-16 Sebastien Pouliot <spouliot@videotron.ca>
* AllTests.cs: Added test suites for StrongName.
* StrongNameTest.cs: New. Test suite for StrongName (complete).
2002-12-15 Sebastien Pouliot <spouliot@videotron.ca>
* AllTests.cs: Added test suites for Publisher and
PublisherMembershipCondition.
* PublisherTest.cs: New. Test suite for Publisher (complete).
* PublisherMembershipConditionTest.cs: New. Test suite for Publisher
PublisherMembershipCondition (incomplete).
2002-10-28 Jackson Harper <jackson@latitudegeo.com>
* AllTests.cs EvidenceTest.cs: Added test for Evidence class
2002-02-10 Nick Drochak <ndrochak@gol.com>
* AllTests.cs: Add new file.
2002-02-07 Nick Drochak <ndrochak@gol.com>
* CodeGroupTest.cs: Tests everything except the (To|From)Xml methods.
2002-02-01 Nick Drochak <ndrochak@gol.com>
* CodeGroupTest.cs: Still not done, checking in now just in case
2002-01-30 Nick Drochak <ndrochak@gol.com>
* CodeGroupTest.cs: New File. Not done, but checking in now just in case

View File

@ -0,0 +1,359 @@
//
// MonoTests.System.Security.Policy.CodeGroupTest
//
// Authors:
// Nick Drochak (ndrochak@gol.com)
// Sebastien Pouliot (spouliot@motus.com)
//
// (C) 2001 Nick Drochak, All rights reserved.
// Portions (C) 2004 Motus Technologies Inc. (http://www.motus.com)
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Security;
using System.Security.Policy;
using System.Security.Permissions;
namespace MonoTests.System.Security.Policy {
public class MyCodeGroup : CodeGroup {
public MyCodeGroup (IMembershipCondition membershipCondition, PolicyStatement policy)
: base (membershipCondition, policy) {}
public override CodeGroup Copy ()
{
return this;
}
public override string MergeLogic {
get { return ""; }
}
public override PolicyStatement Resolve (Evidence evidence)
{
return null;
}
public override CodeGroup ResolveMatchingCodeGroups (Evidence evidence)
{
return this;
}
}
// this version has a constructor with no parameters
public class MySecondCodeGroup : CodeGroup {
// must be public (else the ToFromXmlRoundtrip_WithChildren_Second will fail)
public MySecondCodeGroup () : base (new AllMembershipCondition (), null) {}
public MySecondCodeGroup (IMembershipCondition membershipCondition, PolicyStatement policy)
: base (membershipCondition, policy) {}
public override CodeGroup Copy () {
return this;
}
public override string MergeLogic {
get { return ""; }
}
public override PolicyStatement Resolve (Evidence evidence) {
return null;
}
public override CodeGroup ResolveMatchingCodeGroups (Evidence evidence) {
return this;
}
}
[TestFixture]
public class CodeGroupTest {
private const string ps_Name = "TestName";
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_MembershipConditionNullPolicyStatement ()
{
MyCodeGroup cg = new MyCodeGroup (null, new PolicyStatement(new PermissionSet(PermissionState.None)));
}
[Test]
public void Constructor_MembershipConditionPolicyStatementNull ()
{
// legal
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition(), null);
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
}
[Test]
public void Constructor ()
{
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition(), new PolicyStatement(new PermissionSet(PermissionState.None)));
Assert.IsNotNull (cg.PolicyStatement, "PolicyStatement property not set correctly by constructor.");
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition property not set correctly by constructor.");
}
[Test]
public void Description ()
{
const string description = "Test Description";
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition(), new PolicyStatement(new PermissionSet(PermissionState.None)));
cg.Description = description;
Assert.AreEqual (description, cg.Description, "Description not the expected value");
}
[Test]
public void Name ()
{
const string name = "Test Name";
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition(), new PolicyStatement(new PermissionSet(PermissionState.None)));
cg.Name = name;
Assert.AreEqual (name, cg.Name, "Description not the expected value");
}
[Test]
public void AddChild ()
{
MyCodeGroup cg = new MyCodeGroup(new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
Assert.AreEqual (0, cg.Children.Count, "Unexpected number of children (before add)");
cg.AddChild (new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.Unrestricted))));
Assert.AreEqual (1, cg.Children.Count, "Unexpected number of children (after add)");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void AddChild_Null ()
{
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
cg.AddChild (null);
}
[Test]
public void AttributeString ()
{
PolicyStatementAttribute psa = PolicyStatementAttribute.LevelFinal;
PolicyStatement ps = new PolicyStatement (new PermissionSet (PermissionState.None));
ps.Attributes = psa;
MyCodeGroup cg = new MyCodeGroup(new AllMembershipCondition (), ps);
Assert.AreEqual (psa.ToString(), cg.AttributeString, "AttributeString");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Children_Null ()
{
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
cg.Children = null;
}
[Test]
public void PermissionSetName ()
{
PolicyStatement ps = new PolicyStatement(new NamedPermissionSet (ps_Name));
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
Assert.AreEqual (ps_Name, cg.PermissionSetName, "PermissionSetName");
}
[Test]
public void Equals ()
{
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)");
Assert.IsTrue (!cg.Equals ("Not Equal to this"), "Equals (string)");
MyCodeGroup cg2 = new MyCodeGroup(new AllMembershipCondition(), ps);
cg2.Name = "SomeOtherName";
cg2.Description = "Some Other Description";
Assert.IsTrue (!cg.Equals (cg2), "Equals (another)");
cg2 = new MyCodeGroup (new ApplicationDirectoryMembershipCondition(), ps);
cg2.Name = cg.Name;
cg2.Description = cg.Description;
Assert.IsTrue (!cg.Equals (cg2), "Equals (different Membership Condition)");
}
[Test]
public void EqualsWithChildren ()
{
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);
MyCodeGroup cg2 = new MyCodeGroup (cg.MembershipCondition, cg.PolicyStatement);
cg2.Name = cg.Name;
cg2.Description = cg.Description;
Assert.IsTrue (cg.Equals (cg2), "Should be equal when Children are ignored");
Assert.IsTrue (!cg.Equals(cg2, true), "Should not be equal when Child count is different");
cg2.AddChild(cgChild);
Assert.IsTrue (cg2.Equals(cg, true), "Should be equal when children are equal");
}
[Test]
public void RemoveChild ()
{
PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), ps);
cg.Name = "SomeName";
cg.Description = "Some Description";
MyCodeGroup cgChild = new MyCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
cgChild.Name = "ChildName";
cgChild.Description = "Child Descripiton";
cg.AddChild (cgChild);
MyCodeGroup cgChild2 = new MyCodeGroup (new ApplicationDirectoryMembershipCondition (), ps);
cgChild2.Name = "ChildName2";
cgChild2.Description = "Child Descripiton 2";
cg.AddChild (cgChild2);
Assert.AreEqual (2, cg.Children.Count, "Should be two children before the call to Remove()");
cg.RemoveChild(cgChild);
Assert.AreEqual (1, cg.Children.Count, "Should be one children after the call to Remove()");
Assert.AreEqual("ChildName2", ((CodeGroup)cg.Children[0]).Name, "Remaining child does not have correct name");
}
[Test]
public void RemoveChild_NonExistant ()
{
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.AddChild (cgChild);
cg.RemoveChild (cgChild);
cg.RemoveChild (cgChild);
// no exception
}
[Test]
public void RemoveChild_Null ()
{
MyCodeGroup cg = new MyCodeGroup (new AllMembershipCondition (), new PolicyStatement(new PermissionSet (PermissionState.None)));
cg.RemoveChild (null);
// no exception
}
[Test]
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");
}
[Test]
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)");
}
[Test]
[ExpectedException (typeof (MissingMethodException))]
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)");
}
[Test]
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)");
}
[Test]
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)
}
} // public class CodeGroupTest
} // namespace MonoTests.System.Security.Policy

View File

@ -0,0 +1,369 @@
//
// MonoTests.System.Security.Policy.EvidenceTest
//
// Authors:
// Jackson Harper (Jackson@LatitudeGeo.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2001 Jackson Harper, All rights reserved.
// Portions (C) 2003, 2004 Motus Technologies Inc. (http://www.motus.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 System;
using System.Collections;
using System.Reflection;
using System.Security.Policy;
using NUnit.Framework;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class EvidenceTest {
[Test]
public void DefaultConstructor ()
{
Evidence evidence = new Evidence ();
Assert.AreEqual (evidence.Count, 0, "Default constructor count should be zero");
Assert.AreEqual (evidence.GetHostEnumerator().MoveNext(), false,
"Default constructor host enumerator MoveNext() should be false");
Assert.AreEqual (evidence.GetAssemblyEnumerator().MoveNext(), false,
"Default constructor assembly enumerator MoveNext() should be false");
Assert.AreEqual (evidence.GetEnumerator().MoveNext(), false,
"Default constructor enumerator MoveNext() should be false");
}
[Test]
public void MultipleConstructor ()
{
object[] hostarray = new object[10];
object[] assemarray = new object[10];
Evidence evidence = new Evidence ( hostarray, assemarray );
Assert.AreEqual (evidence.Count, 20,
"Count of multiple arg constructor should equal 20");
}
[Test]
public void CopyConstructor ()
{
object[] hostlist = { "host-1", "host-2", "host-3", "host-4" };
object[] asmblist = { "asmb-1", "asmb-2", "asmb-3", "asmb-4" };
Evidence evidence1 = new Evidence (hostlist, asmblist);
Evidence evidence2 = new Evidence (evidence1);
Assert.AreEqual(evidence1.Count, evidence2.Count, "Copy constructor counts do not match");
}
[Test]
public void Constructor_Null ()
{
Evidence e = new Evidence (null);
Assert.AreEqual (0, e.Count, "Count-Empty");
}
[Test]
public void Constructor_NullNull ()
{
Evidence e = new Evidence (null, null);
Assert.AreEqual (0, e.Count, "Count-Empty");
}
[Test]
public void AddAssembly ()
{
Evidence evidence = new Evidence ();
object[] comparray = new object[100];
string obj;
for (int i=0; i<100; i++) {
obj = String.Format ("asmb-{0}", i+1);
comparray[i] = obj;
evidence.AddAssembly (obj);
Assert.AreEqual (evidence.Count, i+1);
}
int index = 0;
foreach (object compobj in evidence) {
Assert.AreEqual (comparray[index++], compobj, "Comparison object does not equal evidence assembly object");
}
}
[Test]
public void AddHost ()
{
Evidence evidence = new Evidence ();
object[] comparray = new object[100];
string obj;
for (int i=0; i<100; i++) {
obj = String.Format ("asmb-{0}", i+1);
comparray[i] = obj;
evidence.AddAssembly ( obj );
Assert.AreEqual (evidence.Count, i+1);
}
int index = 0;
foreach (object compobj in evidence) {
Assert.AreEqual (comparray[index++], compobj, "Comparison object does not equal evidence host object");
}
}
[Test]
public void MultiArgConstructorForEach ()
{
object[] hostarray = { "host-1", "host-2", "host-3", "host-4" };
object[] asmbarray = { "asmb-1", "asmb-2", "asmb-3", "asmb-4" };
ArrayList compare = new ArrayList ();
Evidence evidence = new Evidence (hostarray, asmbarray);
compare.AddRange (hostarray);
compare.AddRange (asmbarray);
int i = 0;
foreach (object obj in evidence) {
Assert.AreEqual (obj, compare[i++]);
}
}
[Test]
public void EnumeratorReset ()
{
object[] hostarray = { "host-1", "host-2", "host-3", "host-4" };
object[] asmbarray = { "asmb-1", "asmb-2", "asmb-3", "asmb-4" };
ArrayList compare = new ArrayList ();
Evidence evidence = new Evidence (hostarray, asmbarray);
compare.AddRange (hostarray);
compare.AddRange (asmbarray);
int i = 0;
IEnumerator enumerator = evidence.GetEnumerator ();
while (enumerator.MoveNext ()) {
Assert.AreEqual (enumerator.Current, compare[i++]);
}
enumerator.Reset ();
i = 0;
while (enumerator.MoveNext ()) {
Assert.AreEqual (enumerator.Current, compare[i++]);
}
}
[Test]
public void GetHostEnumerator ()
{
object[] hostarray = { "host-1", "host-2", "host-3", "host-4" };
object[] asmbarray = { "asmb-1", "asmb-2" };
Evidence evidence = new Evidence (hostarray, asmbarray);
IEnumerator enumerator = evidence.GetHostEnumerator ();
int i = 0;
while (enumerator.MoveNext ()) {
Assert.AreEqual (enumerator.Current, hostarray[i++]);
}
}
[Test]
public void GetHostAssemblyEnumerator ()
{
object[] hostarray = { "host-1", "host-2", "host-3", "host-4" };
object[] asmbarray = { "asmb-1", "asmb-2", "asmb-3", "asmb-4" };
Evidence evidence;
IEnumerator enumerator;
int i;
evidence = new Evidence (hostarray, asmbarray);
enumerator = evidence.GetAssemblyEnumerator ();
i = 0;
while (enumerator.MoveNext()) {
Assert.AreEqual (enumerator.Current, asmbarray[i++]);
}
}
[Test]
public void Count ()
{
object[] hostarray = { "host-1", "host-2", "host-3", "host-4" };
object[] asmbarray = { "asmb-1", "asmb-2", "asmb-3", "asmb-4" };
Evidence evidence = new Evidence (hostarray, asmbarray);
Assert.AreEqual (evidence.Count, 8);
for( int i=0; i<100; i++ ) {
if ( 0 == i%2 ) {
evidence.AddHost (String.Format ("host-{0}", i + 5) );
} else {
evidence.AddAssembly (String.Format ("asmb-{0}", i + 5));
}
Assert.AreEqual (evidence.Count, 9 + i);
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void NullCopyToException()
{
Evidence evidence = new Evidence ();
evidence.AddHost ("host-1");
evidence.CopyTo (null, 100);
}
/// <summary>
/// No Exception will be generated because the copy won't run because the evidence list is empty
/// </summary>
[Test]
public void CopyToNoException()
{
Evidence evidence = new Evidence ();
evidence.CopyTo (null, 100);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void ArgOutOfRangeCopyToException()
{
Evidence evidence = new Evidence (new object[10], new object[10]);
evidence.CopyTo (new object[10], -100);
}
/// <summary>
/// No Exception will be generated because the copy won't run because the evidence list is empty
/// </summary>
[Test]
public void ArgOutOfRangeCopyToNoException()
{
Evidence evidence = new Evidence ();
evidence.CopyTo (new object[10], -100);
}
[Test]
public void BadMerge ()
{
Evidence evidence = new Evidence (null, null);
Evidence evidence2 = new Evidence ();
evidence2.Merge (evidence);
Assert.AreEqual (evidence.Count, evidence2.Count, "Count");
}
[Test]
public void Merge ()
{
Evidence evidence = new Evidence (new object[10], new object[10]);
Evidence evidence2 = new Evidence ();
evidence2.Merge (evidence);
Assert.AreEqual (evidence.Count, evidence2.Count, "Count");
}
[Test]
public void Merge_Null ()
{
Evidence evidence = new Evidence ();
evidence.Merge (null);
// no exception!
Assert.AreEqual (0, evidence.Count, "Count");
}
[Test]
public void DefaultProperties ()
{
Evidence e = new Evidence ();
Assert.AreEqual (0, e.Count, "Count");
Assert.IsTrue (!e.IsReadOnly, "IsReadOnly");
Assert.IsTrue (!e.IsSynchronized, "IsSynchronized");
Assert.IsTrue (!e.Locked, "Locked");
Assert.IsNotNull (e.SyncRoot, "SyncRoot");
}
#if !NET_4_0
[Test]
public void Equals_GetHashCode ()
{
Evidence e1 = new Evidence ();
Evidence e2 = new Evidence ();
Assert.AreEqual (e1.GetHashCode (), e2.GetHashCode (), "GetHashCode-1");
Assert.IsTrue (e1.Equals (e2), "e1.Equals(e2)");
e1.AddAssembly (String.Empty);
e2.AddAssembly (String.Empty);
Assert.AreEqual (e1.GetHashCode (), e2.GetHashCode (), "GetHashCode-2");
e1.AddHost (String.Empty);
e2.AddHost (String.Empty);
Assert.AreEqual (e1.GetHashCode (), e2.GetHashCode (), "GetHashCode-3");
Assert.IsTrue (e2.Equals (e1), "e2.Equals(e1)");
}
#endif
[Test]
public void Clear ()
{
Evidence e = new Evidence ();
Assert.AreEqual (0, e.Count, "Count-Empty");
e.AddAssembly (new object ());
Assert.AreEqual (1, e.Count, "Count+Assembly");
e.AddHost (new object ());
Assert.AreEqual (2, e.Count, "Count+Host");
e.Clear ();
Assert.AreEqual (0, e.Count, "Count-Cleared");
}
[Category ("NotWorking")]
[Test]
public void RemoveType ()
{
Evidence e = new Evidence ();
Assert.AreEqual (0, e.Count, "Count-Empty");
e.AddAssembly (new object ());
e.AddHost (new object ());
Assert.AreEqual (2, e.Count, "Count");
e.RemoveType (typeof (object));
Assert.AreEqual (0, e.Count, "Count-RemoveType(object)");
}
[Test]
public void AppDomain_NoPermissionRequestEvidence ()
{
// PermissionRequestEvidence is only used druing policy resolution
// and can't be accessed using the Evidence property
Evidence e = AppDomain.CurrentDomain.Evidence;
foreach (object o in e) {
if (o is PermissionRequestEvidence)
Assert.Fail ("Found PermissionRequestEvidence in AppDomain.CurrentDomain.Evidence");
}
}
[Test]
[Category ("MobileNotWorking")]
public void Assembly_NoPermissionRequestEvidence ()
{
// PermissionRequestEvidence is only used druing policy resolution
// and can't be accessed using the Evidence property
Evidence e = Assembly.GetExecutingAssembly ().Evidence;
foreach (object o in e) {
if (o is PermissionRequestEvidence)
Assert.Fail ("Found PermissionRequestEvidence in Assembly.GetExecutingAssembly.Evidence");
}
}
}
}

View File

@ -0,0 +1,459 @@
//
// MonoTests.System.Security.Policy.FileCodeGroupTest
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2004 Motus Technologies Inc. (http://www.motus.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.Policy;
using System.Security.Permissions;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class FileCodeGroupTest {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_MembershipConditionNullFileIOPermissionAccess ()
{
FileCodeGroup cg = new FileCodeGroup (null, FileIOPermissionAccess.AllAccess);
}
[Test]
public void Constructor_AllAccess ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
// documented as always null
Assert.IsNull (cg.AttributeString, "AttributeString");
Assert.IsNotNull (cg.PermissionSetName, "PermissionSetName");
}
[Test]
public void Constructor_Append ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.Append);
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
// documented as always null
Assert.IsNull (cg.AttributeString, "AttributeString");
Assert.IsNotNull (cg.PermissionSetName, "PermissionSetName");
}
[Test]
public void Constructor_NoAccess ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.NoAccess);
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
// documented as always null
Assert.IsNull (cg.AttributeString, "AttributeString");
Assert.IsNotNull (cg.PermissionSetName, "PermissionSetName");
}
[Test]
public void Constructor_PathDiscovery ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.PathDiscovery);
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
// documented as always null
Assert.IsNull (cg.AttributeString, "AttributeString");
Assert.IsNotNull (cg.PermissionSetName, "PermissionSetName");
}
[Test]
public void Constructor_Read ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.Read);
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
// documented as always null
Assert.IsNull (cg.AttributeString, "AttributeString");
Assert.IsNotNull (cg.PermissionSetName, "PermissionSetName");
}
[Test]
public void Constructor_Write ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.Write);
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
// documented as always null
Assert.IsNull (cg.AttributeString, "AttributeString");
Assert.IsNotNull (cg.PermissionSetName, "PermissionSetName");
}
[Test]
public void MergeLogic ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
Assert.AreEqual ("Union", cg.MergeLogic, "MergeLogic");
}
[Test]
public void Copy ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
FileCodeGroup cg2 = (FileCodeGroup) cg.Copy ();
Assert.AreEqual (cg.AttributeString, cg2.AttributeString, "AttributeString");
Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
Assert.AreEqual (cg.Description, cg2.Description, "Description");
Assert.AreEqual (cg.MergeLogic, cg2.MergeLogic, "MergeLogic");
Assert.AreEqual (cg.Name, cg2.Name, "Name");
Assert.AreEqual (cg.PermissionSetName, cg2.PermissionSetName, "PermissionSetName");
Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
}
[Test]
public void CopyWithChildren ()
{
FileCodeGroup cgChild = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
cg.AddChild (cgChild);
FileCodeGroup cg2 = (FileCodeGroup) cg.Copy ();
Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Resolve_Null ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
cg.Resolve (null);
}
[Test]
public void Resolve_NoMatch ()
{
FileCodeGroup cg = new FileCodeGroup (new ZoneMembershipCondition (SecurityZone.Untrusted), FileIOPermissionAccess.AllAccess);
Assert.IsNull (cg.Resolve (new Evidence ()));
}
[Test]
public void Resolve_AllMembershipCondition_NoAccess ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.NoAccess);
PolicyStatement result = cg.Resolve (new Evidence ());
Assert.AreEqual (PolicyStatementAttribute.Nothing, result.Attributes, "Attributes");
Assert.AreEqual (String.Empty, result.AttributeString, "AttributeString");
Assert.IsFalse (result.PermissionSet.IsUnrestricted (), "IsUnrestricted");
Assert.AreEqual (0, result.PermissionSet.Count, "Count");
}
[Test]
public void Resolve_AllMembershipCondition_AllAccess ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
PolicyStatement result = cg.Resolve (new Evidence ());
Assert.AreEqual (PolicyStatementAttribute.Nothing, result.Attributes, "Attributes");
Assert.AreEqual (String.Empty, result.AttributeString, "AttributeString");
Assert.IsFalse (result.PermissionSet.IsUnrestricted (), "IsUnrestricted");
Assert.AreEqual (0, result.PermissionSet.Count, "Count");
}
[Test]
public void Resolve_ZoneMembershipCondition_Internet ()
{
IMembershipCondition mc = new ZoneMembershipCondition (SecurityZone.Internet);
PermissionSet pset = new PermissionSet (PermissionState.Unrestricted);
FileCodeGroup cg = new FileCodeGroup (mc, FileIOPermissionAccess.AllAccess);
Evidence e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Internet));
PolicyStatement result = cg.Resolve (e);
Assert.AreEqual (PolicyStatementAttribute.Nothing, result.Attributes, "Internet-Attributes");
Assert.AreEqual (String.Empty, result.AttributeString, "Internet-AttributeString");
Assert.IsFalse (result.PermissionSet.IsUnrestricted (), "Internet-IsUnrestricted");
Assert.AreEqual (0, result.PermissionSet.Count, "Internet-Count");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Intranet));
Assert.IsNull (cg.Resolve (e), "Intranet");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsNull (cg.Resolve (e), "MyComputer");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.NoZone));
Assert.IsNull (cg.Resolve (e), "NoZone");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Trusted));
Assert.IsNull (cg.Resolve (e), "Trusted");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Untrusted));
Assert.IsNull (cg.Resolve (e), "Untrusted");
}
[Test]
public void Resolve_ZoneMembershipCondition_Intranet ()
{
IMembershipCondition mc = new ZoneMembershipCondition (SecurityZone.Intranet);
PermissionSet pset = new PermissionSet (PermissionState.None);
FileCodeGroup cg = new FileCodeGroup (mc, FileIOPermissionAccess.AllAccess);
Evidence e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Intranet));
PolicyStatement result = cg.Resolve (e);
Assert.AreEqual (PolicyStatementAttribute.Nothing, result.Attributes, "Internet-Attributes");
Assert.AreEqual (String.Empty, result.AttributeString, "Internet-AttributeString");
Assert.IsFalse (result.PermissionSet.IsUnrestricted (), "Intranet-IsUnrestricted");
Assert.AreEqual (0, result.PermissionSet.Count, "Intranet-Count");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Internet));
Assert.IsNull (cg.Resolve (e), "Internet");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsNull (cg.Resolve (e), "MyComputer");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.NoZone));
Assert.IsNull (cg.Resolve (e), "NoZone");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Trusted));
Assert.IsNull (cg.Resolve (e), "Trusted");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Untrusted));
Assert.IsNull (cg.Resolve (e), "Untrusted");
}
[Test]
public void Resolve_ZoneMembershipCondition_MyComputer ()
{
IMembershipCondition mc = new ZoneMembershipCondition (SecurityZone.MyComputer);
PermissionSet pset = new PermissionSet (PermissionState.Unrestricted);
FileCodeGroup cg = new FileCodeGroup (mc, FileIOPermissionAccess.AllAccess);
Evidence e = new Evidence ();
e.AddHost (new Zone (SecurityZone.MyComputer));
PolicyStatement result = cg.Resolve (e);
Assert.AreEqual (PolicyStatementAttribute.Nothing, result.Attributes, "Internet-Attributes");
Assert.AreEqual (String.Empty, result.AttributeString, "Internet-AttributeString");
Assert.IsFalse (result.PermissionSet.IsUnrestricted (), "MyComputer-IsUnrestricted");
Assert.AreEqual (0, result.PermissionSet.Count, "MyComputer-Count");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Internet));
Assert.IsNull (cg.Resolve (e), "Internet");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Intranet));
Assert.IsNull (cg.Resolve (e), "Intranet");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.NoZone));
Assert.IsNull (cg.Resolve (e), "NoZone");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Trusted));
Assert.IsNull (cg.Resolve (e), "Trusted");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Untrusted));
Assert.IsNull (cg.Resolve (e), "Untrusted");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Resolve_ZoneMembershipCondition_NoZone ()
{
IMembershipCondition mc = new ZoneMembershipCondition (SecurityZone.NoZone);
}
[Test]
public void Resolve_ZoneMembershipCondition_Trusted ()
{
IMembershipCondition mc = new ZoneMembershipCondition (SecurityZone.Trusted);
PermissionSet pset = new PermissionSet (PermissionState.Unrestricted);
FileCodeGroup cg = new FileCodeGroup (mc, FileIOPermissionAccess.AllAccess);
Evidence e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Trusted));
PolicyStatement result = cg.Resolve (e);
Assert.AreEqual (PolicyStatementAttribute.Nothing, result.Attributes, "Internet-Attributes");
Assert.AreEqual (String.Empty, result.AttributeString, "Internet-AttributeString");
Assert.IsFalse (result.PermissionSet.IsUnrestricted (), "Trusted-IsUnrestricted");
Assert.AreEqual (0, result.PermissionSet.Count, "Trusted-Count");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Internet));
Assert.IsNull (cg.Resolve (e), "Internet");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Intranet));
Assert.IsNull (cg.Resolve (e), "Intranet");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsNull (cg.Resolve (e), "MyComputer");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.NoZone));
Assert.IsNull (cg.Resolve (e), "NoZone");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Untrusted));
Assert.IsNull (cg.Resolve (e), "Untrusted");
}
[Test]
public void Resolve_ZoneMembershipCondition_Untrusted ()
{
IMembershipCondition mc = new ZoneMembershipCondition (SecurityZone.Untrusted);
PermissionSet pset = new PermissionSet (PermissionState.None);
FileCodeGroup cg = new FileCodeGroup (mc, FileIOPermissionAccess.AllAccess);
Evidence e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Untrusted));
PolicyStatement result = cg.Resolve (e);
Assert.AreEqual (PolicyStatementAttribute.Nothing, result.Attributes, "Untrusted-Attributes");
Assert.AreEqual (String.Empty, result.AttributeString, "Untrusted-AttributeString");
Assert.IsFalse (result.PermissionSet.IsUnrestricted (), "Untrusted-IsUnrestricted");
Assert.AreEqual (0, result.PermissionSet.Count, "Untrusted-Count");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Internet));
Assert.IsNull (cg.Resolve (e), "Internet");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Intranet));
Assert.IsNull (cg.Resolve (e), "Intranet");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsNull (cg.Resolve (e), "MyComputer");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.NoZone));
Assert.IsNull (cg.Resolve (e), "NoZone");
e = new Evidence ();
e.AddHost (new Zone (SecurityZone.Trusted));
Assert.IsNull (cg.Resolve (e), "Trusted");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ResolveMatchingCodeGroups_Null ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
cg.ResolveMatchingCodeGroups (null);
}
[Test]
public void ResolveMatchingCodeGroups_NoMatch ()
{
FileCodeGroup cg = new FileCodeGroup (new ZoneMembershipCondition (SecurityZone.Untrusted), FileIOPermissionAccess.AllAccess);
Assert.IsNull (cg.ResolveMatchingCodeGroups (new Evidence ()));
}
[Test]
public void ResolveMatchingCodeGroups_OneLevel ()
{
FileCodeGroup level1 = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
CodeGroup match = level1.ResolveMatchingCodeGroups (new Evidence ());
Assert.IsNotNull (match, "Match");
Assert.IsTrue (match.Equals (level1, false), "Equals(false)");
Assert.IsTrue (match.Equals (level1, true), "Equals(true)");
}
[Test]
public void ResolveMatchingCodeGroups_TwoLevel ()
{
FileCodeGroup level1 = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
CodeGroup level2 = level1.Copy ();
level1.AddChild (level2);
CodeGroup match = level1.ResolveMatchingCodeGroups (new Evidence ());
Assert.IsNotNull (match, "Match");
Assert.IsTrue (match.Equals (level1, false), "Equals(false)");
Assert.IsTrue (match.Equals (level1, true), "Equals(true)");
FileCodeGroup level2b = new FileCodeGroup (new ZoneMembershipCondition (SecurityZone.Untrusted), FileIOPermissionAccess.AllAccess);
level1.AddChild (level2b);
CodeGroup match2 = level1.ResolveMatchingCodeGroups (new Evidence ());
Assert.IsNotNull (match2, "Match2");
Assert.IsTrue (match2.Equals (level1, false), "Equals(false)");
Assert.IsTrue (!match2.Equals (level1, true), "Equals(true)");
}
[Test]
public void ResolveMatchingCodeGroups_ThreeLevel ()
{
FileCodeGroup level1 = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
CodeGroup level2 = level1.Copy ();
level1.AddChild (level2);
FileCodeGroup level3 = new FileCodeGroup (new ZoneMembershipCondition (SecurityZone.Untrusted), FileIOPermissionAccess.AllAccess);
level2.AddChild (level3);
CodeGroup match = level1.ResolveMatchingCodeGroups (new Evidence ());
Assert.IsNotNull (match, "Match");
Assert.IsTrue (match.Equals (level1, false), "Equals(false)");
// Equals (true) isn't a deep compare (just one level)
Assert.IsTrue (match.Equals (level1, true), "Equals(true)");
}
[Test]
public void ToXml ()
{
FileIOPermissionAccess access = FileIOPermissionAccess.Read | FileIOPermissionAccess.Write;
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), access);
string s = cg.ToXml ().ToString ();
Assert.IsTrue (s.IndexOf ("Access=\"Read, Write\"") > 0, "Access='Read, Write'");
}
[Test]
public void ToFromXmlRoundtrip ()
{
FileCodeGroup cg = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.AllAccess);
cg.Name = "SomeName";
cg.Description = "Some Description";
Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
SecurityElement se = cg.ToXml ();
FileCodeGroup cg2 = new FileCodeGroup (new AllMembershipCondition (), FileIOPermissionAccess.NoAccess);
cg2.Name = "SomeOtherName";
cg2.Description = "Some Other Description";
Assert.IsFalse (cg.Equals (cg2), "Equals (another)");
cg2.FromXml (se);
Assert.IsTrue (cg.Equals (cg2), "Equals (FromXml)");
}
}
}

View File

@ -0,0 +1,113 @@
//
// MonoTests.System.Security.Policy.FirstMatchCodeGroupTest
//
// Author:
// Sebastien Pouliot (spouliot@motus.com)
//
// (C) 2004 Motus Technologies Inc. (http://www.motus.com)
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Security;
using System.Security.Policy;
using System.Security.Permissions;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class FirstMatchCodeGroupTest {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_MembershipConditionNullPolicyStatement ()
{
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (null, new PolicyStatement (new PermissionSet (PermissionState.None)));
}
[Test]
public void Constructor_MembershipConditionPolicyStatementNull ()
{
// legal
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), null);
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
}
[Test]
public void Constructor ()
{
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
Assert.IsNotNull (cg.PolicyStatement, "PolicyStatement");
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
}
[Test]
public void MergeLogic ()
{
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
Assert.AreEqual ("First Match", cg.MergeLogic, "MergeLogic");
}
[Test]
public void Copy ()
{
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
FirstMatchCodeGroup cg2 = (FirstMatchCodeGroup) cg.Copy ();
Assert.AreEqual (cg.AttributeString, cg2.AttributeString, "AttributeString");
Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
Assert.AreEqual (cg.Description, cg2.Description, "Description");
Assert.AreEqual (cg.MergeLogic, cg2.MergeLogic, "MergeLogic");
Assert.AreEqual (cg.Name, cg2.Name, "Name");
Assert.AreEqual (cg.PermissionSetName, cg2.PermissionSetName, "PermissionSetName");
Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
}
[Test]
public void CopyWithChildren ()
{
FirstMatchCodeGroup cgChild = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.Unrestricted)));
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
cg.AddChild (cgChild);
FirstMatchCodeGroup cg2 = (FirstMatchCodeGroup) cg.Copy ();
Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Resolve_Null ()
{
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
cg.Resolve (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ResolveMatchingCodeGroups_Null ()
{
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
cg.ResolveMatchingCodeGroups (null);
}
[Test]
public void ToFromXmlRoundtrip ()
{
const string ps_Name = "TestName";
PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));
FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), ps);
cg.Name = "SomeName";
cg.Description = "Some Description";
Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
SecurityElement se = cg.ToXml ();
FirstMatchCodeGroup cg2 = new FirstMatchCodeGroup (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)");
}
}
}

View File

@ -0,0 +1,204 @@
//
// GacMembershipConditionTest.cs - NUnit Test Cases for GacMembershipCondition
//
// 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class GacMembershipConditionTest {
[Test]
public void Constructor ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
Assert.IsNotNull (gac);
}
[Test]
public void Check ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
Evidence e = null;
Assert.IsFalse (gac.Check (e), "Check (null)");
e = new Evidence ();
Assert.IsFalse (gac.Check (e), "Check (empty)");
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsFalse (gac.Check (e), "Check (zone)");
GacInstalled g = new GacInstalled ();
e.AddAssembly (g);
Assert.IsFalse (gac.Check (e), "Check (gac-assembly)");
e.AddHost (g);
Assert.IsTrue (gac.Check (e), "Check (gac-host)");
}
[Test]
public void Copy ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
GacMembershipCondition copy = (GacMembershipCondition) gac.Copy ();
Assert.AreEqual (gac, copy, "Equals");
Assert.IsFalse (Object.ReferenceEquals (gac, copy), "ReferenceEquals");
}
[Test]
public void Equals ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
Assert.IsFalse (gac.Equals (null), "Equals(null)");
GacMembershipCondition g2 = new GacMembershipCondition ();
Assert.IsTrue (gac.Equals (g2), "Equals(g2)");
Assert.IsTrue (g2.Equals (gac), "Equals(gac)");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
gac.FromXml (null);
}
[Test]
public void FromXml ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
SecurityElement se = gac.ToXml ();
gac.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_InvalidTag ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
SecurityElement se = gac.ToXml ();
se.Tag = "IMonoship";
gac.FromXml (se);
}
[Test]
public void FromXml_InvalidClass ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
SecurityElement se = gac.ToXml ();
se.Attributes ["class"] = "Hello world";
gac.FromXml (se);
}
[Test]
public void FromXml_NoClass ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
SecurityElement se = gac.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
gac.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
public void FromXml_InvalidVersion ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
SecurityElement se = gac.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("version", "2");
gac.FromXml (w);
}
[Test]
public void FromXml_NoVersion ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
SecurityElement se = gac.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
gac.FromXml (w);
}
[Test]
#if MOBILE
[Ignore]
#endif
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_SecurityElementNull ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
gac.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
}
[Test]
public void FromXml_PolicyLevelNull ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
SecurityElement se = gac.ToXml ();
gac.FromXml (se, null);
}
[Test]
public void GetHashCode_ ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
Assert.AreEqual (0, gac.GetHashCode ());
}
[Test]
public void ToString_ ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
Assert.AreEqual ("GAC", gac.ToString ());
}
[Test]
#if MOBILE
[Ignore]
#endif
public void ToXml ()
{
GacMembershipCondition gac = new GacMembershipCondition ();
SecurityElement se = gac.ToXml ();
Assert.AreEqual ("IMembershipCondition", se.Tag, "Tag");
Assert.IsTrue (se.Attribute ("class").StartsWith ("System.Security.Policy.GacMembershipCondition"), "class");
Assert.AreEqual ("1", se.Attribute ("version"), "version");
Assert.AreEqual (se.ToString (), gac.ToXml (null).ToString (), "ToXml(null)");
Assert.AreEqual (se.ToString (), gac.ToXml (PolicyLevel.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");
}
}
}
#endif

View File

@ -0,0 +1,95 @@
//
// GacInstalledTest.cs - NUnit Test Cases for GacInstalled
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 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.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Policy;
using System.Security.Permissions;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class GacInstalledTest {
[Test]
public void Constructor ()
{
GacInstalled gac = new GacInstalled ();
Assert.IsNotNull (gac);
}
[Test]
public void Copy ()
{
GacInstalled gac = new GacInstalled ();
GacInstalled copy = (GacInstalled)gac.Copy ();
Assert.AreEqual (gac, copy, "Equals");
Assert.IsFalse (Object.ReferenceEquals (gac, copy), "ReferenceEquals");
}
[Test]
public void CreateIdentityPermission ()
{
GacInstalled gac = new GacInstalled ();
IPermission p = gac.CreateIdentityPermission (null);
Assert.IsTrue ((p is GacIdentityPermission), "GacIdentityPermission");
Assert.IsNotNull (p, "CreateIdentityPermission(null)");
p = gac.CreateIdentityPermission (new Evidence ());
Assert.IsNotNull (p, "CreateIdentityPermission(Evidence)");
}
[Test]
public void Equals ()
{
GacInstalled gac = new GacInstalled ();
Assert.IsFalse (gac.Equals (null), "Equals(null)");
GacInstalled g2 = new GacInstalled ();
Assert.IsTrue (gac.Equals (g2), "Equals(g2)");
Assert.IsTrue (g2.Equals (gac), "Equals(gac)");
}
[Test]
public void GetHashCode_ ()
{
GacInstalled gac = new GacInstalled ();
Assert.AreEqual (0, gac.GetHashCode ());
}
[Test]
public void ToString_ ()
{
GacInstalled gac = new GacInstalled ();
Assert.IsTrue (gac.ToString ().StartsWith ("<System.Security.Policy.GacInstalled version=\"1\"/>"));
}
}
}
#endif

View File

@ -0,0 +1,324 @@
//
// HashMembershipConditionTest.cs -
// NUnit Test Cases for HashMembershipCondition
//
// 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.Reflection;
using System.Security;
using System.Security.Cryptography;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class HashMembershipConditionTest {
static Hash hashEvidence;
static MD5 md5;
static SHA1 sha1;
static byte[] digestMd5;
static byte[] digestSha1;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
Assembly a = Assembly.GetExecutingAssembly ();
hashEvidence = new Hash (a);
md5 = MD5.Create ();
digestMd5 = hashEvidence.GenerateHash (md5);
sha1 = SHA1.Create ();
digestSha1 = hashEvidence.GenerateHash (sha1);
}
[Test]
public void Constructor_MD5 ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
Assert.IsNotNull (hash);
Assert.AreEqual (md5, hash.HashAlgorithm, "HashAlgorithm");
Assert.AreEqual (BitConverter.ToString (digestMd5), BitConverter.ToString (hash.HashValue), "HashValue");
}
[Test]
public void Constructor_SHA1 ()
{
HashMembershipCondition hash = new HashMembershipCondition (sha1, digestSha1);
Assert.IsNotNull (hash);
Assert.AreEqual (sha1, hash.HashAlgorithm, "HashAlgorithm");
Assert.AreEqual (BitConverter.ToString (digestSha1), BitConverter.ToString (hash.HashValue), "HashValue");
}
[Test]
public void HashValue ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
// we can't change the instance data by getting a reference inside it
byte[] value = hash.HashValue;
value [0] ^= 0xFF;
Assert.IsFalse (value [0] == hash.HashValue [0], "reference");
Assert.AreEqual (BitConverter.ToString (digestMd5), BitConverter.ToString (hash.HashValue), "HashValue");
// and we can't change the instance data by keeping a reference to what we supply
hash.HashValue = value;
byte old_value = value [0];
value [0] += 42;
Assert.IsFalse (value [0] == hash.HashValue [0], "reference-2");
Assert.AreEqual (old_value, hash.HashValue [0], "HashValue[0]");
}
[Test]
public void Check ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
Evidence e = null;
Assert.IsFalse (hash.Check (e), "Check (null)");
e = new Evidence ();
Assert.IsFalse (hash.Check (e), "Check (empty)");
e.AddHost (new Zone (SecurityZone.MyComputer));
Assert.IsFalse (hash.Check (e), "Check (zone)");
e.AddAssembly (hashEvidence);
Assert.IsFalse (hash.Check (e), "Check (hash-assembly)");
e = new Evidence ();
e.AddHost (hashEvidence);
Assert.IsTrue (hash.Check (e), "Check (MD5-host)");
hash = new HashMembershipCondition (sha1, digestSha1);
Assert.IsTrue (hash.Check (e), "Check (SHA1-host)");
}
[Test]
public void Copy ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
HashMembershipCondition copy = (HashMembershipCondition)hash.Copy ();
Assert.AreEqual (hash, copy, "Equals");
Assert.IsFalse (Object.ReferenceEquals (hash, copy), "ReferenceEquals");
}
[Test]
public void Equals ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
Assert.IsFalse (hash.Equals (null), "Equals(null)");
Assert.IsFalse (hash.Equals (new object ()), "Equals (object)");
HashMembershipCondition h2 = new HashMembershipCondition (md5, digestMd5);
Assert.IsTrue (hash.Equals (h2), "Equals(h2)");
Assert.IsTrue (h2.Equals (hash), "Equals(hash)");
// same assembly but different algorithm / value
hash = new HashMembershipCondition (sha1, digestSha1);
Assert.IsFalse (hash.Equals (h2), "Equals(h2)");
Assert.IsFalse (h2.Equals (hash), "Equals(hash)");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
hash.FromXml (null);
}
[Test]
public void FromXml ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
hash.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_InvalidTag ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
se.Tag = "IMonoship";
hash.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongTagCase ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
se.Tag = "IMEMBERSHIPCONDITION"; // instehash of IMembershipCondition
hash.FromXml (se);
}
[Test]
public void FromXml_InvalidClass ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
se.Attributes ["class"] = "Hello world";
hash.FromXml (se);
}
[Test]
public void FromXml_NoClass ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
hash.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
public void FromXml_InvalidVersion ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("version", "2");
hash.FromXml (w);
// doesn't seems to care about the version number!
}
[Test]
public void FromXml_NoVersion ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
hash.FromXml (w);
}
[Test]
public void FromXml_Empty_HashAlgorithm ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("version", "1");
hash.FromXml (w);
// this is accepted - but doesn't include a hash algorithm or value
// both would throw ArgumentNullException from the constructor
Assert.IsTrue ((hash.HashAlgorithm is SHA1Managed), "HashAlgorithm");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_Empty_HashValue()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("version", "1");
hash.FromXml (w);
// this is accepted - but doesn't include a hash algorithm or value
// both would throw ArgumentNullException from the constructor
byte[] value = hash.HashValue;
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_Empty_ToString ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("version", "1");
hash.FromXml (w);
// this is accepted - but doesn't include a hash algorithm or value
// both would throw ArgumentNullException from the constructor
string s = hash.ToString ();
}
[Test]
#if MOBILE
[Ignore]
#endif
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_SecurityElementNull ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
hash.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
}
[Test]
public void FromXml_PolicyLevelNull ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
hash.FromXml (se, null);
}
[Test]
public void GetHashCode_ ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
HashMembershipCondition copy = (HashMembershipCondition)hash.Copy ();
Assert.AreEqual (hash.GetHashCode (), copy.GetHashCode ());
}
[Test]
public void ToString_ ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
Assert.IsTrue (hash.ToString ().StartsWith ("Hash - System.Security.Cryptography.MD5"), "MD5");
hash = new HashMembershipCondition (sha1, digestSha1);
Assert.IsTrue (hash.ToString ().StartsWith ("Hash - System.Security.Cryptography.SHA1"), "SHA1");
}
[Test]
#if MOBILE
[Ignore]
#endif
public void ToXml ()
{
HashMembershipCondition hash = new HashMembershipCondition (md5, digestMd5);
SecurityElement se = hash.ToXml ();
Assert.AreEqual ("IMembershipCondition", se.Tag, "Tag");
Assert.IsTrue (se.Attribute ("class").StartsWith ("System.Security.Policy.HashMembershipCondition"), "class");
Assert.AreEqual ("1", se.Attribute ("version"), "version");
Assert.AreEqual (se.ToString (), hash.ToXml (null).ToString (), "ToXml(null)");
Assert.AreEqual (se.ToString (), hash.ToXml (PolicyLevel.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");
}
}
}

View File

@ -0,0 +1,256 @@
//
// HashTest.cs - NUnit Test Cases for Hash
//
// 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 System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Cryptography;
using System.Security.Policy;
using NUnit.Framework;
namespace MonoTests.System.Security.Policy {
[TestFixture]
[Category ("MobileNotWorking")]
public class HashTest {
// mcs compiled
// class Program { static void Main () { System.Console.WriteLine ("Hello World!"); } }
static byte[] helloWorldAssemby = { 0x4D, 0x5A, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x0E, 0x1F, 0xBA, 0x0E, 0x00, 0xB4, 0x09, 0xCD, 0x21, 0xB8, 0x01, 0x4C, 0xCD, 0x21, 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x20, 0x63, 0x61, 0x6E, 0x6E, 0x6F, 0x74, 0x20, 0x62, 0x65, 0x20,
0x72, 0x75, 0x6E, 0x20, 0x69, 0x6E, 0x20, 0x44, 0x4F, 0x53, 0x20, 0x6D, 0x6F, 0x64, 0x65, 0x2E, 0x0D, 0x0D, 0x0A, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x4C, 0x01, 0x03, 0x00, 0x95, 0xEF, 0x2C, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x0E, 0x01, 0x0B, 0x01, 0x06, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x22, 0x00, 0x00, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0xF0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0xA4, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x60, 0x2E, 0x72, 0x73, 0x72, 0x63, 0x00, 0x00, 0x00, 0xF0, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x2E, 0x72, 0x65, 0x6C, 0x6F, 0x63, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7C, 0x20, 0x00, 0x00, 0xD4, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x30, 0x02, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x11, 0x02, 0x28, 0x01, 0x00, 0x00, 0x0A, 0x2A, 0x00, 0x13, 0x30, 0x01, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x11, 0x72, 0x01, 0x00, 0x00, 0x70, 0x28, 0x02, 0x00, 0x00, 0x0A, 0x2A, 0x00, 0x42, 0x53, 0x4A, 0x42, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x76, 0x31, 0x2E, 0x31, 0x2E, 0x34, 0x33, 0x32, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x6C, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x23, 0x7E, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x23, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x73, 0x00, 0x00, 0x00, 0x00, 0x8C,
0x01, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x23, 0x55, 0x53, 0x00, 0xA8, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x23, 0x47, 0x55, 0x49, 0x44, 0x00, 0x00, 0x00, 0xB8, 0x01, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x23, 0x42, 0x6C, 0x6F, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x47, 0x04, 0x02, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0xFA, 0x01, 0x33, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x51, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x1B, 0x00, 0x22, 0x00, 0x06, 0x00, 0x29, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x00, 0x50, 0x20, 0x00, 0x00, 0x00, 0x00, 0x86, 0x18, 0x31, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x64, 0x20, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x37, 0x00, 0x0E, 0x00, 0x01, 0x00, 0x09, 0x00, 0x31, 0x00, 0x0A, 0x00, 0x11, 0x00, 0x3C, 0x00, 0x12, 0x00, 0x17, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x88, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x4D, 0x6F, 0x64, 0x75, 0x6C, 0x65, 0x3E, 0x00, 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x00, 0x6D, 0x73, 0x63, 0x6F, 0x72, 0x6C, 0x69, 0x62, 0x00, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x43, 0x6F, 0x6E, 0x73, 0x6F, 0x6C, 0x65, 0x00, 0x2E, 0x63, 0x74, 0x6F, 0x72, 0x00, 0x4D, 0x61, 0x69, 0x6E, 0x00, 0x57, 0x72, 0x69, 0x74, 0x65,
0x4C, 0x69, 0x6E, 0x65, 0x00, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x00, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x2E, 0x65, 0x78, 0x65, 0x00, 0x00, 0x19, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x20, 0x00, 0x57, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64, 0x00, 0x21, 0x00, 0x00, 0x00, 0xF7, 0x08, 0xDD, 0x5E, 0x9E, 0xFB, 0x95, 0x42, 0x9B, 0x20, 0xDD, 0xA5, 0x71, 0x2E, 0xBE, 0xFA, 0x00, 0x08, 0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89, 0x03, 0x20, 0x00, 0x01, 0x03, 0x00, 0x00, 0x01, 0x04, 0x00, 0x01, 0x01, 0x0E, 0x02, 0x07,
0x00, 0x00, 0x00, 0x78, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8E, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x43, 0x6F, 0x72, 0x45, 0x78, 0x65, 0x4D, 0x61, 0x69, 0x6E, 0x00, 0x6D, 0x73, 0x63, 0x6F, 0x72, 0x65, 0x65, 0x2E, 0x64, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x25, 0x00, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x58, 0x40, 0x00, 0x00, 0x98, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x02, 0x34, 0x00, 0x00, 0x00, 0x56, 0x00, 0x53, 0x00, 0x5F, 0x00, 0x56, 0x00, 0x45, 0x00, 0x52, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4F, 0x00, 0x4E, 0x00, 0x5F, 0x00, 0x49, 0x00, 0x4E, 0x00, 0x46, 0x00, 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x04, 0xEF, 0xFE, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x56, 0x00, 0x61, 0x00, 0x72, 0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x49, 0x00, 0x6E, 0x00, 0x66, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x04, 0x00, 0x00, 0x00, 0x54, 0x00, 0x72, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0xB0, 0x04, 0xF8, 0x01, 0x00, 0x00, 0x01, 0x00, 0x53, 0x00, 0x74, 0x00, 0x72, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67,
0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x49, 0x00, 0x6E, 0x00, 0x66, 0x00, 0x6F, 0x00, 0x00, 0x00, 0xD4, 0x01, 0x00, 0x00, 0x01, 0x00, 0x30, 0x00, 0x30, 0x00, 0x37, 0x00, 0x66, 0x00, 0x30, 0x00, 0x34, 0x00, 0x62, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x02, 0x00, 0x01, 0x00, 0x43, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x6D, 0x00, 0x65, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x73, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x24, 0x00, 0x02, 0x00, 0x01, 0x00, 0x43, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x70, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x79, 0x00, 0x4E, 0x00, 0x61, 0x00, 0x6D, 0x00, 0x65, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x02, 0x00, 0x01, 0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x44, 0x00, 0x65, 0x00, 0x73, 0x00, 0x63, 0x00, 0x72, 0x00, 0x69, 0x00, 0x70, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x30, 0x00, 0x08, 0x00, 0x01, 0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x56, 0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x2E, 0x00, 0x30, 0x00, 0x2E, 0x00, 0x30, 0x00, 0x2E, 0x00, 0x30, 0x00, 0x00, 0x00, 0x38,
0x00, 0x0B, 0x00, 0x01, 0x00, 0x49, 0x00, 0x6E, 0x00, 0x74, 0x00, 0x65, 0x00, 0x72, 0x00, 0x6E, 0x00, 0x61, 0x00, 0x6C, 0x00, 0x4E, 0x00, 0x61, 0x00, 0x6D, 0x00, 0x65, 0x00, 0x00, 0x00, 0x68, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x77, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x02, 0x00, 0x01, 0x00, 0x4C, 0x00, 0x65, 0x00, 0x67, 0x00, 0x61, 0x00, 0x6C, 0x00, 0x43, 0x00, 0x6F, 0x00, 0x70, 0x00, 0x79, 0x00, 0x72, 0x00, 0x69, 0x00, 0x67, 0x00, 0x68, 0x00, 0x74, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x02, 0x00, 0x01,
0x00, 0x4C, 0x00, 0x65, 0x00, 0x67, 0x00, 0x61, 0x00, 0x6C, 0x00, 0x54, 0x00, 0x72, 0x00, 0x61, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x72, 0x00, 0x6B, 0x00, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x48, 0x00, 0x0F, 0x00, 0x01, 0x00, 0x4F, 0x00, 0x72, 0x00, 0x69, 0x00, 0x67, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x61, 0x00, 0x6C, 0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x6E, 0x00, 0x61, 0x00, 0x6D, 0x00, 0x65, 0x00, 0x00, 0x00, 0x68, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x77, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64, 0x00, 0x2E,
0x00, 0x65, 0x00, 0x78, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x02, 0x00, 0x01, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x64, 0x00, 0x75, 0x00, 0x63, 0x00, 0x74, 0x00, 0x4E, 0x00, 0x61, 0x00, 0x6D, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x28, 0x00, 0x02, 0x00, 0x01, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x64, 0x00, 0x75, 0x00, 0x63, 0x00, 0x74, 0x00, 0x56, 0x00, 0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0xA0, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
private Assembly wellKnownAssembly;
private string location;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
if (!File.Exists ("helloworld.exe")) {
using (FileStream fs = File.OpenWrite ("helloworld.exe")) {
location = Path.GetFullPath (fs.Name);
fs.Write (helloWorldAssemby, 0, helloWorldAssemby.Length);
fs.Close ();
}
}
else
location = Path.GetFullPath ("helloworld.exe");
wellKnownAssembly = Assembly.LoadFile (location);
}
[TestFixtureTearDown]
public void FixtureTearDown ()
{
try {
File.Delete (location);
}
catch {} // don't fail tests over this
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Hash_Null ()
{
new Hash (null);
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
public void MD5_Property ()
{
Hash h = new Hash (wellKnownAssembly);
Assert.AreEqual ("D0-C6-1F-66-C8-49-9F-C8-BE-63-89-9D-C5-FC-4F-D4", BitConverter.ToString (h.MD5), "MD5");
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
public void SHA1_Property ()
{
Hash h = new Hash (wellKnownAssembly);
Assert.AreEqual ("68-28-89-F6-D8-D4-9F-AF-FD-00-90-EF-5A-BA-C9-ED-2C-08-A6-F5", BitConverter.ToString (h.SHA1), "SHA1");
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
public void GenerateHash_MD5 ()
{
Hash h = new Hash (wellKnownAssembly);
byte[] result = h.GenerateHash (MD5.Create ());
Assert.AreEqual ("D0-C6-1F-66-C8-49-9F-C8-BE-63-89-9D-C5-FC-4F-D4", BitConverter.ToString (result), "GenerateHash");
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
public void GenerateHash_SHA1 ()
{
Hash h = new Hash (wellKnownAssembly);
byte[] result = h.GenerateHash (SHA1.Create ());
Assert.AreEqual ("68-28-89-F6-D8-D4-9F-AF-FD-00-90-EF-5A-BA-C9-ED-2C-08-A6-F5", BitConverter.ToString (result));
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
public void GenerateHash_SHA256 ()
{
Hash h = new Hash (wellKnownAssembly);
byte[] result = h.GenerateHash (SHA256.Create ());
Assert.AreEqual ("A1-3E-D6-44-BF-1D-B2-22-5D-34-53-14-E5-26-94-78-0A-4E-D0-C2-0F-9D-BA-3D-7C-67-61-3B-3A-17-CD-B0", BitConverter.ToString (result));
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
public void GenerateHash_SHA384 ()
{
Hash h = new Hash (wellKnownAssembly);
byte[] result = h.GenerateHash (SHA384.Create ());
Assert.AreEqual ("23-58-E8-A2-61-B0-9E-0D-86-B1-C7-69-55-D4-52-18-5F-F8-8E-41-C1-94-B6-9B-2D-6A-6D-7F-86-9A-7F-BB-86-55-D4-BF-04-0C-B9-84-A5-52-35-9E-BC-CA-62-BC", BitConverter.ToString (result));
}
[Test]
#if !NET_2_0
[Category ("NotDotNet")] // Current hashing is compatible with Fx 2.0 but not with Fx 1.0/1.1
#endif
public void GenerateHash_SHA512 ()
{
Hash h = new Hash (wellKnownAssembly);
byte[] result = h.GenerateHash (SHA512.Create ());
Assert.AreEqual ("C0-05-76-29-F9-E7-32-A9-8D-73-4B-90-12-6A-85-3F-5C-D3-5B-EF-A6-F2-A6-15-38-9C-22-FA-7E-72-CA-10-B0-21-E0-B6-0B-B8-AB-9E-0E-9F-64-0E-C6-F3-48-96-01-7B-A6-20-07-2F-03-6A-51-03-0F-3F-C4-70-B3-0F", BitConverter.ToString (result));
}
#if NET_2_0
[Test]
public void GenerateHash_RIPEMD160 ()
{
Hash h = new Hash (wellKnownAssembly);
byte[] result = h.GenerateHash (RIPEMD160.Create ());
Assert.AreEqual ("29-5A-21-11-BC-CA-1B-26-A2-46-F2-48-B4-61-96-1C-A5-2C-9A-9A", BitConverter.ToString (result));
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CreateMD5_Null ()
{
Hash.CreateMD5 (null);
}
[Test]
public void CreateMD5_Empty ()
{
Hash h = Hash.CreateMD5 (new byte [0]);
Assert.AreEqual (0, h.MD5.Length, "MD5");
}
[Test]
[ExpectedException (typeof (SecurityException))]
public void CreateMD5_SHA1 ()
{
Hash h = Hash.CreateMD5 (new byte [0]);
byte[] oops = h.SHA1;
}
[Test]
[ExpectedException (typeof (SecurityException))]
public void CreateMD5_ToString ()
{
Hash h = Hash.CreateMD5 (new byte [0]);
string ts = h.ToString ();
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CreateSHA1_Null ()
{
Hash.CreateSHA1 (null);
}
[Test]
public void CreateSHA1_Empty ()
{
Hash h = Hash.CreateSHA1 (new byte [0]);
Assert.AreEqual (0, h.SHA1.Length, "SHA1");
}
[Test]
[ExpectedException (typeof (SecurityException))]
public void CreateSHA1_MD5 ()
{
Hash h = Hash.CreateSHA1 (new byte [0]);
byte[] oops = h.MD5;
}
[Test]
[ExpectedException (typeof (SecurityException))]
public void CreateSHA1_ToString ()
{
Hash h = Hash.CreateSHA1 (new byte [0]);
string ts = h.ToString ();
}
#endif
}
}

View File

@ -0,0 +1,257 @@
//
// IBuiltInEvidenceTest.cs - NUnit Test Cases for IBuiltInEvidence
//
// 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.Reflection;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
// IBuiltInEvidence is internal but we can test it using reflection.
[TestFixture]
[Ignore ("not sure if we gonna need this and, if we do, if we must be compatible with it")]
public class IBuiltInEvidenceTest {
static byte [] msSpCert = { 0x30, 0x82, 0x05, 0x0F, 0x30, 0x82, 0x03, 0xF7, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0A, 0x61, 0x07, 0x11, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x81, 0xA6, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0A, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6E, 0x67, 0x74, 0x6F, 0x6E, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x07, 0x52, 0x65, 0x64, 0x6D, 0x6F, 0x6E, 0x64, 0x31, 0x1E, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x15, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x6F, 0x72, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x31, 0x2B, 0x30, 0x29, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x22, 0x43, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x32, 0x30, 0x30, 0x30, 0x20, 0x4D, 0x69, 0x63, 0x72,
0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x2E, 0x31, 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1A, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x64, 0x65, 0x20, 0x53, 0x69, 0x67, 0x6E, 0x69, 0x6E, 0x67, 0x20, 0x50, 0x43, 0x41, 0x30, 0x1E, 0x17, 0x0D, 0x30, 0x32, 0x30, 0x35, 0x32, 0x35, 0x30, 0x30, 0x35, 0x35, 0x34, 0x38, 0x5A, 0x17, 0x0D, 0x30, 0x33, 0x31, 0x31, 0x32, 0x35, 0x30, 0x31, 0x30, 0x35, 0x34, 0x38, 0x5A, 0x30, 0x81, 0xA1, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0A, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6E, 0x67, 0x74, 0x6F, 0x6E, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x07, 0x52, 0x65, 0x64, 0x6D, 0x6F, 0x6E, 0x64, 0x31, 0x1E, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x15, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x6F, 0x72, 0x61,
0x74, 0x69, 0x6F, 0x6E, 0x31, 0x2B, 0x30, 0x29, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x22, 0x43, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x32, 0x30, 0x30, 0x32, 0x20, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x2E, 0x31, 0x1E, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x15, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x6F, 0x72, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xAA, 0x99, 0xBD, 0x39, 0xA8, 0x18, 0x27, 0xF4, 0x2B, 0x3D, 0x0B, 0x4C, 0x3F, 0x7C, 0x77, 0x2E, 0xA7, 0xCB, 0xB5, 0xD1, 0x8C, 0x0D, 0xC2, 0x3A, 0x74, 0xD7, 0x93, 0xB5, 0xE0, 0xA0, 0x4B, 0x3F, 0x59, 0x5E, 0xCE, 0x45, 0x4F, 0x9A, 0x79, 0x29, 0xF1, 0x49, 0xCC, 0x1A, 0x47, 0xEE, 0x55, 0xC2, 0x08,
0x3E, 0x12, 0x20, 0xF8, 0x55, 0xF2, 0xEE, 0x5F, 0xD3, 0xE0, 0xCA, 0x96, 0xBC, 0x30, 0xDE, 0xFE, 0x58, 0xC8, 0x27, 0x32, 0xD0, 0x85, 0x54, 0xE8, 0xF0, 0x91, 0x10, 0xBB, 0xF3, 0x2B, 0xBE, 0x19, 0xE5, 0x03, 0x9B, 0x0B, 0x86, 0x1D, 0xF3, 0xB0, 0x39, 0x8C, 0xB8, 0xFD, 0x0B, 0x1D, 0x3C, 0x73, 0x26, 0xAC, 0x57, 0x2B, 0xCA, 0x29, 0xA2, 0x15, 0x90, 0x82, 0x15, 0xE2, 0x77, 0xA3, 0x40, 0x52, 0x03, 0x8B, 0x9D, 0xC2, 0x70, 0xBA, 0x1F, 0xE9, 0x34, 0xF6, 0xF3, 0x35, 0x92, 0x4E, 0x55, 0x83, 0xF8, 0xDA, 0x30, 0xB6, 0x20, 0xDE, 0x57, 0x06, 0xB5, 0x5A, 0x42, 0x06, 0xDE, 0x59, 0xCB, 0xF2, 0xDF, 0xA6, 0xBD, 0x15, 0x47, 0x71, 0x19, 0x25, 0x23, 0xD2, 0xCB, 0x6F, 0x9B, 0x19, 0x79, 0xDF, 0x6A, 0x5B, 0xF1, 0x76, 0x05, 0x79, 0x29, 0xFC, 0xC3, 0x56, 0xCA, 0x8F, 0x44, 0x08, 0x85, 0x55, 0x8A, 0xCB, 0xC8, 0x0F, 0x46, 0x4B, 0x55, 0xCB, 0x8C, 0x96, 0x77, 0x4A, 0x87, 0xE8, 0xA9, 0x41, 0x06, 0xC7, 0xFF, 0x0D, 0xE9, 0x68, 0x57, 0x63, 0x72, 0xC3, 0x69, 0x57, 0xB4, 0x43, 0xCF, 0x32, 0x3A, 0x30, 0xDC,
0x1B, 0xE9, 0xD5, 0x43, 0x26, 0x2A, 0x79, 0xFE, 0x95, 0xDB, 0x22, 0x67, 0x24, 0xC9, 0x2F, 0xD0, 0x34, 0xE3, 0xE6, 0xFB, 0x51, 0x49, 0x86, 0xB8, 0x3C, 0xD0, 0x25, 0x5F, 0xD6, 0xEC, 0x9E, 0x03, 0x61, 0x87, 0xA9, 0x68, 0x40, 0xC7, 0xF8, 0xE2, 0x03, 0xE6, 0xCF, 0x05, 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x01, 0x40, 0x30, 0x82, 0x01, 0x3C, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, 0x06, 0xC0, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x0C, 0x30, 0x0A, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x03, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x6B, 0xC8, 0xC6, 0x51, 0x20, 0xF0, 0xB4, 0x2F, 0xD3, 0xA0, 0xB6, 0xAE, 0x7F, 0x5E, 0x26, 0xB2, 0xB8, 0x87, 0x52, 0x29, 0x30, 0x81, 0xA9, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04, 0x81, 0xA1, 0x30, 0x81, 0x9E, 0x80, 0x14, 0x29, 0x5C, 0xB9, 0x1B, 0xB6, 0xCD, 0x33, 0xEE, 0xBB, 0x9E, 0x59, 0x7D, 0xF7, 0xE5, 0xCA, 0x2E, 0xC4, 0x0D, 0x34, 0x28, 0xA1, 0x74,
0xA4, 0x72, 0x30, 0x70, 0x31, 0x2B, 0x30, 0x29, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x22, 0x43, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39, 0x39, 0x37, 0x20, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x2E, 0x31, 0x1E, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x15, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x43, 0x6F, 0x72, 0x70, 0x6F, 0x72, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x31, 0x21, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x18, 0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, 0x69, 0x74, 0x79, 0x82, 0x10, 0x6A, 0x0B, 0x99, 0x4F, 0xC0, 0x00, 0xDE, 0xAA, 0x11, 0xD4, 0xD8, 0x40, 0x9A, 0xA8, 0xBE, 0xE6, 0x30, 0x4A, 0x06, 0x03, 0x55, 0x1D, 0x1F, 0x04, 0x43, 0x30, 0x41, 0x30, 0x3F, 0xA0, 0x3D, 0xA0, 0x3B, 0x86, 0x39, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x63, 0x72, 0x6C,
0x2E, 0x6D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66, 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x70, 0x6B, 0x69, 0x2F, 0x63, 0x72, 0x6C, 0x2F, 0x70, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2F, 0x43, 0x6F, 0x64, 0x65, 0x53, 0x69, 0x67, 0x6E, 0x50, 0x43, 0x41, 0x2E, 0x63, 0x72, 0x6C, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x35, 0x23, 0xFD, 0x13, 0x54, 0xFC, 0xE9, 0xDC, 0xF0, 0xDD, 0x0C, 0x14, 0x7A, 0xFA, 0xA7, 0xB3, 0xCE, 0xFD, 0xA7, 0x3A, 0xC8, 0xBA, 0xE5, 0xE7, 0xF6, 0x03, 0xFB, 0x53, 0xDB, 0xA7, 0x99, 0xA9, 0xA0, 0x9B, 0x36, 0x9C, 0x03, 0xEB, 0x82, 0x47, 0x1C, 0x21, 0xBD, 0x14, 0xCB, 0xE7, 0x67, 0x40, 0x09, 0xC7, 0x16, 0x91, 0x02, 0x55, 0xCE, 0x43, 0x42, 0xB4, 0xCD, 0x1B, 0x5D, 0xB0, 0xF3, 0x32, 0x04, 0x3D, 0x12, 0xE5, 0x1D, 0xA7, 0x07, 0xA7, 0x8F, 0xA3, 0x7E, 0x45, 0x55, 0x76, 0x1B, 0x96, 0x95, 0x91, 0x69, 0xF0, 0xDD, 0x38, 0xF3, 0x48, 0x89, 0xEF, 0x70, 0x40, 0xB7, 0xDB, 0xB5, 0x55,
0x80, 0xC0, 0x03, 0xC4, 0x2E, 0xB6, 0x28, 0xDC, 0x0A, 0x82, 0x0E, 0xC7, 0x43, 0xE3, 0x7A, 0x48, 0x5D, 0xB8, 0x06, 0x89, 0x92, 0x40, 0x6C, 0x6E, 0xC5, 0xDC, 0xF8, 0x9A, 0xEF, 0x0B, 0xBE, 0x21, 0x0A, 0x8C, 0x2F, 0x3A, 0xB5, 0xED, 0xA7, 0xCE, 0x71, 0x87, 0x68, 0x23, 0xE1, 0xB3, 0xE4, 0x18, 0x7D, 0xB8, 0x47, 0x01, 0xA5, 0x2B, 0xC4, 0x58, 0xCB, 0xB2, 0x89, 0x6C, 0x5F, 0xFD, 0xD3, 0x2C, 0xC4, 0x6F, 0xB8, 0x23, 0xB2, 0x0D, 0xFF, 0x3C, 0xF2, 0x11, 0x45, 0x74, 0xF2, 0x09, 0x06, 0x99, 0x18, 0xDD, 0x6F, 0xC0, 0x86, 0x01, 0x18, 0x12, 0x1D, 0x2B, 0x16, 0xAF, 0x56, 0xEF, 0x65, 0x33, 0xA1, 0xEA, 0x67, 0x4E, 0xF4, 0x4B, 0x82, 0xAB, 0xE9, 0x0F, 0xDC, 0x01, 0xFA, 0xDF, 0x60, 0x7F, 0x66, 0x47, 0x5D, 0xCB, 0x2C, 0x70, 0xCC, 0x7B, 0x4E, 0xD9, 0x06, 0xB8, 0x6E, 0x8C, 0x0C, 0xFE, 0x62, 0x1E, 0x42, 0xF9, 0x93, 0x7C, 0xA2, 0xAB, 0x0A, 0x9E, 0xD0, 0x23, 0x10, 0xAE, 0x4D, 0x7B, 0x27, 0x91, 0x6F, 0x26, 0xBE, 0x68, 0xFA, 0xA6, 0x3F, 0x9F, 0x23, 0xEB, 0xC8, 0x9D, 0xBB, 0x87 };
private int GetRequiredSize (object evidence, bool verbose)
{
try {
Type t = evidence.GetType ();
object[] args = new object [1] { verbose };
int result = (int)t.InvokeMember ("System.Security.Policy.IBuiltInEvidence.GetRequiredSize", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, evidence, args);
return result;
}
catch (TargetInvocationException tie) {
throw tie.InnerException;
}
}
private int InitFromBuffer (object evidence, char[] buffer, int position)
{
try {
Type t = evidence.GetType ();
object [] args = new object [2] { buffer, position };
int result = (int)t.InvokeMember ("System.Security.Policy.IBuiltInEvidence.InitFromBuffer", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, evidence, args);
return result;
}
catch (TargetInvocationException tie) {
throw tie.InnerException;
}
}
private int OutputToBuffer (object evidence, char[] buffer, int position, bool verbose)
{
try {
Type t = evidence.GetType ();
object [] args = new object [3] { buffer, position, verbose };
int result = (int)t.InvokeMember ("System.Security.Policy.IBuiltInEvidence.OutputToBuffer", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, evidence, args);
return result;
}
catch (TargetInvocationException tie) {
throw tie.InnerException;
}
}
[Test]
public void ApplicationDirectory_GetRequiredSize ()
{
ApplicationDirectory ad = new ApplicationDirectory ("file://MONO");
Assert.AreEqual (14, GetRequiredSize (ad, true), "GetRequiredSize-true");
Assert.AreEqual (12, GetRequiredSize (ad, false), "GetRequiredSize-false");
ad = new ApplicationDirectory ("file://NOVELL/mono");
Assert.AreEqual (21, GetRequiredSize (ad, true), "GetRequiredSize-true-2");
Assert.AreEqual (19, GetRequiredSize (ad, false), "GetRequiredSize-false-2");
}
#if NET_2_0
[Test]
public void GacInstalled_GetRequiredSize ()
{
GacInstalled g = new GacInstalled ();
Assert.AreEqual (1, GetRequiredSize (g, true), "GetRequiredSize-true");
Assert.AreEqual (1, GetRequiredSize (g, false), "GetRequiredSize-false");
}
[Test]
public void GacInstalled_InitFromBuffer ()
{
char[] buffer = new char [2] { '\t', '\t' };
GacInstalled g = new GacInstalled ();
Assert.AreEqual (0, InitFromBuffer (g, buffer, 0), "InitFromBuffer-1");
Assert.AreEqual (1, InitFromBuffer (g, buffer, 1), "InitFromBuffer-2");
}
[Test]
public void GacInstalled_InitFromBuffer_BadData ()
{
char [] buffer = new char [1] { '\r' };
GacInstalled g = new GacInstalled ();
Assert.AreEqual (0, InitFromBuffer (g, buffer, 0), "InitFromBuffer");
}
[Test]
public void GacInstalled_InitFromBuffer_Null ()
{
GacInstalled g = new GacInstalled ();
Assert.AreEqual (0, InitFromBuffer (g, null, 0), "InitFromBuffer");
}
[Test]
public void GacInstalled_InitFromBuffer_OutOfRange ()
{
char [] buffer = new char [1] { '\t' };
GacInstalled g = new GacInstalled ();
Assert.AreEqual (4, InitFromBuffer (g, buffer, 4), "InitFromBuffer");
}
[Test]
public void GacInstalled_OutputToBuffer ()
{
char[] buffer = new char [2];
GacInstalled g = new GacInstalled ();
Assert.AreEqual (1, OutputToBuffer (g, buffer, 0, false), "OutputToBuffer-false");
Assert.AreEqual ('\t', buffer [0], "Buffer-false");
Assert.AreEqual (2, OutputToBuffer (g, buffer, 1, true), "OutputToBuffer-true");
Assert.AreEqual ('\t', buffer [1], "Buffer-true");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void GacInstalled_OutputToBuffer_Null ()
{
GacInstalled g = new GacInstalled ();
OutputToBuffer (g, null, 0, false);
}
[Test]
[ExpectedException (typeof (IndexOutOfRangeException))]
public void GacInstalled_OutputToBuffer_OutOfRange ()
{
char[] buffer = new char [1] { '\t' };
GacInstalled g = new GacInstalled ();
OutputToBuffer (g, buffer, 1, false);
}
#endif
[Test]
public void Hash_GetRequiredSize ()
{
Hash h = new Hash (Assembly.GetExecutingAssembly ());
Assert.AreEqual (5, GetRequiredSize (h, true), "GetRequiredSize-true");
Assert.AreEqual (0, GetRequiredSize (h, false), "GetRequiredSize-false");
}
[Test]
public void PermissionRequestEvidence_GetRequiredSize ()
{
PermissionRequestEvidence pre = new PermissionRequestEvidence (null, null, null);
Assert.AreEqual (3, GetRequiredSize (pre, true), "(null,null,null).GetRequiredSize-true");
Assert.AreEqual (1, GetRequiredSize (pre, false), "(null,null,null).GetRequiredSize-false");
PermissionSet ps = new PermissionSet (PermissionState.None);
pre = new PermissionRequestEvidence (ps, null, null);
Assert.AreEqual (75, GetRequiredSize (pre, true), "(none,null,null).GetRequiredSize-true");
Assert.AreEqual (70, GetRequiredSize (pre, false), "(none,null,null).GetRequiredSize-false");
pre = new PermissionRequestEvidence (ps, ps, null);
Assert.AreEqual (147, GetRequiredSize (pre, true), "(none,none,null).GetRequiredSize-true");
Assert.AreEqual (139, GetRequiredSize (pre, false), "(none,none,null).GetRequiredSize-false");
pre = new PermissionRequestEvidence (ps, ps, ps);
Assert.AreEqual (219, GetRequiredSize (pre, true), "(none,none,none).GetRequiredSize-true");
Assert.AreEqual (208, GetRequiredSize (pre, false), "(none,none,none).GetRequiredSize-false");
ps = new PermissionSet (PermissionState.Unrestricted);
pre = new PermissionRequestEvidence (ps, ps, ps);
Assert.AreEqual (282, GetRequiredSize (pre, true), "(unrestricted,unrestricted,unrestricted).GetRequiredSize-true");
Assert.AreEqual (271, GetRequiredSize (pre, false), "(unrestricted,unrestricted,unrestricted).GetRequiredSize-false");
}
[Test]
public void Publisher_GetRequiredSize ()
{
X509Certificate x509 = new X509Certificate (msSpCert);
Publisher p = new Publisher (x509);
Assert.AreEqual (653, GetRequiredSize (p, true), "GetRequiredSize-true");
Assert.AreEqual (651, GetRequiredSize (p, false), "GetRequiredSize-false");
}
[Test]
public void Site_GetRequiredSize ()
{
Site s = new Site ("www.mono-project.com");
Assert.AreEqual (23, GetRequiredSize (s, true), "GetRequiredSize-true");
Assert.AreEqual (21, GetRequiredSize (s, false), "GetRequiredSize-false");
s = new Site ("www.go-mono.com");
Assert.AreEqual (18, GetRequiredSize (s, true), "GetRequiredSize-true-2");
Assert.AreEqual (16, GetRequiredSize (s, false), "GetRequiredSize-false-2");
}
[Test]
public void StrongName_GetRequiredSize ()
{
byte[] pk = { 0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD, 0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B, 0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9, 0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78, 0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68, 0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E, 0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F, 0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D, 0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB, 0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5, 0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56, 0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00, 0x4A, 0xF8, 0xFF, 0xA4, 0xCB };
StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob (pk);
StrongName sn = new StrongName (snpkb, "mono", new Version ());
Assert.AreEqual (97, GetRequiredSize (sn, true), "GetRequiredSize-true");
Assert.AreEqual (93, GetRequiredSize (sn, false), "GetRequiredSize-false");
}
[Test]
public void Url_GetRequiredSize ()
{
Url u = new Url ("http://www.mono-project.com/");
Assert.AreEqual (31, GetRequiredSize (u, true), "GetRequiredSize-true");
Assert.AreEqual (29, GetRequiredSize (u, false), "GetRequiredSize-false");
u = new Url ("http://www.go-mono.com/");
Assert.AreEqual (26, GetRequiredSize (u, true), "GetRequiredSize-true-2");
Assert.AreEqual (24, GetRequiredSize (u, false), "GetRequiredSize-false-2");
}
[Test]
public void Zone_GetRequiredSize ()
{
Zone z = new Zone (SecurityZone.MyComputer);
Assert.AreEqual (3, GetRequiredSize (z, true), "GetRequiredSize-true");
Assert.AreEqual (3, GetRequiredSize (z, false), "GetRequiredSize-false");
}
}
}

View File

@ -0,0 +1,132 @@
//
// MonoTests.System.Security.Policy.NetCodeGroupTest
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2004 Motus Technologies Inc. (http://www.motus.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.Policy;
using System.Security.Permissions;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class NetCodeGroupTest {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_Null ()
{
NetCodeGroup cg = new NetCodeGroup ((IMembershipCondition)null);
}
[Test]
public void Constructor ()
{
NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
// documented as always null
Assert.IsNull (cg.AttributeString, "AttributeString");
#if NET_2_0
// seems it's easier to change code than to change code ;)
Assert.AreEqual ("Same site Web", cg.PermissionSetName, "PermissionSetName");
#else
// documented as always "Same site Web" but it's "Same site Web." (missing .)
Assert.AreEqual ("Same site Web.", cg.PermissionSetName, "PermissionSetName");
#endif
}
[Test]
public void MergeLogic ()
{
NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
Assert.AreEqual ("Union", cg.MergeLogic, "MergeLogic");
}
[Test]
public void Copy ()
{
NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
NetCodeGroup cg2 = (NetCodeGroup) cg.Copy ();
Assert.AreEqual (cg.AttributeString, cg2.AttributeString, "AttributeString");
Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
Assert.AreEqual (cg.Description, cg2.Description, "Description");
Assert.AreEqual (cg.MergeLogic, cg2.MergeLogic, "MergeLogic");
Assert.AreEqual (cg.Name, cg2.Name, "Name");
Assert.AreEqual (cg.PermissionSetName, cg2.PermissionSetName, "PermissionSetName");
Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
}
[Test]
public void CopyWithChildren ()
{
NetCodeGroup cgChild = new NetCodeGroup (new AllMembershipCondition ());
NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
cg.AddChild (cgChild);
NetCodeGroup cg2 = (NetCodeGroup) cg.Copy ();
Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Resolve_Null ()
{
NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
cg.Resolve (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ResolveMatchingCodeGroups_Null ()
{
NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
cg.ResolveMatchingCodeGroups (null);
}
[Test]
public void ToFromXmlRoundtrip ()
{
NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
cg.Name = "SomeName";
cg.Description = "Some Description";
Assert.IsTrue (cg.Equals (cg), "Equals (itself)");
SecurityElement se = cg.ToXml ();
NetCodeGroup cg2 = new NetCodeGroup (new AllMembershipCondition());
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)");
}
}
}

View File

@ -0,0 +1,168 @@
//
// PermissionRequestEvidenceTest.cs -
// NUnit Test Cases for PermissionRequestEvidence
//
// Authors:
// Nick Drochak (ndrochak@gol.com)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2004 Nick Drochak
// 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.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class PermissionRequestEvidenceTest {
private string AdjustNewLine (string s)
{
#if NET_2_0
// no spaces are used in Fx 2.0
while (s.IndexOf ("\r\n ") != -1)
s = s.Replace ("\r\n ", "\r\n");
#endif
if (Environment.NewLine != "\r\n")
s = s.Replace ("\r\n", Environment.NewLine);
return s;
}
[Test]
public void NullConstructor ()
{
PermissionRequestEvidence pre = new PermissionRequestEvidence (null, null, null);
Assert.IsNull (pre.RequestedPermissions, "Requested");
Assert.IsNull (pre.OptionalPermissions, "Optional");
Assert.IsNull (pre.DeniedPermissions, "Denied");
string expected = AdjustNewLine ("<System.Security.Policy.PermissionRequestEvidence version=\"1\"/>\r\n");
Assert.AreEqual (expected, pre.ToString (), "ToString");
}
[Test]
public void Constructor1 ()
{
PermissionSet ps = new PermissionSet (PermissionState.None);
PermissionRequestEvidence pre = new PermissionRequestEvidence (ps, ps, ps);
Assert.IsFalse (pre.RequestedPermissions.IsUnrestricted (), "Requested");
Assert.IsFalse (pre.OptionalPermissions.IsUnrestricted (), "Optional");
Assert.IsFalse (pre.DeniedPermissions.IsUnrestricted (), "Denied");
Assert.IsFalse (Object.ReferenceEquals (ps, pre.RequestedPermissions), "!ReferenceEquals-RequestedPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps, pre.OptionalPermissions), "!ReferenceEquals-OptionalPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps, pre.DeniedPermissions), "!ReferenceEquals-DeniedPermissions");
string expected = AdjustNewLine ("<System.Security.Policy.PermissionRequestEvidence version=\"1\">\r\n <Request>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"/>\r\n </Request>\r\n <Optional>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"/>\r\n </Optional>\r\n <Denied>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"/>\r\n </Denied>\r\n</System.Security.Policy.PermissionRequestEvidence>\r\n");
Assert.AreEqual (expected, pre.ToString (), "ToString");
}
[Test]
public void Constructor2 ()
{
PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
PermissionRequestEvidence pre = new PermissionRequestEvidence (ps, ps, ps);
Assert.IsTrue (pre.RequestedPermissions.IsUnrestricted (), "Requested");
Assert.IsTrue (pre.OptionalPermissions.IsUnrestricted (), "Optional");
Assert.IsTrue (pre.DeniedPermissions.IsUnrestricted (), "Denied");
Assert.IsFalse (Object.ReferenceEquals (ps, pre.RequestedPermissions), "!ReferenceEquals-RequestedPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps, pre.OptionalPermissions), "!ReferenceEquals-OptionalPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps, pre.DeniedPermissions), "!ReferenceEquals-DeniedPermissions");
string expected = AdjustNewLine ("<System.Security.Policy.PermissionRequestEvidence version=\"1\">\r\n <Request>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"\r\n Unrestricted=\"true\"/>\r\n </Request>\r\n <Optional>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"\r\n Unrestricted=\"true\"/>\r\n </Optional>\r\n <Denied>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"\r\n Unrestricted=\"true\"/>\r\n </Denied>\r\n</System.Security.Policy.PermissionRequestEvidence>\r\n");
Assert.AreEqual (expected, pre.ToString (), "ToString");
}
[Test]
public void Constructor3 ()
{
PermissionSet ps1 = new PermissionSet (PermissionState.None);
PermissionSet ps2 = new PermissionSet (PermissionState.Unrestricted);
PermissionRequestEvidence pre = new PermissionRequestEvidence (ps1, ps2, ps1);
Assert.IsFalse (pre.RequestedPermissions.IsUnrestricted (), "Requested");
Assert.IsTrue (pre.OptionalPermissions.IsUnrestricted (), "Optional");
Assert.IsFalse (pre.DeniedPermissions.IsUnrestricted (), "Denied");
Assert.IsFalse (Object.ReferenceEquals (ps1, pre.RequestedPermissions), "!ReferenceEquals-RequestedPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps2, pre.OptionalPermissions), "!ReferenceEquals-OptionalPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps1, pre.DeniedPermissions), "!ReferenceEquals-DeniedPermissions");
string expected = AdjustNewLine ("<System.Security.Policy.PermissionRequestEvidence version=\"1\">\r\n <Request>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"/>\r\n </Request>\r\n <Optional>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"\r\n Unrestricted=\"true\"/>\r\n </Optional>\r\n <Denied>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"/>\r\n </Denied>\r\n</System.Security.Policy.PermissionRequestEvidence>\r\n");
Assert.AreEqual (expected, pre.ToString (), "ToString");
}
[Test]
public void Constructor4 ()
{
PermissionSet ps1 = new PermissionSet (PermissionState.None);
PermissionSet ps2 = new PermissionSet (PermissionState.Unrestricted);
PermissionRequestEvidence pre = new PermissionRequestEvidence (ps2, ps1, ps2);
Assert.IsTrue (pre.RequestedPermissions.IsUnrestricted (), "Requested");
Assert.IsFalse (pre.OptionalPermissions.IsUnrestricted (), "Optional");
Assert.IsTrue (pre.DeniedPermissions.IsUnrestricted (), "Denied");
Assert.IsFalse (Object.ReferenceEquals (ps2, pre.RequestedPermissions), "!ReferenceEquals-RequestedPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps1, pre.OptionalPermissions), "!ReferenceEquals-OptionalPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps2, pre.DeniedPermissions), "!ReferenceEquals-DeniedPermissions");
string expected = AdjustNewLine ("<System.Security.Policy.PermissionRequestEvidence version=\"1\">\r\n <Request>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"\r\n Unrestricted=\"true\"/>\r\n </Request>\r\n <Optional>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"/>\r\n </Optional>\r\n <Denied>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"\r\n Unrestricted=\"true\"/>\r\n </Denied>\r\n</System.Security.Policy.PermissionRequestEvidence>\r\n");
Assert.AreEqual (expected, pre.ToString (), "ToString");
}
[Test]
public void Copy ()
{
PermissionSet ps1 = new PermissionSet (PermissionState.None);
PermissionSet ps2 = new PermissionSet (PermissionState.Unrestricted);
PermissionRequestEvidence pre = new PermissionRequestEvidence (ps2, ps1, ps2);
PermissionRequestEvidence copy = pre.Copy ();
Assert.IsFalse (Object.ReferenceEquals (pre, copy), "!ReferenceEquals");
Assert.IsTrue (copy.RequestedPermissions.IsUnrestricted (), "Requested");
Assert.IsFalse (copy.OptionalPermissions.IsUnrestricted (), "Optional");
Assert.IsTrue (copy.DeniedPermissions.IsUnrestricted (), "Denied");
Assert.IsFalse (Object.ReferenceEquals (ps2, copy.RequestedPermissions), "!ReferenceEquals-RequestedPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps1, copy.OptionalPermissions), "!ReferenceEquals-OptionalPermissions");
Assert.IsFalse (Object.ReferenceEquals (ps2, copy.DeniedPermissions), "!ReferenceEquals-DeniedPermissions");
Assert.IsFalse (Object.ReferenceEquals (pre.RequestedPermissions, copy.RequestedPermissions), "!ReferenceEquals-Copy-RequestedPermissions");
Assert.IsFalse (Object.ReferenceEquals (pre.OptionalPermissions, copy.OptionalPermissions), "!ReferenceEquals-Copy-OptionalPermissions");
Assert.IsFalse (Object.ReferenceEquals (pre.DeniedPermissions, copy.DeniedPermissions), "!ReferenceEquals-Copy-DeniedPermissions");
string expected = AdjustNewLine ("<System.Security.Policy.PermissionRequestEvidence version=\"1\">\r\n <Request>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"\r\n Unrestricted=\"true\"/>\r\n </Request>\r\n <Optional>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"/>\r\n </Optional>\r\n <Denied>\r\n <PermissionSet class=\"System.Security.PermissionSet\"\r\n version=\"1\"\r\n Unrestricted=\"true\"/>\r\n </Denied>\r\n</System.Security.Policy.PermissionRequestEvidence>\r\n");
Assert.AreEqual (expected, pre.ToString (), "ToString");
Assert.AreEqual (pre.ToString (), copy.ToString (), "ToString-Copy");
}
[Test]
public void CopiesButNotReadOnly ()
{
PermissionSet ps = new PermissionSet (PermissionState.None);
PermissionRequestEvidence pre = new PermissionRequestEvidence (ps, ps, ps);
ps.AddPermission (new SecurityPermission (SecurityPermissionFlag.Execution));
Assert.AreEqual (1, ps.Count, "ps.Count");
// not a reference
Assert.AreEqual (0, pre.RequestedPermissions.Count, "Requested.Count");
Assert.AreEqual (0, pre.OptionalPermissions.Count, "Optional.Count");
Assert.AreEqual (0, pre.DeniedPermissions.Count, "Denied.Count");
// and we can still add permissions
pre.RequestedPermissions.AddPermission (new SecurityPermission (SecurityPermissionFlag.Execution));
Assert.AreEqual (1, pre.RequestedPermissions.Count, "Requested.Count-2");
Assert.AreEqual (0, pre.OptionalPermissions.Count, "Optional.Count-2");
Assert.AreEqual (0, pre.DeniedPermissions.Count, "Denied.Count-2");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,217 @@
//
// PolicyStatementTest.cs - NUnit Test Cases for PolicyStatement
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 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.IO;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoTests.System.Security.Policy {
[TestFixture]
public class PolicyStatementTest {
static PermissionSet Empty = new PermissionSet (PermissionState.None);
static PermissionSet Unrestricted = new PermissionSet (PermissionState.Unrestricted);
[Test]
public void Constructor_PermissionSet_Null ()
{
PolicyStatement ps = new PolicyStatement (null);
Assert.AreEqual (PolicyStatementAttribute.Nothing, ps.Attributes, "Attributes");
Assert.AreEqual (String.Empty, ps.AttributeString, "AttributeString");
Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
}
[Test]
public void Constructor_PermissionSet_None ()
{
PermissionSet pset = new PermissionSet (PermissionState.None);
PolicyStatement ps = new PolicyStatement (pset);
Assert.AreEqual (PolicyStatementAttribute.Nothing, ps.Attributes, "Attributes");
Assert.AreEqual (String.Empty, ps.AttributeString, "AttributeString");
Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
}
[Test]
public void Constructor_PermissionSet_Unrestricted ()
{
PermissionSet pset = new PermissionSet (PermissionState.Unrestricted);
PolicyStatement ps = new PolicyStatement (pset);
Assert.AreEqual (PolicyStatementAttribute.Nothing, ps.Attributes, "Attributes");
Assert.AreEqual (String.Empty, ps.AttributeString, "AttributeString");
Assert.AreEqual (Unrestricted.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
}
[Test]
public void Constructor_PermissionSetPolicyStatementAttribute_Null ()
{
PolicyStatement ps = new PolicyStatement (null, PolicyStatementAttribute.All);
Assert.AreEqual (PolicyStatementAttribute.All, ps.Attributes, "Attributes");
Assert.AreEqual ("Exclusive LevelFinal", ps.AttributeString, "AttributeString");
Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
}
[Test]
public void Constructor_Copy ()
{
PermissionSet original = new PermissionSet (PermissionState.None);
PolicyStatement ps = new PolicyStatement (original, PolicyStatementAttribute.All);
Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
original.AddPermission (new SecurityPermission (SecurityPermissionFlag.AllFlags));
Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "PermissionSet");
Assert.AreEqual (ps.ToXml ().ToString (), ps.Copy ().ToXml ().ToString (), "Copy");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Attribute_Invalid ()
{
PolicyStatement ps = new PolicyStatement (null);
ps.Attributes = (PolicyStatementAttribute)Int32.MinValue;
}
[Test]
public void AttributeString ()
{
PolicyStatement ps = new PolicyStatement (null);
Assert.AreEqual (String.Empty, ps.AttributeString, "Nothing");
ps.Attributes = PolicyStatementAttribute.LevelFinal;
Assert.AreEqual ("LevelFinal", ps.AttributeString, "LevelFinal");
ps.Attributes = PolicyStatementAttribute.Exclusive;
Assert.AreEqual ("Exclusive", ps.AttributeString, "Exclusive");
ps.Attributes = PolicyStatementAttribute.All;
Assert.AreEqual ("Exclusive LevelFinal", ps.AttributeString, "All");
}
[Test]
public void AddToPermissionSet ()
{
PolicyStatement ps = new PolicyStatement (null);
Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "Empty");
SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Execution);
IPermission p = ps.PermissionSet.AddPermission (sp);
Assert.AreEqual (sp.ToXml ().ToString (), p.ToXml ().ToString (), "AddPermission");
// but nothing was added
Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "Still Empty");
// and (strangely) it's not considered a read-only permission set
// as this property is always false for PermissionSet
Assert.IsFalse (ps.PermissionSet.IsReadOnly, "IsReadOnly");
}
[Test]
public void SetPermissionSet ()
{
PolicyStatement ps = new PolicyStatement (null);
Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "Empty");
ps.PermissionSet = new PermissionSet (PermissionState.Unrestricted);
Assert.AreEqual (Unrestricted.ToString (), ps.PermissionSet.ToString (), "Unrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
PolicyStatement ps = new PolicyStatement (null);
ps.FromXml (null);
}
[Test]
#if MOBILE
[Ignore]
#endif
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_SecurityElementNull ()
{
PolicyStatement ps = new PolicyStatement (null);
ps.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_BadSecurityElement ()
{
PolicyStatement ps = new PolicyStatement (null);
ps.FromXml (new SecurityElement ("Bad"));
}
[Test]
public void ToFromXml_PolicyLevelNull ()
{
PolicyStatement ps = new PolicyStatement (null);
SecurityElement se = ps.ToXml (null);
ps.FromXml (se, null);
}
[Test]
public void ToFromXml_RoundTrip ()
{
PolicyStatement ps1 = new PolicyStatement (Unrestricted, PolicyStatementAttribute.All);
SecurityElement se = ps1.ToXml ();
PolicyStatement ps2 = new PolicyStatement (null);
ps2.FromXml (se, null);
Assert.AreEqual (ps1.ToXml ().ToString (), ps2.ToXml ().ToString (), "Xml");
}
#if NET_2_0
[Test]
[Category ("NotWorking")]
public void Equals ()
{
PolicyStatement empty1 = new PolicyStatement (null);
PolicyStatement empty2 = new PolicyStatement (null);
Assert.IsTrue (empty1.Equals (empty2), "empty1.Equals (empty2)");
Assert.IsTrue (empty2.Equals (empty1), "empty2.Equals (empty1)");
Assert.IsFalse (Object.ReferenceEquals (empty1, empty2), "!ReferenceEquals");
PolicyStatement unr1 = new PolicyStatement (Unrestricted, PolicyStatementAttribute.All);
Assert.IsFalse (unr1.Equals (empty1), "unr1.Equals (empty1)");
Assert.IsFalse (empty1.Equals (unr1), "empty1.Equals (unr1)");
PolicyStatement unr2 = new PolicyStatement (Unrestricted, PolicyStatementAttribute.Exclusive);
Assert.IsFalse (unr1.Equals (unr2), "unr1.Equals (unr2)");
Assert.IsFalse (unr2.Equals (unr1), "unr2.Equals (unr1)");
PolicyStatement unr3 = unr2.Copy ();
Assert.IsTrue (unr3.Equals (unr2), "unr3.Equals (unr2)");
Assert.IsTrue (unr2.Equals (unr3), "unr2.Equals (unr3)");
}
#endif
}
}

Some files were not shown because too many files have changed in this diff Show More