Author: spouliot
Date: 2005-04-04 15:02:51 -0400 (Mon, 04 Apr 2005)
New Revision: 42534
Added:
trunk/mcs/class/corlib/Test/System.Reflection/AssemblyNameCas.cs
trunk/mcs/class/corlib/Test/System.Reflection/StrongNameKeyPairCas.cs
Modified:
trunk/mcs/class/corlib/Test/System.Reflection/AssemblyNameTest.cs
trunk/mcs/class/corlib/Test/System.Reflection/ChangeLog
trunk/mcs/class/corlib/Test/System.Reflection/StrongNameKeyPairTest.cs
Log:
* AssemblyNameTest.cs: Added tests for Clone and serialization without
a strongname.
* AssemblyNameCas.cs: New. CAS unit tests for AssemblyName.
* StrongNameKeyPairTest.cs: Little changes to make it easier to reuse
in CAS tests.
* StrongNameKeyPairCas.cs: New. CAS unit tests for StrongNameKeyPair.
2005-04-04 Sebastien Pouliot <[EMAIL PROTECTED]>
Added: trunk/mcs/class/corlib/Test/System.Reflection/AssemblyNameCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection/AssemblyNameCas.cs
2005-04-04 19:00:34 UTC (rev 42533)
+++ trunk/mcs/class/corlib/Test/System.Reflection/AssemblyNameCas.cs
2005-04-04 19:02:51 UTC (rev 42534)
@@ -0,0 +1,138 @@
+//
+// AssemblyNameCas.cs - CAS unit tests for System.Reflection.AssemblyName
+//
+// Author:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// 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.Configuration.Assemblies;
+using System.Reflection;
+using System.Runtime.Serialization;
+using System.Security;
+using System.Security.Permissions;
+
+namespace MonoCasTests.System.Reflection {
+
+ [TestFixture]
+ [Category ("CAS")]
+ public class AssemblyNameCas {
+
+ private MonoTests.System.Reflection.AssemblyNameTest ant;
+ private AssemblyName main;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ ant = new MonoTests.System.Reflection.AssemblyNameTest
();
+ }
+
+ [SetUp]
+ public void SetUp ()
+ {
+ if (!SecurityManager.SecurityEnabled)
+ Assert.Ignore ("SecurityManager.SecurityEnabled
is OFF");
+ ant.SetUp ();
+ }
+
+ [TearDown]
+ public void TearDown ()
+ {
+ ant.TearDown ();
+ }
+
+ // Partial Trust Tests
+
+ [Test]
+ [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+ public void PartialTrust_Deny_Unrestricted ()
+ {
+ // call "normal" unit with reduced privileges
+ ant.EmptyAssembly ();
+ ant.PublicKey ();
+ ant.PublicKeyToken ();
+ ant.Clone_Empty ();
+ }
+
+ [Test]
+ [SecurityPermission (SecurityAction.PermitOnly,
SerializationFormatter = true)]
+ public void PartialTrust_PermitOnly_SerializationFormatter ()
+ {
+ ant.Serialization_WithoutStrongName ();
+ }
+
+ [Test]
+ [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode =
true)]
+ public void PartialTrust_PermitOnly_UnmanagedCode ()
+ {
+ ant.KeyPair ();
+ }
+
+
+ [Test]
+ [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode =
true, SerializationFormatter = true)]
+ public void
PartialTrust_PermitOnly_UnmanagedCodeSerializationFormatter ()
+ {
+ // UnmanagedCode is required to create a
StrongNameKeyPair instance
+ ant.Serialization ();
+ }
+
+ [Test]
+ [SecurityPermission (SecurityAction.Deny,
SerializationFormatter = true)]
+ [ExpectedException (typeof (SecurityException))]
+ public void PartialTrust_Deny_SerializationFormatter ()
+ {
+ ant.Serialization ();
+ }
+
+ [Test]
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ [ExpectedException (typeof (SecurityException))]
+ public void PartialTrust_Deny_UnmanagedCode ()
+ {
+ ant.KeyPair ();
+ }
+
+ [Test]
+ [FileIOPermission (SecurityAction.PermitOnly, Unrestricted =
true)]
+ public void PartialTrust_PermitOnly_FileIOPermission ()
+ {
+ // call "normal" unit with reduced privileges
+ ant.Self ();
+ ant.FullName1 ();
+ ant.FullName2 ();
+ ant.FullName3 ();
+ ant.FullName4 ();
+ ant.FullName5 ();
+ ant.FullName6 ();
+ ant.FullName7 ();
+ ant.FullName8 ();
+ ant.HashAlgorithm ();
+ ant.Clone_Empty ();
+ // mostly because they call Assembly.GetName
+ }
+ }
+}
Modified: trunk/mcs/class/corlib/Test/System.Reflection/AssemblyNameTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection/AssemblyNameTest.cs
2005-04-04 19:00:34 UTC (rev 42533)
+++ trunk/mcs/class/corlib/Test/System.Reflection/AssemblyNameTest.cs
2005-04-04 19:02:51 UTC (rev 42534)
@@ -80,7 +80,7 @@
{
try {
if (Directory.Exists (tempDir))
- Directory.Delete (tempDir, true);
+ Directory.Delete (tempDir, true);
}
catch (Exception) {
// This can happen on windows when the directory
contains
@@ -364,13 +364,91 @@
}
[Test]
+ public void Serialization_WithoutStrongName ()
+ {
+ AssemblyName an = new AssemblyName ();
+ an.CodeBase = "http://www.test.com/test.dll";
+ an.CultureInfo = CultureInfo.InvariantCulture;
+ an.Flags = AssemblyNameFlags.None;
+ an.HashAlgorithm = AssemblyHashAlgorithm.SHA1;
+ an.KeyPair = null;
+ an.Name = "TestAssembly2";
+ an.Version = new Version (1, 5, 0, 0);
+ an.VersionCompatibility =
AssemblyVersionCompatibility.SameMachine;
+
+ MemoryStream ms = new MemoryStream ();
+ BinaryFormatter bf = new BinaryFormatter ();
+ bf.Serialize (ms, an);
+
+ // reset position of memorystream
+ ms.Position = 0;
+
+ // deserialze assembly name
+ AssemblyName dsAssemblyName = (AssemblyName) bf.Deserialize
(ms);
+
+ // close the memorystream
+ ms.Close ();
+
+ // compare orginal and deserialized assembly name
+ Assert.AreEqual (an.CodeBase, dsAssemblyName.CodeBase,
"CodeBase");
+ Assert.AreEqual (an.CultureInfo, dsAssemblyName.CultureInfo,
"CultureInfo");
+ Assert.AreEqual (an.Flags, dsAssemblyName.Flags, "Flags");
+ Assert.AreEqual (an.HashAlgorithm,
dsAssemblyName.HashAlgorithm, "HashAlgorithm");
+ Assert.AreEqual (an.Name, dsAssemblyName.Name, "Name");
+ Assert.AreEqual (an.Version, dsAssemblyName.Version, "Version");
+ Assert.AreEqual (an.VersionCompatibility,
dsAssemblyName.VersionCompatibility, "VersionCompatibility");
+ Assert.AreEqual (an.EscapedCodeBase,
dsAssemblyName.EscapedCodeBase, "EscapedCodeBase");
+ Assert.AreEqual (an.FullName, dsAssemblyName.FullName,
"FullName");
+ Assert.AreEqual (an.ToString (), dsAssemblyName.ToString (),
"ToString");
+ AssertEqualsByteArrays ("PublicKey", an.GetPublicKey (),
dsAssemblyName.GetPublicKey ());
+ AssertEqualsByteArrays ("PublicToken", an.GetPublicKeyToken (),
dsAssemblyName.GetPublicKeyToken ());
+ }
+
+ [Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetObjectData_Null ()
{
AssemblyName an = new AssemblyName ();
an.GetObjectData (null, new StreamingContext
(StreamingContextStates.All));
+ }
+
+ [Test]
+ public void Clone_Empty ()
+ {
+ an = new AssemblyName ();
+ AssemblyName clone = (AssemblyName) an.Clone ();
+
+ Assert.IsNull (clone.CodeBase, "CodeBase");
+ Assert.IsNull (clone.CultureInfo, "CultureInfo");
+ Assert.IsNull (clone.EscapedCodeBase, "EscapedCodeBase");
+ Assert.AreEqual (AssemblyNameFlags.None, clone.Flags, "Flags");
+ Assert.IsNull (clone.FullName, "FullName");
+ Assert.AreEqual (AssemblyHashAlgorithm.None,
clone.HashAlgorithm, "HashAlgorithm");
+ Assert.IsNull (clone.KeyPair, "KeyPair");
+ Assert.IsNull (clone.Name, "Name");
+ Assert.IsNull (clone.Version, "Version");
+ Assert.AreEqual (AssemblyVersionCompatibility.SameMachine,
+ clone.VersionCompatibility, "VersionCompatibility");
}
+ [Test]
+ public void Clone_Self ()
+ {
+ an = Assembly.GetExecutingAssembly ().GetName ();
+ AssemblyName clone = (AssemblyName) an.Clone ();
+
+ Assert.AreEqual (an.CodeBase, clone.CodeBase, "CodeBase");
+ Assert.AreEqual (an.CultureInfo, clone.CultureInfo,
"CultureInfo");
+ Assert.AreEqual (an.EscapedCodeBase, clone.EscapedCodeBase,
"EscapedCodeBase");
+ Assert.AreEqual (an.Flags, clone.Flags, "Flags");
+ Assert.AreEqual (an.FullName, clone.FullName, "FullName");
+ Assert.AreEqual (an.HashAlgorithm, clone.HashAlgorithm,
"HashAlgorithm");
+ Assert.AreEqual (an.KeyPair, clone.KeyPair, "KeyPair");
+ Assert.AreEqual (an.Name, clone.Name, "Name");
+ Assert.AreEqual (an.Version, clone.Version, "Version");
+ Assert.AreEqual (an.VersionCompatibility,
clone.VersionCompatibility, "VersionCompatibility");
+ }
+
// helpers
private string GetTokenString (byte[] value)
Modified: trunk/mcs/class/corlib/Test/System.Reflection/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection/ChangeLog 2005-04-04
19:00:34 UTC (rev 42533)
+++ trunk/mcs/class/corlib/Test/System.Reflection/ChangeLog 2005-04-04
19:02:51 UTC (rev 42534)
@@ -1,5 +1,14 @@
2005-04-04 Sebastien Pouliot <[EMAIL PROTECTED]>
+ * AssemblyNameTest.cs: Added tests for Clone and serialization without
+ a strongname.
+ * AssemblyNameCas.cs: New. CAS unit tests for AssemblyName.
+ * StrongNameKeyPairTest.cs: Little changes to make it easier to reuse
+ in CAS tests.
+ * StrongNameKeyPairCas.cs: New. CAS unit tests for StrongNameKeyPair.
+
+2005-04-04 Sebastien Pouliot <[EMAIL PROTECTED]>
+
* AssemblyNameTest.cs: Add test for ArgumentNullException on
GetObjectData. Made existing tests more nunit2.2 like.
* ModuleCas.cs: Added new tests for FullyQualifiedName and Name
Added: trunk/mcs/class/corlib/Test/System.Reflection/StrongNameKeyPairCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection/StrongNameKeyPairCas.cs
2005-04-04 19:00:34 UTC (rev 42533)
+++ trunk/mcs/class/corlib/Test/System.Reflection/StrongNameKeyPairCas.cs
2005-04-04 19:02:51 UTC (rev 42534)
@@ -0,0 +1,136 @@
+//
+// StrongNameKeyPairCas.cs - CAS unit tests for
System.Reflection.StrongNameKeyPair
+//
+// Author:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// 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.Reflection;
+using System.Security;
+using System.Security.Permissions;
+
+using MonoTests.System.Reflection;
+
+namespace MonoCasTests.System.Reflection {
+
+ [TestFixture]
+ [Category ("CAS")]
+ public class StrongNameKeyPairCas {
+
+ [SetUp]
+ public void SetUp ()
+ {
+ if (!SecurityManager.SecurityEnabled)
+ Assert.Ignore ("SecurityManager.SecurityEnabled
is OFF");
+ }
+
+ // Partial Trust Tests
+
+ [Test]
+ [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+ [ExpectedException (typeof (SecurityException))]
+ public void CtorByteArray_Deny_Unrestricted ()
+ {
+ new StrongNameKeyPair ((byte[])null);
+ }
+
+ [Test]
+ [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+ [ExpectedException (typeof (SecurityException))]
+ public void CtorFileStream_Deny_Unrestricted ()
+ {
+ new StrongNameKeyPair ((FileStream)null);
+ }
+
+ [Test]
+ [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+ [ExpectedException (typeof (SecurityException))]
+ public void CtorKeyContainer_Deny_Unrestricted ()
+ {
+ new StrongNameKeyPair ((string)null);
+ }
+
+ [Test]
+ public void PublicKey_Deny_Unrestricted ()
+ {
+ PublicKey (new StrongNameKeyPair
(StrongNameKeyPairTest.GetKey ()));
+ }
+
+ [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+ private void PublicKey (StrongNameKeyPair snkp)
+ {
+ Assert.IsNotNull (snkp.PublicKey, "PublicKey");
+ }
+
+ // Partial Trust - Working (minimal permissions)
+
+ [Test]
+ [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode =
true)]
+ public void CtorByteArray_PermitOnly_UnmanagedCode ()
+ {
+ StrongNameKeyPairTest snkpt = new StrongNameKeyPairTest
();
+ snkpt.ConstructorByteArray ();
+ snkpt.ConstructorECMAByteArray ();
+ }
+
+ [Test]
+ public void
CtorFileStream_PermitOnly_UnmanagedCodeFileIOPermission ()
+ {
+ StrongNameKeyPairTest snkpt = new StrongNameKeyPairTest
();
+ FileStream fs = null;
+ try {
+ snkpt.SetUp ();
+ string filename = snkpt.CreateSnkFile ();
+ fs = new FileStream (filename, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);
+ // we needed too much permissions before
calling the
+ // interesting part, so the test is splitted in
two
+ CtorFileStream (fs);
+ }
+ finally {
+ if (fs != null)
+ fs.Close ();
+ snkpt.TearDown ();
+ }
+ }
+
+ [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode =
true)]
+ private void CtorFileStream (FileStream fs)
+ {
+ new StrongNameKeyPair (fs);
+ }
+
+ [Test]
+ [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode =
true)]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void CtorKeyContainer_PermitOnly_UnmanagedCode ()
+ {
+ StrongNameKeyPairTest snkpt = new StrongNameKeyPairTest
();
+ snkpt.ConstructorNullString ();
+ }
+ }
+}
Modified: trunk/mcs/class/corlib/Test/System.Reflection/StrongNameKeyPairTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection/StrongNameKeyPairTest.cs
2005-04-04 19:00:34 UTC (rev 42533)
+++ trunk/mcs/class/corlib/Test/System.Reflection/StrongNameKeyPairTest.cs
2005-04-04 19:02:51 UTC (rev 42534)
@@ -5,7 +5,7 @@
// Sebastien Pouliot <[EMAIL PROTECTED]>
//
// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
@@ -46,6 +46,21 @@
} catch {} // do no affect unit tests
}
+ // helper functions (also required for CAS unit tests)
+ public string CreateSnkFile ()
+ {
+ using (FileStream fs = new FileStream (file,
FileMode.OpenOrCreate)) {
+ fs.Write (test, 0, test.Length);
+ fs.Close ();
+ }
+ return file;
+ }
+
+ static public byte[] GetKey ()
+ {
+ return test;
+ }
+
[Test]
public void ConstructorByteArray ()
{
@@ -81,9 +96,7 @@
[Test]
public void ConstructorFileStream ()
{
- FileStream testFile = new FileStream (file,
FileMode.OpenOrCreate);
- testFile.Write (test, 0, test.Length);
- testFile.Close ();
+ CreateSnkFile ();
FileStream fs = new FileStream (file, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);
snpk = new StrongNameKeyPair (fs);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches