2004-05-11 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 11 May 2004 11:22:51 +0000 (11:22 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 11 May 2004 11:22:51 +0000 (11:22 -0000)
* PrivateKeyTest.cs: Added new unit tests for better coverage.
* SoftwarePublisherCertificateTest.cs: Added new unit tests for better
coverage.

svn path=/trunk/mcs/; revision=27085

mcs/class/Mono.Security/Test/Mono.Security.Authenticode/ChangeLog
mcs/class/Mono.Security/Test/Mono.Security.Authenticode/PrivateKeyTest.cs
mcs/class/Mono.Security/Test/Mono.Security.Authenticode/SoftwarePublisherCertificateTest.cs

index 9430d28f7b0e91c14ddf03a9f47323ca97a53ca2..eee740f04a684e58b318c3938c97b8f355f50fe5 100644 (file)
@@ -1,3 +1,9 @@
+2004-05-11  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * PrivateKeyTest.cs: Added new unit tests for better coverage.
+       * SoftwarePublisherCertificateTest.cs: Added new unit tests for better
+       coverage.
+
 2004-04-22  Sebastien Pouliot  <sebastien@ximian.com>
 
        * SoftwarePublisherCertificateTest.cs: Ajusted to changes in the
index e5201c96f9f4493822e0a35ab7462e3e5413147f..671dc024c4eabeb20210822115737de31c58c6ec 100644 (file)
@@ -2,13 +2,15 @@
 // PrivateKeyTest.cs - NUnit Test Cases for Private Key File
 //
 // Author:
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot (sebastien@ximian.com)
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell (http://www.novell.com)
 //
 
 using System;
 using System.IO;
+using System.Security.Cryptography;
 using System.Text;
 
 using Mono.Security.Authenticode;
@@ -101,6 +103,7 @@ public class PrivateKeyTest : Assertion {
                AssertNotNull ("msnopwd.RSA", pvk.RSA);
                Assert ("msnopwd.Encrypted", !pvk.Encrypted);
                Assert ("msnopwd.Weak", pvk.Weak);
+               AssertEquals ("msnopwd.KeyType", 2, pvk.KeyType);
        }
 
        // this will convert a PVK file without a password to a PVK file
@@ -195,6 +198,85 @@ public class PrivateKeyTest : Assertion {
                Assert ("nomorepwd.Encrypted", !pvk.Encrypted);
                Assert ("nomorepwd.Weak", pvk.Weak);
        }
+       
+       [Test]
+       public void CreatePVK () 
+       {
+               PrivateKey pvk = new PrivateKey ();
+               pvk.KeyType = 2;
+               pvk.RSA = RSA.Create ();
+               string rsa1 = pvk.RSA.ToXmlString (true);
+               pvk.Save (testfile, "mono");
+
+               pvk = PrivateKey.CreateFromFile (testfile, "mono");
+               AssertNotNull ("new.RSA", pvk.RSA);
+               string rsa2 = pvk.RSA.ToXmlString (true);
+               AssertEquals ("new.RSA identical", rsa1, rsa2);
+               Assert ("new.Encrypted", pvk.Encrypted);
+               Assert ("new.Weak", !pvk.Weak);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentNullException))]
+       public void Save_Null () 
+       {
+               PrivateKey pvk = new PrivateKey ();
+               pvk.Save (null, "mono");
+       }
+       
+       [Test]
+       [ExpectedException (typeof (CryptographicException))]
+       public void BadMagic () 
+       {
+               byte[] bad = (byte[]) nopwd.Clone ();
+               bad [0] = 0x00;
+               WriteBuffer (bad);
+               PrivateKey pvk = PrivateKey.CreateFromFile (testfile, null);
+       }
+       
+       [Test]
+       [ExpectedException (typeof (CryptographicException))]
+       public void BadHeader () 
+       {
+               byte[] bad = (byte[]) nopwd.Clone ();
+               bad [4] = 0x01;
+               WriteBuffer (bad);
+               PrivateKey pvk = PrivateKey.CreateFromFile (testfile, null);
+       }
+
+       [Test]
+       [ExpectedException (typeof (CryptographicException))]
+       public void SaltWithoutPassword () 
+       {
+               byte[] bad = (byte[]) nopwd.Clone ();
+               int saltlen = BitConverter.ToInt32 (bad, 16);
+               int keylen = BitConverter.ToInt32 (bad, 20);
+               // preserve total length
+               saltlen += 8;
+               keylen -= 8;
+               // modify blob
+               byte[] data = BitConverter.GetBytes (saltlen);
+               Buffer.BlockCopy (data, 0, bad, 16, data.Length); 
+               data = BitConverter.GetBytes (keylen);
+               Buffer.BlockCopy (data, 0, bad, 20, data.Length); 
+               // save-n-load          
+               WriteBuffer (bad);
+               PrivateKey pvk = PrivateKey.CreateFromFile (testfile, null);
+       }
+       
+       [Test]
+       [ExpectedException (typeof (ArgumentNullException))]
+       public void CreateFromFile_Null () 
+       {
+               PrivateKey pvk = PrivateKey.CreateFromFile (null, "password");
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentNullException))]
+       public void Constructor_Null () 
+       {
+               PrivateKey pvk = new PrivateKey (null, "password");
+       }
 }
 
 }
index 54e99f49e60b4c243a427417fc9f4386f8e527bc..ba2933a8b7f039e478c63c228a6cbb258768b590 100644 (file)
@@ -3,9 +3,10 @@
 //     - NUnit Test Cases for Software Publisher Certificate
 //
 // Author:
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot (sebastien@ximian.com)
 //
 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell (http://www.novell.com)
 //
 
 using System;
@@ -495,5 +496,28 @@ namespace MonoTests.Mono.Security.Authenticode {
                        AssertEquals ("navy.Certificates", 3, newerspc.Certificates.Count);
                        AssertEquals ("navy.Crl", 2, newerspc.Crls.Count);
                }
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void Constructor_Null () 
+               {
+                       SoftwarePublisherCertificate spc = new SoftwarePublisherCertificate (null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void Constructor_BadOid () 
+               {
+                       byte[] bad = (byte[]) certonly.Clone ();
+                       bad [9] -= 1;
+                       SoftwarePublisherCertificate spc = new SoftwarePublisherCertificate (bad);
+               }
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void CreateFromFile_Null () 
+               {
+                       SoftwarePublisherCertificate spc = SoftwarePublisherCertificate.CreateFromFile (null);
+               }
        }
 }