Browse Source

2006-11-08 Sebastien Pouliot <[email protected]>

	* X509Certificate2UICas.cs: New (2.0) CAS tests for X509Certificate2UI
	* X509Certificate2UITest.cs: New (2.0) unit tests for 
	X509Certificate2UI


svn path=/trunk/mcs/; revision=67534
Sebastien Pouliot 19 years ago
parent
commit
b38770bbb7

+ 6 - 0
mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/ChangeLog

@@ -1,3 +1,9 @@
+2006-11-08  Sebastien Pouliot  <[email protected]>
+
+	* X509Certificate2UICas.cs: New (2.0) CAS tests for X509Certificate2UI
+	* X509Certificate2UITest.cs: New (2.0) unit tests for 
+	X509Certificate2UI
+
 2005-09-26  Sebastien Pouliot  <[email protected]>
 
 	* All tests moved to System.dll assembly.

+ 208 - 0
mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509Certificate2UICas.cs

@@ -0,0 +1,208 @@
+//
+// X509Certificate2UITest.cs - CAS tests for X509Certificate2UI
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2006 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.Reflection;
+using System.Security;
+using System.Security.Cryptography.X509Certificates;
+using System.Security.Permissions;
+
+using MonoTests.System.Security.Cryptography.X509Certificates;
+
+namespace MonoCasTests.System.Security.Cryptography.X509Certificates {
+
+	[TestFixture]
+	[Category ("CAS")]
+	public class X509Certificate2UICas {
+
+		private X509Certificate2UITest unit;
+
+		[TestFixtureSetUp]
+		public void FixtureSetUp ()
+		{
+			unit = new X509Certificate2UITest ();
+			unit.FixtureSetUp ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.Deny, Window=UIPermissionWindow.AllWindows)]
+		[ExpectedException (typeof (SecurityException))]
+		public void DisplayCertificate_Deny_Unrestricted ()
+		{
+			unit.DisplayCertificate ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeSubWindows)]
+		[ExpectedException (typeof (SecurityException))]
+		public void DisplayCertificate_PermitOnly_SafeSubWindows ()
+		{
+			unit.DisplayCertificate ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeTopLevelWindows)]
+		[Ignore ("UI would block tests")]
+		public void DisplayCertificate_PermitOnly_SafeTopLevelWindows ()
+		{
+			unit.DisplayCertificate ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeSubWindows)]
+		[ExpectedException (typeof (SecurityException))]
+		public void DisplayCertificate_IntPtr_PermitOnly_SafeSubWindows ()
+		{
+			unit.DisplayCertificate_IntPtr_Zero ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeTopLevelWindows)]
+		[Ignore ("UI would block tests")]
+		public void DisplayCertificate_IntPtr_PermitOnly_SafeTopLevelWindows ()
+		{
+			unit.DisplayCertificate_IntPtr_Zero ();
+		}
+
+
+		[Test]
+		[UIPermission (SecurityAction.Deny, Window = UIPermissionWindow.AllWindows)]
+		[ExpectedException (typeof (SecurityException))]
+		public void SelectFromCollection_Deny_Unrestricted ()
+		{
+			unit.SelectFromCollection ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeSubWindows)]
+		[ExpectedException (typeof (SecurityException))]
+		public void SelectFromCollection_PermitOnly_SafeSubWindows ()
+		{
+			unit.SelectFromCollection ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeTopLevelWindows)]
+		[Ignore ("UI would block tests")]
+		public void SelectFromCollection_PermitOnly_SafeTopLevelWindows ()
+		{
+			unit.SelectFromCollection ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeSubWindows)]
+		[ExpectedException (typeof (SecurityException))]
+		public void SelectFromCollection_IntPtr_PermitOnly_SafeSubWindows ()
+		{
+			unit.SelectFromCollection_IntPtr_Zero ();
+		}
+
+		[Test]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeTopLevelWindows)]
+		[Ignore ("UI would block tests")]
+		public void SelectFromCollection_IntPtr_PermitOnly_SafeTopLevelWindows ()
+		{
+			unit.SelectFromCollection_IntPtr_Zero ();
+		}
+
+		// the methods accepting an IntPtr are documented as having a LinkDemand
+		// and InheritanceDemand for UnmanagedCode. InheritanceDemand doesn't make
+		// sense as the class is sealed but we can test the LinkDemand with reflection
+
+		[Test]
+		[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+		[Ignore ("UI would block tests")]
+		public void LinkDemand_DisplayCertificate_Deny_UnmanagedCode ()
+		{
+			Type[] types = new Type[1] { typeof (X509Certificate2) };
+			MethodInfo mi = typeof (X509Certificate2UI).GetMethod ("DisplayCertificate", types);
+			mi.Invoke (null, new object[1] { unit.x509 });
+			// no LinkDemand on the DisplayCertificate(X509Certificate2) method
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+		[ExpectedException (typeof (SecurityException))]
+		public void LinkDemand_DisplayCertificate_IntPtr_Deny_UnmanagedCode ()
+		{
+			Type[] types = new Type[2] { typeof (X509Certificate2), typeof (IntPtr) };
+			MethodInfo mi = typeof (X509Certificate2UI).GetMethod ("DisplayCertificate", types);
+			mi.Invoke (null, new object[2] { unit.x509, IntPtr.Zero } );
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeTopLevelWindows)]
+		[Ignore ("UI would block tests")]
+		public void LinkDemand_DisplayCertificate_IntPtr_Permit ()
+		{
+			Type[] types = new Type[2] { typeof (X509Certificate2), typeof (IntPtr) };
+			MethodInfo mi = typeof (X509Certificate2UI).GetMethod ("DisplayCertificate", types);
+			mi.Invoke (null, new object[2] { unit.x509, IntPtr.Zero });
+		}
+
+
+		[Test]
+		[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+		[Ignore ("UI would block tests")]
+		public void LinkDemand_SelectFromCollection_Deny_UnmanagedCode ()
+		{
+			Type[] types = new Type[4] { typeof (X509Certificate2Collection), typeof (string), typeof (string), typeof (X509SelectionFlag) };
+			MethodInfo mi = typeof (X509Certificate2UI).GetMethod ("SelectFromCollection", types);
+			mi.Invoke (null, new object[4] { unit.coll, null, null, X509SelectionFlag.MultiSelection });
+			// no LinkDemand on the SelectFromCollection(X509Certificate2Collection,string,string,X509SelectionFlag) method
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+		[ExpectedException (typeof (SecurityException))]
+		public void LinkDemand_SelectFromCollection_IntPtr_Deny_UnmanagedCode ()
+		{
+			Type[] types = new Type[5] { typeof (X509Certificate2Collection), typeof (string), typeof (string), typeof (X509SelectionFlag), typeof (IntPtr) };
+			MethodInfo mi = typeof (X509Certificate2UI).GetMethod ("SelectFromCollection", types);
+			mi.Invoke (null, new object[5] { unit.coll, null, null, X509SelectionFlag.MultiSelection, IntPtr.Zero });
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
+		[UIPermission (SecurityAction.PermitOnly, Window = UIPermissionWindow.SafeTopLevelWindows)]
+		[Ignore ("UI would block tests")]
+		public void LinkDemand_SelectFromCollection_IntPtr_Permit ()
+		{
+			Type[] types = new Type[5] { typeof (X509Certificate2Collection), typeof (string), typeof (string), typeof (X509SelectionFlag), typeof (IntPtr) };
+			MethodInfo mi = typeof (X509Certificate2UI).GetMethod ("SelectFromCollection", types);
+			mi.Invoke (null, new object[5] { unit.coll, null, null, X509SelectionFlag.MultiSelection, IntPtr.Zero });
+		}
+	}
+}
+
+#endif

+ 133 - 0
mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509Certificate2UITest.cs

@@ -0,0 +1,133 @@
+//
+// X509Certificate2UITest.cs - NUnit tests for X509Certificate2UI
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2006 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.Cryptography;
+using System.Security.Cryptography.X509Certificates;
+
+namespace MonoTests.System.Security.Cryptography.X509Certificates {
+
+	[TestFixture]
+	public class X509Certificate2UITest {
+
+		static public byte[] cert = {0x30,0x82,0x01,0xFF,0x30,0x82,0x01,0x6C,0x02,0x05,0x02,0x72,0x00,0x06,0xE8,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,0x05,0x00,0x30,0x5F,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x20,0x30,0x1E,0x06,0x03,0x55,0x04,0x0A,0x13,0x17,0x52,0x53,0x41,0x20,0x44,0x61,0x74,0x61,0x20,0x53,0x65,0x63,0x75,0x72,0x69,0x74,0x79,0x2C,0x20,0x49,0x6E,0x63,0x2E,0x31,0x2E,0x30,0x2C,0x06,0x03,0x55,0x04,0x0B,0x13,0x25,0x53,0x65,0x63,0x75,0x72,0x65,0x20,0x53,0x65,0x72,0x76,0x65,0x72,0x20,0x43,0x65,0x72,0x74,0x69,0x66,0x69,0x63,0x61,0x74,0x69,0x6F,
+			0x6E,0x20,0x41,0x75,0x74,0x68,0x6F,0x72,0x69,0x74,0x79,0x30,0x1E,0x17,0x0D,0x39,0x36,0x30,0x33,0x31,0x32,0x31,0x38,0x33,0x38,0x34,0x37,0x5A,0x17,0x0D,0x39,0x37,0x30,0x33,0x31,0x32,0x31,0x38,0x33,0x38,0x34,0x36,0x5A,0x30,0x61,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x08,0x13,0x0A,0x43,0x61,0x6C,0x69,0x66,0x6F,0x72,0x6E,0x69,0x61,0x31,0x14,0x30,0x12,0x06,0x03,0x55,0x04,0x0A,0x13,0x0B,0x43,0x6F,0x6D,0x6D,0x65,0x72,0x63,0x65,0x4E,0x65,0x74,0x31,0x27,0x30,0x25,0x06,0x03,0x55,0x04,0x0B,0x13,0x1E,0x53,0x65,0x72,0x76,0x65,0x72,0x20,0x43,
+			0x65,0x72,0x74,0x69,0x66,0x69,0x63,0x61,0x74,0x69,0x6F,0x6E,0x20,0x41,0x75,0x74,0x68,0x6F,0x72,0x69,0x74,0x79,0x30,0x70,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x03,0x5F,0x00,0x30,0x5C,0x02,0x55,0x2D,0x58,0xE9,0xBF,0xF0,0x31,0xCD,0x79,0x06,0x50,0x5A,0xD5,0x9E,0x0E,0x2C,0xE6,0xC2,0xF7,0xF9,0xD2,0xCE,0x55,0x64,0x85,0xB1,0x90,0x9A,0x92,0xB3,0x36,0xC1,0xBC,0xEA,0xC8,0x23,0xB7,0xAB,0x3A,0xA7,0x64,0x63,0x77,0x5F,0x84,0x22,0x8E,0xE5,0xB6,0x45,0xDD,0x46,0xAE,0x0A,0xDD,0x00,0xC2,0x1F,0xBA,0xD9,0xAD,0xC0,0x75,0x62,0xF8,0x95,0x82,0xA2,0x80,0xB1,0x82,0x69,0xFA,0xE1,0xAF,
+			0x7F,0xBC,0x7D,0xE2,0x7C,0x76,0xD5,0xBC,0x2A,0x80,0xFB,0x02,0x03,0x01,0x00,0x01,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,0x05,0x00,0x03,0x7E,0x00,0x54,0x20,0x67,0x12,0xBB,0x66,0x14,0xC3,0x26,0x6B,0x7F,0xDA,0x4A,0x25,0x4D,0x8B,0xE0,0xFD,0x1E,0x53,0x6D,0xAC,0xA2,0xD0,0x89,0xB8,0x2E,0x90,0xA0,0x27,0x43,0xA4,0xEE,0x4A,0x26,0x86,0x40,0xFF,0xB8,0x72,0x8D,0x1E,0xE7,0xB7,0x77,0xDC,0x7D,0xD8,0x3F,0x3A,0x6E,0x55,0x10,0xA6,0x1D,0xB5,0x58,0xF2,0xF9,0x0F,0x2E,0xB4,0x10,0x55,0x48,0xDC,0x13,0x5F,0x0D,0x08,0x26,0x88,0xC9,0xAF,0x66,0xF2,0x2C,0x9C,0x6F,0x3D,0xC3,0x2B,0x69,0x28,0x89,0x40,
+			0x6F,0x8F,0x35,0x3B,0x9E,0xF6,0x8E,0xF1,0x11,0x17,0xFB,0x0C,0x98,0x95,0xA1,0xC2,0xBA,0x89,0x48,0xEB,0xB4,0x06,0x6A,0x22,0x54,0xD7,0xBA,0x18,0x3A,0x48,0xA6,0xCB,0xC2,0xFD,0x20,0x57,0xBC,0x63,0x1C };
+
+		internal X509Certificate2 x509;
+		internal X509Certificate2Collection coll;
+
+		[TestFixtureSetUp]
+		public void FixtureSetUp ()
+		{
+			x509 = new X509Certificate2 (cert);
+			coll = new X509Certificate2Collection (x509);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void DisplayCertificate_Null ()
+		{
+			X509Certificate2UI.DisplayCertificate (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (CryptographicException))]
+		public void DisplayCertificate_Certificate_Empty ()
+		{
+			// this is unusable
+			X509Certificate2 empty = new X509Certificate2 ();
+			X509Certificate2UI.DisplayCertificate (empty);
+		}
+
+		[Test]
+		[Ignore ("UI would block tests")]
+		public void DisplayCertificate ()
+		{
+			X509Certificate2UI.DisplayCertificate (x509);
+		}
+
+		[Test]
+		[Ignore ("UI would block tests")]
+		public void DisplayCertificate_IntPtr_Zero ()
+		{
+			X509Certificate2UI.DisplayCertificate (x509, IntPtr.Zero);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void SelectFromCollection_Collection_Null ()
+		{
+			X509Certificate2UI.SelectFromCollection (null, "title", "message", X509SelectionFlag.SingleSelection);
+		}
+
+		[Test]
+		[Ignore ("UI would block tests")]
+		public void SelectFromCollection_Title_Null ()
+		{
+			X509Certificate2UI.SelectFromCollection (coll, null, "message", X509SelectionFlag.SingleSelection);
+		}
+
+		[Test]
+		[Ignore ("UI would block tests")]
+		public void SelectFromCollection_Message_Null ()
+		{
+			X509Certificate2UI.SelectFromCollection (coll, "title", null, X509SelectionFlag.SingleSelection);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void SelectFromCollection_Flags_Invalid ()
+		{
+			X509Certificate2UI.SelectFromCollection (coll, "title", "message", (X509SelectionFlag)Int32.MinValue);
+		}
+
+		[Test]
+		[Ignore ("UI would block tests")]
+		public void SelectFromCollection ()
+		{
+			X509Certificate2Collection empty = new X509Certificate2Collection ();
+			X509Certificate2UI.SelectFromCollection (empty, String.Empty, String.Empty, X509SelectionFlag.SingleSelection);
+		}
+
+		[Test]
+		[Ignore ("UI would block tests")]
+		public void SelectFromCollection_IntPtr_Zero ()
+		{
+			X509Certificate2UI.SelectFromCollection (coll, "title", "message", X509SelectionFlag.MultiSelection);
+		}
+	}
+}
+
+#endif