diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2005-09-26 18:08:58 +0400 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2005-09-26 18:08:58 +0400 |
commit | 6a080fe2bdbe19466ea1d53037a41e749fff1720 (patch) | |
tree | bfcf209567e7bdedbb8ed0b048c25b6c1552cc97 /mcs/class/System.Security/Test | |
parent | c09f673f6d7a7e7d61b0731522095f7ad4d7f205 (diff) |
In Test/System.Security.Cryptography:
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* Asn*.cs, Oid*.cs: Moved to System.dll
In Test/System.Security.Permissions:
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* StorePermissionAttributeTest.cs: Moved in System.dll
In Test/System.Security.Cryptography.X509Certificates:
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* All tests moved to System.dll assembly.
In System.Security.Cryptography:
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* Asn*.cs, Oid*.cs: Moved to System.dll
In System.Security.Permissions:
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* Store*.cs: Moved in System.dll
In .:
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* System.Security.dll.sources: Remove all X509 related classes.
* System.Security_test.dll.sources: Remove all X509 related tests.
* System.Security.Cryptography.X509Certificates/*.cs: moved to
System.dll assembly.
* Test/System.Security.Cryptography.X509Certificates/*.cs: moved to
System.dll assembly.
In System.Security.Cryptography.X509Certificates:
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* All classes moved in System.dll
svn path=/trunk/mcs/; revision=50770
Diffstat (limited to 'mcs/class/System.Security/Test')
16 files changed, 10 insertions, 2650 deletions
diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/ChangeLog b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/ChangeLog index dd5ddec7812..cafefa7b780 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/ChangeLog +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/ChangeLog @@ -1,26 +1,3 @@ -2005-04-23 Sebastien Pouliot <sebastien@ximian.com> +2005-09-26 Sebastien Pouliot <sebastien@ximian.com> - * X509BasicConstraintsExtensionTest.cs, X509ChainPolicyTest.cs, - X509EnhancedKeyUsageExtensionTest.cs, X509ExtensionTest.cs, - X509KeyUsageExtensionTest.cs, X509StoreTest.cs, - X509SubjectKeyIdentifierExtensionTest.cs: Changed X509CertificateEx to - X509Certificate2 and re-activated some tests on Windows that were - fixed in beta2. - -2005-01-17 Sebastien Pouliot <sebastien@ximian.com> - - * X509BasicConstraintsExtensionTest.cs: New. Unit tests. - * X509EnhancedKeyUsageExtensionTest.cs: New. Unit tests. - * X509ExtensionTest.cs: New. Unit tests. - * X509KeyUsageExtensionTest.cs: New. Unit tests. - * X509SubjectKeyIdentifierExtensionTest.cs: New. Unit tests. - -2003-11-08 Sebastien Pouliot <spouliot@videotron.ca> - - * X509ChainElementCollectionTest.cs: New. Unit tests for - X509ChainElementCollection. - * X509ChainElementEnumeratorTest.cs: New. Unit tests for - X509ChainElementEnumerator. - * X509ChainPolicyTest.cs: New. Unit tests for X509ChainPolicy. - * X509ChainTest.cs: New. (Incomplete) Unit tests for X509Chain. - * X509StoreTest.cs: New. (Incomplete) Unit tests for X509Store. + * All tests moved to System.dll assembly. diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509BasicConstraintsExtensionTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509BasicConstraintsExtensionTest.cs deleted file mode 100644 index 29d38060cc3..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509BasicConstraintsExtensionTest.cs +++ /dev/null @@ -1,285 +0,0 @@ -// -// X509BasicConstraintsExtensionTest.cs -// - NUnit tests for X509BasicConstraintsExtension -// -// 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.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography.X509Certificates { - - [TestFixture] - public class X509BasicConstraintsExtensionTest { - - private const string oid = "2.5.29.19"; - private const string fname = "Basic Constraints"; - - [Test] - public void ConstructorEmpty () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (); - Assert.IsFalse (bc.Critical, "Critical"); - Assert.IsNull (bc.RawData, "RawData"); - Assert.AreEqual (oid, bc.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, bc.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (String.Empty, bc.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, bc.Format (false), "Format(false)"); - } - - [Test] - public void ConstructorEmpty_CertificateAuthority () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (); - Assert.AreEqual (false, bc.CertificateAuthority, "CertificateAuthority"); - } - - [Test] - public void ConstructorEmpty_HasPathLengthConstraint () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (); - Assert.AreEqual (false, bc.HasPathLengthConstraint, "HasPathLengthConstraint"); - } - - [Test] - public void ConstructorEmpty_PathLengthConstraint () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (); - Assert.AreEqual (0, bc.PathLengthConstraint, "PathLengthConstraint"); - } - - [Test] - public void ConstructorAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x06, 0x01, 0x01, 0xFF, 0x02, 0x01, 0x01 }); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (aed, true); - Assert.IsTrue (bc.Critical, "Critical"); - Assert.AreEqual (8, bc.RawData.Length, "RawData"); // original Oid ignored - Assert.AreEqual (oid, bc.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, bc.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.IsTrue (bc.CertificateAuthority, "CertificateAuthority"); - Assert.IsTrue (bc.HasPathLengthConstraint, "HasPathLengthConstraint"); - Assert.AreEqual (1, bc.PathLengthConstraint, "PathLengthConstraint"); - Assert.AreEqual ("Subject Type=CA" + Environment.NewLine + "Path Length Constraint=1" + Environment.NewLine, bc.Format (true), "Format(true)"); - Assert.AreEqual ("Subject Type=CA, Path Length Constraint=1", bc.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsn () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[0]); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (aed, true); - Assert.AreEqual (String.Empty, bc.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, bc.Format (false), "Format(false)"); - bool b = bc.CertificateAuthority; - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsnTag () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x05, 0x00 }); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (aed, true); - Assert.AreEqual ("0500", bc.Format (true), "Format(true)"); - Assert.AreEqual ("0500", bc.Format (false), "Format(false)"); - bool b = bc.CertificateAuthority; - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsnLength () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x30, 0x01 }); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (aed, true); - Assert.AreEqual ("3001", bc.Format (true), "Format(true)"); - Assert.AreEqual ("3001", bc.Format (false), "Format(false)"); - bool b = bc.CertificateAuthority; - } - - [Test] - public void ConstructorAsnEncodedData_SmallestValid () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x30, 0x00 }); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (aed, true); - Assert.IsFalse (bc.CertificateAuthority, "CertificateAuthority"); - Assert.IsFalse (bc.HasPathLengthConstraint, "HasPathLengthConstraint"); - Assert.AreEqual (0, bc.PathLengthConstraint, "PathLengthConstraint"); - Assert.AreEqual ("30-00", BitConverter.ToString (bc.RawData), "RawData"); - Assert.AreEqual ("Subject Type=End Entity" + Environment.NewLine + "Path Length Constraint=None" + Environment.NewLine, bc.Format (true), "Format(true)"); - Assert.AreEqual ("Subject Type=End Entity, Path Length Constraint=None", bc.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (NullReferenceException))] - public void ConstructorAsnEncodedData_Null () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (null, true); - } - - [Test] - public void Constructor_TrueTrueZero () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (true, true, 0, true); - Assert.IsTrue (bc.CertificateAuthority, "CertificateAuthority"); - Assert.IsTrue (bc.HasPathLengthConstraint, "HasPathLengthConstraint"); - Assert.AreEqual (0, bc.PathLengthConstraint, "PathLengthConstraint"); - Assert.AreEqual ("30-06-01-01-FF-02-01-00", BitConverter.ToString (bc.RawData), "RawData"); - Assert.AreEqual ("Subject Type=CA" + Environment.NewLine + "Path Length Constraint=0" + Environment.NewLine, bc.Format (true), "Format(true)"); - Assert.AreEqual ("Subject Type=CA, Path Length Constraint=0", bc.Format (false), "Format(false)"); - } - - [Test] - public void Constructor_TrueTrueMaxInt () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (true, true, Int32.MaxValue, true); - Assert.IsTrue (bc.CertificateAuthority, "CertificateAuthority"); - Assert.IsTrue (bc.HasPathLengthConstraint, "HasPathLengthConstraint"); - Assert.AreEqual (Int32.MaxValue, bc.PathLengthConstraint, "PathLengthConstraint"); - Assert.AreEqual ("30-09-01-01-FF-02-04-7F-FF-FF-FF", BitConverter.ToString (bc.RawData), "RawData"); - Assert.AreEqual ("Subject Type=CA" + Environment.NewLine + "Path Length Constraint=2147483647" + Environment.NewLine, bc.Format (true), "Format(true)"); - Assert.AreEqual ("Subject Type=CA, Path Length Constraint=2147483647", bc.Format (false), "Format(false)"); - } - - [Test] - public void Constructor_TrueFalseNegative () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (true, false, -1, true); - Assert.IsTrue (bc.CertificateAuthority, "CertificateAuthority"); - Assert.IsFalse (bc.HasPathLengthConstraint, "HasPathLengthConstraint"); - Assert.AreEqual (0, bc.PathLengthConstraint, "PathLengthConstraint"); - Assert.AreEqual ("30-03-01-01-FF", BitConverter.ToString (bc.RawData), "RawData"); - Assert.AreEqual ("Subject Type=CA" + Environment.NewLine + "Path Length Constraint=None" + Environment.NewLine, bc.Format (true), "Format(true)"); - Assert.AreEqual ("Subject Type=CA, Path Length Constraint=None", bc.Format (false), "Format(false)"); - } - - [Test] - public void Constructor_FalseTruePositive () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (false, true, 1, true); - Assert.IsFalse (bc.CertificateAuthority, "CertificateAuthority"); - Assert.IsTrue (bc.HasPathLengthConstraint, "HasPathLengthConstraint"); - Assert.AreEqual (1, bc.PathLengthConstraint, "PathLengthConstraint"); - Assert.AreEqual ("30-03-02-01-01", BitConverter.ToString (bc.RawData), "RawData"); - Assert.AreEqual ("Subject Type=End Entity" + Environment.NewLine + "Path Length Constraint=1" + Environment.NewLine, bc.Format (true), "Format(true)"); - Assert.AreEqual ("Subject Type=End Entity, Path Length Constraint=1", bc.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (ArgumentOutOfRangeException))] - public void Constructor_FalseTrueNegative () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (false, true, -1, true); - } - - [Test] - public void Constructor_FalseFalseNegative () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (false, false, -1, true); - Assert.IsFalse (bc.CertificateAuthority, "CertificateAuthority"); - Assert.IsFalse (bc.HasPathLengthConstraint, "HasPathLengthConstraint"); - Assert.AreEqual (0, bc.PathLengthConstraint, "PathLengthConstraint"); - Assert.AreEqual ("30-00", BitConverter.ToString (bc.RawData), "RawData"); - Assert.AreEqual ("Subject Type=End Entity" + Environment.NewLine + "Path Length Constraint=None" + Environment.NewLine, bc.Format (true), "Format(true)"); - Assert.AreEqual ("Subject Type=End Entity, Path Length Constraint=None", bc.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void WrongExtension_X509KeyUsageExtension () - { - X509KeyUsageExtension ku = new X509KeyUsageExtension (); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (); - bc.CopyFrom (ku); - } - - [Test] - public void WrongExtension_X509Extension () - { - X509Extension ex = new X509Extension ("1.2.3", new byte[0], true); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (false, true, 1, false); - Assert.IsFalse (bc.Critical, "Critical"); - bc.CopyFrom (ex); - Assert.IsTrue (bc.Critical, "Critical"); - Assert.AreEqual (String.Empty, BitConverter.ToString (bc.RawData), "RawData"); - Assert.AreEqual ("1.2.3", bc.Oid.Value, "Oid.Value"); - Assert.IsNull (bc.Oid.FriendlyName, "Oid.FriendlyName"); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void WrongExtension_X509Extension_CertificateAuthority () - { - X509Extension ex = new X509Extension ("1.2.3", new byte[0], true); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (); - bc.CopyFrom (ex); - bool b = bc.CertificateAuthority; - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void WrongAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new byte[0]); - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (false, true, 1, false); - bc.CopyFrom (aed); // note: not the same behaviour than using the constructor! - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void CopyFrom_Null () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (); - bc.CopyFrom (null); - } - - [Test] - public void CopyFrom_Self () - { - X509BasicConstraintsExtension bc = new X509BasicConstraintsExtension (false, false, -1, true); - Assert.IsTrue (bc.Critical, "Critical"); - byte[] raw = bc.RawData; - Assert.AreEqual ("30-00", BitConverter.ToString (raw), "RawData"); - - AsnEncodedData aed = new AsnEncodedData (raw); - X509BasicConstraintsExtension copy = new X509BasicConstraintsExtension (aed, false); - Assert.IsFalse (copy.Critical, "Critical"); - Assert.AreEqual (2, copy.RawData.Length, "RawData"); // original Oid ignored - Assert.AreEqual (oid, copy.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, copy.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.IsFalse (copy.CertificateAuthority, "CertificateAuthority"); - Assert.IsFalse (copy.HasPathLengthConstraint, "HasPathLengthConstraint"); - Assert.AreEqual (0, copy.PathLengthConstraint, "PathLengthConstraint"); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ChainPolicyTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ChainPolicyTest.cs deleted file mode 100644 index 2f1adb9a982..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ChainPolicyTest.cs +++ /dev/null @@ -1,169 +0,0 @@ -// -// X509ChainPolicyTest.cs - NUnit tests for X509ChainPolicy -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// -// (C) 2003 Motus Technologies Inc. (http://www.motus.com) -// - -#if NET_2_0 - -using NUnit.Framework; - -using System; -using System.Collections; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography.X509Certificates { - - [TestFixture] - public class X509ChainPolicyTest : Assertion { - - static string signingTimeOid = "1.2.840.113549.1.9.5"; - - private X509ChainPolicy GetPolicy () - { - X509Chain c = new X509Chain (); - return c.ChainPolicy; - } - - [Test] - public void Default () - { - X509ChainPolicy cp = GetPolicy (); - // default properties - AssertEquals ("ApplicationPolicy", 0, cp.ApplicationPolicy.Count); - AssertEquals ("CertificatePolicy", 0, cp.CertificatePolicy.Count); - AssertEquals ("ExtraStore", 0, cp.ExtraStore.Count); - AssertEquals ("RevocationFlag", X509RevocationFlag.ExcludeRoot, cp.RevocationFlag); - AssertEquals ("RevocationMode", X509RevocationMode.Online, cp.RevocationMode); - AssertEquals ("UrlRetrievalTimeout", 0, cp.UrlRetrievalTimeout.Ticks); - AssertEquals ("VerificationFlags", X509VerificationFlags.NoFlag, cp.VerificationFlags); - DateTime vt = cp.VerificationTime; - Assert ("VerificationTime", ((vt <= DateTime.Now) && (vt > DateTime.Now.AddMinutes (-1)))); - } - - [Test] - public void ApplicationPolicy () - { - X509ChainPolicy cp = GetPolicy (); - cp.ApplicationPolicy.Add (new Oid (signingTimeOid)); - AssertEquals ("ApplicationPolicy", 1, cp.ApplicationPolicy.Count); - } - - [Test] - public void CertificatePolicy () - { - X509ChainPolicy cp = GetPolicy (); - cp.CertificatePolicy.Add (new Oid (signingTimeOid)); - AssertEquals ("CertificatePolicy", 1, cp.CertificatePolicy.Count); - } - - [Test] - public void ExtraStore () - { - X509ChainPolicy cp = GetPolicy (); - cp.ExtraStore.Add (new X509Certificate2 ()); - AssertEquals ("ExtraStore", 1, cp.ExtraStore.Count); - } - - [Test] - public void RevocationFlag () - { - X509ChainPolicy cp = GetPolicy (); - cp.RevocationFlag = X509RevocationFlag.EndCertificateOnly; - AssertEquals ("EndCertificateOnly", X509RevocationFlag.EndCertificateOnly, cp.RevocationFlag); - cp.RevocationFlag = X509RevocationFlag.EntireChain; - AssertEquals ("EntireChain", X509RevocationFlag.EntireChain, cp.RevocationFlag); - cp.RevocationFlag = X509RevocationFlag.ExcludeRoot; - AssertEquals ("ExcludeRoot", X509RevocationFlag.ExcludeRoot, cp.RevocationFlag); - } - - [Test] - public void RevocationMode () - { - X509ChainPolicy cp = GetPolicy (); - cp.RevocationMode = X509RevocationMode.NoCheck; - AssertEquals ("NoCheck", X509RevocationMode.NoCheck, cp.RevocationMode); - cp.RevocationMode = X509RevocationMode.Offline; - AssertEquals ("Offline", X509RevocationMode.Offline, cp.RevocationMode); - cp.RevocationMode = X509RevocationMode.Online; - AssertEquals ("Online", X509RevocationMode.Online, cp.RevocationMode); - } - - [Test] - public void UrlRetrievalTimeout () - { - X509ChainPolicy cp = GetPolicy (); - cp.UrlRetrievalTimeout = new TimeSpan (100); - AssertEquals ("TimeSpan=100", 100, cp.UrlRetrievalTimeout.Ticks); - cp.UrlRetrievalTimeout = new TimeSpan (0); - AssertEquals ("TimeSpan=0", 0, cp.UrlRetrievalTimeout.Ticks); - } - - [Test] - public void VerificationFlags () - { - X509ChainPolicy cp = GetPolicy (); - cp.VerificationFlags = X509VerificationFlags.AllFlags; - AssertEquals ("AllFlags", X509VerificationFlags.AllFlags, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.AllowUnknownCertificateAuthority; - AssertEquals ("AllowUnknownCertificateAuthority", X509VerificationFlags.AllowUnknownCertificateAuthority, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreCertificateAuthorityRevocationUnknown; - AssertEquals ("IgnoreCertificateAuthorityRevocationUnknown", X509VerificationFlags.IgnoreCertificateAuthorityRevocationUnknown, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreCtlNotTimeValid; - AssertEquals ("IgnoreCtlNotTimeValid", X509VerificationFlags.IgnoreCtlNotTimeValid, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreCtlSignerRevocationUnknown; - AssertEquals ("IgnoreCtlSignerRevocationUnknown", X509VerificationFlags.IgnoreCtlSignerRevocationUnknown, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreEndRevocationUnknown; - AssertEquals ("IgnoreEndRevocationUnknown", X509VerificationFlags.IgnoreEndRevocationUnknown, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreInvalidBasicConstraints; - AssertEquals ("IgnoreInvalidBasicConstraints", X509VerificationFlags.IgnoreInvalidBasicConstraints, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreInvalidName; - AssertEquals ("IgnoreInvalidName", X509VerificationFlags.IgnoreInvalidName, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreInvalidPolicy; - AssertEquals ("IgnoreInvalidPolicy", X509VerificationFlags.IgnoreInvalidPolicy, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreNotTimeNested; - AssertEquals ("IgnoreNotTimeNested", X509VerificationFlags.IgnoreNotTimeNested, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreNotTimeValid; - AssertEquals ("IgnoreNotTimeValid", X509VerificationFlags.IgnoreNotTimeValid, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreRootRevocationUnknown; - AssertEquals ("IgnoreRootRevocationUnknown", X509VerificationFlags.IgnoreRootRevocationUnknown, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.IgnoreWrongUsage; - AssertEquals ("IgnoreWrongUsage", X509VerificationFlags.IgnoreWrongUsage, cp.VerificationFlags); - cp.VerificationFlags = X509VerificationFlags.NoFlag; - AssertEquals ("NoFlag", X509VerificationFlags.NoFlag, cp.VerificationFlags); - } - - [Test] - public void Reset () - { - X509ChainPolicy cp = GetPolicy (); - cp.ApplicationPolicy.Add (new Oid (signingTimeOid)); - cp.CertificatePolicy.Add (new Oid (signingTimeOid)); - cp.ExtraStore.Add (new X509Certificate2 ()); - cp.RevocationFlag = X509RevocationFlag.EndCertificateOnly; - cp.RevocationMode = X509RevocationMode.NoCheck; - cp.UrlRetrievalTimeout = new TimeSpan (100); - cp.VerificationFlags = X509VerificationFlags.AllFlags; - DateTime vt = cp.VerificationTime; - Assert ("VerificationTime", ((vt <= DateTime.Now) && (vt > DateTime.Now.AddMinutes (-1)))); - cp.Reset (); - Assert ("VerificationTime-Reset", (vt != cp.VerificationTime)); - // default properties - AssertEquals ("ApplicationPolicy", 0, cp.ApplicationPolicy.Count); - AssertEquals ("CertificatePolicy", 0, cp.CertificatePolicy.Count); - AssertEquals ("ExtraStore", 0, cp.ExtraStore.Count); - AssertEquals ("RevocationFlag", X509RevocationFlag.ExcludeRoot, cp.RevocationFlag); - AssertEquals ("RevocationMode", X509RevocationMode.Online, cp.RevocationMode); - AssertEquals ("UrlRetrievalTimeout", 0, cp.UrlRetrievalTimeout.Ticks); - AssertEquals ("VerificationFlags", X509VerificationFlags.NoFlag, cp.VerificationFlags); - vt = cp.VerificationTime; - Assert ("VerificationTime", ((vt <= DateTime.Now) && (vt > DateTime.Now.AddMinutes (-1)))); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ChainTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ChainTest.cs deleted file mode 100644 index 953607bcf42..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ChainTest.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -// X509ChainTest.cs - NUnit tests for X509Chain -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// -// (C) 2003 Motus Technologies Inc. (http://www.motus.com) -// - -#if NET_2_0 - -using NUnit.Framework; - -using System; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography.X509Certificates { - - [TestFixture] - public class X509ChainTest : Assertion { - - [Test] - public void ConstructorEmpty () - { - X509Chain c = new X509Chain (); - // default properties - AssertEquals ("ChainElements", 0, c.ChainElements.Count); - AssertNotNull ("ChainPolicy", c.ChainPolicy); - AssertEquals ("ChainStatus", 0, c.ChainStatus.Length); - } - - [Test] - public void ConstructorMachineContextFalse () - { - X509Chain c = new X509Chain (false); - // default properties - AssertEquals ("ChainElements", 0, c.ChainElements.Count); - AssertNotNull ("ChainPolicy", c.ChainPolicy); - AssertEquals ("ChainStatus", 0, c.ChainStatus.Length); - } - - [Test] - public void ConstructorMachineContextTrue () - { - X509Chain c = new X509Chain (true); - // default properties - AssertEquals ("ChainElements", 0, c.ChainElements.Count); - AssertNotNull ("ChainPolicy", c.ChainPolicy); - AssertEquals ("ChainStatus", 0, c.ChainStatus.Length); - } - - [Test] - public void StaticCreation () - { - X509Chain c = X509Chain.Create (); - // default properties - AssertEquals ("ChainElements", 0, c.ChainElements.Count); - AssertNotNull ("ChainPolicy", c.ChainPolicy); - AssertEquals ("ChainStatus", 0, c.ChainStatus.Length); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509EnhancedKeyUsageExtensionTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509EnhancedKeyUsageExtensionTest.cs deleted file mode 100644 index be42e12efa6..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509EnhancedKeyUsageExtensionTest.cs +++ /dev/null @@ -1,224 +0,0 @@ -// -// X509EnhancedKeyUsageExtensionTest.cs -// - NUnit tests for X509EnhancedKeyUsageExtension -// -// 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.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography.X509Certificates { - - [TestFixture] - public class X509EnhancedKeyUsageExtensionTest { - - private const string oid = "2.5.29.37"; - private const string fname = "Enhanced Key Usage"; - - [Test] - public void ConstructorEmpty () - { - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (); - Assert.IsFalse (eku.Critical, "Critical"); - Assert.IsNull (eku.RawData, "RawData"); - Assert.AreEqual (oid, eku.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, eku.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (String.Empty, eku.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, eku.Format (false), "Format(false)"); - } - - [Test] - public void ConstructorEmpty_EnhancedKeyUsages () - { - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (); - Assert.AreEqual (0, eku.EnhancedKeyUsages.Count, "EnhancedKeyUsages"); - } - - [Test] - public void ConstructorAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 }); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, true); - Assert.IsTrue (eku.Critical, "Critical"); - Assert.AreEqual (7, eku.RawData.Length, "RawData"); // original Oid ignored - Assert.AreEqual (oid, eku.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, eku.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (1, eku.EnhancedKeyUsages.Count, "EnhancedKeyUsages"); - Assert.AreEqual ("1.2.3.4", eku.EnhancedKeyUsages[0].Value, "EnhancedKeyUsages Oid"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, eku.Format (true), "Format(true)"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", eku.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsn () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[0]); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, true); - Assert.AreEqual (String.Empty, eku.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, eku.Format (false), "Format(false)"); - OidCollection oc = eku.EnhancedKeyUsages; - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsnTag () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x05, 0x00 }); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, true); - OidCollection oc = eku.EnhancedKeyUsages; - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsnLength () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x30, 0x01 }); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, true); - OidCollection oc = eku.EnhancedKeyUsages; - } - - [Test] - [ExpectedException (typeof (NullReferenceException))] - public void ConstructorAsnEncodedData_Null () - { - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension ((AsnEncodedData)null, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorOidCollection_Null () - { - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension ((OidCollection)null, true); - } - - [Test] - public void ConstructorOidCollection () - { - OidCollection oc = new OidCollection (); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (oc, true); - Assert.AreEqual ("30-00", BitConverter.ToString (eku.RawData), "RawData"); - Assert.AreEqual (0, eku.EnhancedKeyUsages.Count, "Count 0"); - Assert.AreEqual ("Information Not Available", eku.Format (true), "Format(true)"); - Assert.AreEqual ("Information Not Available", eku.Format (false), "Format(false)"); - oc.Add (new Oid ("1.2.3.4")); - Assert.AreEqual (0, eku.EnhancedKeyUsages.Count, "Count still 0"); - int n = eku.EnhancedKeyUsages.Add (new Oid ("1.2.3")); - Assert.AreEqual (0, n, "Add"); - Assert.AreEqual (0, eku.EnhancedKeyUsages.Count, "Count again 0"); // readonly! - Assert.AreEqual (1, oc.Count, "Count 1 - oc"); - Assert.AreEqual ("1.2.3.4", oc [0].Value, "Value - oc"); - - oc.Add (new Oid ("1.3.6.1.5.5.7.3.1")); - eku = new X509EnhancedKeyUsageExtension (oc, true); - Assert.AreEqual (2, eku.EnhancedKeyUsages.Count, "Count 2"); - Assert.AreEqual ("1.2.3.4", eku.EnhancedKeyUsages[0].Value, "Value - 1"); - Assert.AreEqual ("1.3.6.1.5.5.7.3.1", eku.EnhancedKeyUsages[1].Value, "Value - 2"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine + "Server Authentication (1.3.6.1.5.5.7.3.1)" + Environment.NewLine, - eku.Format (true), "Format(true)"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4), Server Authentication (1.3.6.1.5.5.7.3.1)", eku.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void WrongExtension_X509EnhancedKeyUsageExtension () - { - X509KeyUsageExtension ku = new X509KeyUsageExtension (); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (); - eku.CopyFrom (ku); - } - - [Test] - public void WrongExtension_X509Extension () - { - X509Extension ex = new X509Extension ("1.2.3", new byte[0], true); - OidCollection oc = new OidCollection (); - oc.Add (new Oid ("1.2.3.4")); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (oc, false); - Assert.AreEqual (1, eku.EnhancedKeyUsages.Count, "EnhancedKeyUsages"); - Assert.IsFalse (eku.Critical, "Critical"); - eku.CopyFrom (ex); - Assert.IsTrue (eku.Critical, "Critical"); - Assert.AreEqual (String.Empty, BitConverter.ToString (eku.RawData), "RawData"); - Assert.AreEqual ("1.2.3", eku.Oid.Value, "Oid.Value"); - Assert.IsNull (eku.Oid.FriendlyName, "Oid.FriendlyName"); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void WrongExtension_X509Extension_KeyUsages () - { - X509Extension ex = new X509Extension ("1.2.3", new byte[0], true); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (); - eku.CopyFrom (ex); - Assert.AreEqual (0, eku.EnhancedKeyUsages.Count, "EnhancedKeyUsages"); - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void WrongAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new byte[0]); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (new OidCollection (), true); - eku.CopyFrom (aed); // note: not the same behaviour than using the constructor! - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void CopyFrom_Null () - { - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (); - eku.CopyFrom (null); - } - - [Test] - public void CopyFrom_Self () - { - OidCollection oc = new OidCollection (); - oc.Add (new Oid ("1.2.3.4")); - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (oc, true); - Assert.IsTrue (eku.Critical, "Critical"); - byte[] raw = eku.RawData; - Assert.AreEqual ("30-05-06-03-2A-03-04", BitConverter.ToString (raw), "RawData"); - - AsnEncodedData aed = new AsnEncodedData (raw); - X509EnhancedKeyUsageExtension copy = new X509EnhancedKeyUsageExtension (aed, false); - Assert.IsFalse (copy.Critical, "Critical"); - Assert.AreEqual (7, copy.RawData.Length, "RawData"); // original Oid ignored - Assert.AreEqual (oid, copy.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, copy.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (1, copy.EnhancedKeyUsages.Count, "EnhancedKeyUsages"); - Assert.AreEqual ("1.2.3.4", copy.EnhancedKeyUsages[0].Value, "EnhancedKeyUsages Oid"); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ExtensionTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ExtensionTest.cs deleted file mode 100644 index e8bfbd17d24..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509ExtensionTest.cs +++ /dev/null @@ -1,189 +0,0 @@ -// -// X509ExtensionTest.cs -// - NUnit tests for X509Extension -// -// 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.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography.X509Certificates { - - // used to test the protected constructor properly - public class X509Ex : X509Extension { - - public X509Ex () - { - } - } - - [TestFixture] - public class X509ExtensionTest { - - [Test] - public void ConstructorEmpty () - { - X509Ex ex = new X509Ex (); - Assert.IsFalse (ex.Critical, "Critical"); - Assert.IsNull (ex.RawData, "RawData"); - Assert.IsNull (ex.Oid, "Oid"); - Assert.AreEqual (String.Empty, ex.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, ex.Format (false), "Format(false)"); - - ex.Critical = true; - Assert.IsTrue (ex.Critical, "Critical 2"); - ex.Oid = new Oid ("2.5.29.37"); - Assert.AreEqual ("2.5.29.37", ex.Oid.Value, "Oid.Value"); - Assert.AreEqual ("Enhanced Key Usage", ex.Oid.FriendlyName, "Oid.FriendlyName"); - ex.RawData = new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 }; - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, ex.Format (true), "Format(true)"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", ex.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorAsnEncodedData_WithNullOid () - { - AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 }); - X509Extension eku = new X509Extension (aed, true); - } - - [Test] - public void ConstructorAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new Oid ("2.5.29.37"), new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 }); - X509Extension ex = new X509Extension (aed, true); - Assert.IsTrue (ex.Critical, "Critical"); - Assert.AreEqual (7, ex.RawData.Length, "RawData"); // original Oid ignored - Assert.AreEqual ("2.5.29.37", ex.Oid.Value, "Oid.Value"); - Assert.AreEqual ("Enhanced Key Usage", ex.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, ex.Format (true), "Format(true)"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", ex.Format (false), "Format(false)"); - } - - [Test] - public void ConstructorAsnEncodedData_BadAsn () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[0]); - X509Extension ex = new X509Extension (aed, true); - Assert.AreEqual (String.Empty, ex.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, ex.Format (false), "Format(false)"); - // no exception for an "empty" extension - } - - [Test] - public void ConstructorAsnEncodedData_BadAsnTag () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x05, 0x00 }); - X509Extension ex = new X509Extension (aed, true); - Assert.AreEqual ("05 00", ex.Format (true), "Format(true)"); - Assert.AreEqual ("05 00", ex.Format (false), "Format(false)"); - // no exception for an "unknown" (ASN.1 NULL) extension - } - - [Test] - public void ConstructorAsnEncodedData_BadAsnLength () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x30, 0x01 }); - X509Extension ex = new X509Extension (aed, true); - Assert.AreEqual ("30 01", ex.Format (true), "Format(true)"); - Assert.AreEqual ("30 01", ex.Format (false), "Format(false)"); - // no exception for an bad (invalid length) extension - } - - [Test] - [ExpectedException (typeof (NullReferenceException))] - public void ConstructorAsnEncodedData_Null () - { - X509Extension ex = new X509Extension ((AsnEncodedData)null, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorOid_Null () - { - X509Extension ex = new X509Extension ((Oid)null, new byte[] { 0x30, 0x01 }, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorOid_RawNull () - { - X509Extension ex = new X509Extension (new Oid ("1.2.3"), null, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorString_Null () - { - X509Extension ex = new X509Extension ((string)null, new byte[] { 0x30, 0x01 }, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorString_RawNull () - { - X509Extension ex = new X509Extension ("1.2.3", null, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void CopyFrom_Null () - { - X509Ex ex = new X509Ex (); - ex.CopyFrom (null); - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void CopyFrom_AsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new Oid ("2.5.29.37"), new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 }); - // this is recognized as an Enhanced Key Usages extension - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, aed.Format (true), "aed.Format(true)"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", aed.Format (false), "aed.Format(false)"); - X509Ex ex = new X509Ex (); - // but won't be accepted by the CopyFrom method (no a X509Extension) - ex.CopyFrom (aed); - } - - [Test] - public void Build_NetscapeCertTypeExtension () - { - X509Extension ex = new X509Extension (new Oid ("2.16.840.1.113730.1.1"), new byte[] { 0x03, 0x02, 0x00, 0xFF }, false); - // strangely no NewLine is being appended to Format(true) - Assert.AreEqual ("SSL Client Authentication, SSL Server Authentication, SMIME, Signature, Unknown cert type, SSL CA, SMIME CA, Signature CA (ff)", ex.Format (true), "aed.Format(true)"); - Assert.AreEqual ("SSL Client Authentication, SSL Server Authentication, SMIME, Signature, Unknown cert type, SSL CA, SMIME CA, Signature CA (ff)", ex.Format (false), "aed.Format(false)"); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509KeyUsageExtensionTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509KeyUsageExtensionTest.cs deleted file mode 100644 index 56631e8573b..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509KeyUsageExtensionTest.cs +++ /dev/null @@ -1,251 +0,0 @@ -// -// X509KeyUsageExtensionTest.cs - NUnit tests for X509KeyUsageExtension -// -// 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.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography.X509Certificates { - - [TestFixture] - public class X509KeyUsageExtensionTest { - - private const string oid = "2.5.29.15"; - private const string fname = "Key Usage"; - - [Test] - public void ConstructorEmpty () - { - X509KeyUsageExtension ku = new X509KeyUsageExtension (); - Assert.IsFalse (ku.Critical , "Critical"); - Assert.IsNull (ku.RawData, "RawData"); - Assert.AreEqual (oid, ku.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, ku.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (String.Empty, ku.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, ku.Format (false), "Format(false)"); - } - - [Test] - [Category ("NotDotNet")] // MS bug reported as http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=34cdc5e9-c7f9-4f55-b390-288bfef6e44e - public void ConstructorEmpty_KeyUsage () - { - X509KeyUsageExtension ku = new X509KeyUsageExtension (); - Assert.AreEqual (0, (int)ku.KeyUsages, "KeyUsages"); - } - - [Test] - public void ConstructorAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x03, 0x01, 0x00 }); - X509KeyUsageExtension ku = new X509KeyUsageExtension (aed, true); - Assert.IsTrue (ku.Critical, "Critical"); - Assert.AreEqual (3, ku.RawData.Length, "RawData"); // original Oid ignored - Assert.AreEqual (oid, ku.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, ku.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual ("Information Not Available", ku.Format (true), "Format(true)"); - Assert.AreEqual ("Information Not Available", ku.Format (false), "Format(false)"); - Assert.AreEqual (0, (int)ku.KeyUsages, "KeyUsages"); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsn () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[0]); - X509KeyUsageExtension ku = new X509KeyUsageExtension (aed, true); - Assert.AreEqual (String.Empty, ku.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, ku.Format (false), "Format(false)"); - X509KeyUsageFlags kuf = ku.KeyUsages; - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsnTag () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x05, 0x00 }); - X509KeyUsageExtension ku = new X509KeyUsageExtension (aed, true); - Assert.AreEqual ("0500", ku.Format (true), "Format(true)"); - Assert.AreEqual ("0500", ku.Format (false), "Format(false)"); - X509KeyUsageFlags kuf = ku.KeyUsages; - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsnLength () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x03, 0x01 }); - X509KeyUsageExtension ku = new X509KeyUsageExtension (aed, true); - Assert.AreEqual ("0301", ku.Format (true), "Format(true)"); - Assert.AreEqual ("0301", ku.Format (false), "Format(false)"); - X509KeyUsageFlags kuf = ku.KeyUsages; - } - - [Test] - [ExpectedException (typeof (NullReferenceException))] - public void ConstructorAsnEncodedData_Null () - { - X509KeyUsageExtension ku = new X509KeyUsageExtension (null, true); - } - - [Test] - // [ExpectedException (typeof (...))] - public void ConstructorKeyUsage_Invalid () - { - X509KeyUsageFlags kuf = (X509KeyUsageFlags)Int32.MinValue; - X509KeyUsageExtension ku = new X509KeyUsageExtension (kuf, false); - Assert.AreEqual (0, (int)ku.KeyUsages, "KeyUsages"); - Assert.AreEqual ("03-01-00", BitConverter.ToString (ku.RawData), "RawData"); - Assert.AreEqual ("Information Not Available", ku.Format (true), "Format(true)"); - Assert.AreEqual ("Information Not Available", ku.Format (false), "Format(false)"); - } - - private X509KeyUsageExtension ValidateKeyUsage (X509KeyUsageFlags kuf, string rawdata) - { - X509KeyUsageExtension ku = new X509KeyUsageExtension (kuf, false); - Assert.IsFalse (ku.Critical, kuf.ToString () + ".Critical"); - Assert.AreEqual (rawdata, BitConverter.ToString (ku.RawData), kuf.ToString () + ".RawData"); - Assert.AreEqual (oid, ku.Oid.Value, kuf.ToString () + ".Oid.Value"); - Assert.AreEqual (fname, ku.Oid.FriendlyName, kuf.ToString () + ".Oid.FriendlyName"); - Assert.AreEqual (kuf, ku.KeyUsages, kuf.ToString () + ".KeyUsages"); - return ku; - } - - [Test] - public void ConstructorKeyUsage_CRLSign () - { - X509KeyUsageExtension ku = ValidateKeyUsage (X509KeyUsageFlags.CrlSign, "03-02-01-02"); - Assert.AreEqual ("Off-line CRL Signing, CRL Signing (02)", ku.Format (false), "CRLSign"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.DataEncipherment, "03-02-04-10"); - Assert.AreEqual ("Data Encipherment (10)", ku.Format (false), "DataEncipherment"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.DecipherOnly, "03-03-07-00-80"); - Assert.AreEqual ("Decipher Only (00 80)", ku.Format (false), "DecipherOnly"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.DigitalSignature, "03-02-07-80"); - Assert.AreEqual ("Digital Signature (80)", ku.Format (false), "DigitalSignature"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.EncipherOnly, "03-02-00-01"); - Assert.AreEqual ("Encipher Only (01)", ku.Format (false), "EncipherOnly"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.KeyAgreement, "03-02-03-08"); - Assert.AreEqual ("Key Agreement (08)", ku.Format (false), "KeyAgreement"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.KeyCertSign, "03-02-02-04"); - Assert.AreEqual ("Certificate Signing (04)", ku.Format (false), "KeyCertSign"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.KeyEncipherment, "03-02-05-20"); - Assert.AreEqual ("Key Encipherment (20)", ku.Format (false), "KeyEncipherment"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.NonRepudiation, "03-02-06-40"); - Assert.AreEqual ("Non-Repudiation (40)", ku.Format (false), "NonRepudiation"); - - ValidateKeyUsage (X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.DecipherOnly, "03-03-07-10-80"); - ValidateKeyUsage (X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.DecipherOnly, "03-03-07-80-80"); - ValidateKeyUsage (X509KeyUsageFlags.EncipherOnly | X509KeyUsageFlags.DecipherOnly, "03-03-07-01-80"); - ValidateKeyUsage (X509KeyUsageFlags.NonRepudiation | X509KeyUsageFlags.DataEncipherment, "03-02-04-50"); - - ku = ValidateKeyUsage (X509KeyUsageFlags.CrlSign | X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.DecipherOnly | - X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.EncipherOnly | X509KeyUsageFlags.KeyAgreement | - X509KeyUsageFlags.KeyCertSign | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.NonRepudiation, "03-03-07-FF-80"); - Assert.AreEqual ("Digital Signature, Non-Repudiation, Key Encipherment, Data Encipherment, Key Agreement, Certificate Signing, Off-line CRL Signing, CRL Signing, Encipher Only, Decipher Only (ff 80)" + Environment.NewLine, - ku.Format (true), "All"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void WrongExtension_X509EnhancedKeyUsageExtension () - { - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (); - X509KeyUsageExtension ku = new X509KeyUsageExtension (); - ku.CopyFrom (eku); - } - - [Test] - public void WrongExtension_X509Extension () - { - X509Extension ex = new X509Extension ("1.2.3", new byte [0], true); - X509KeyUsageExtension ku = new X509KeyUsageExtension (X509KeyUsageFlags.CrlSign, true); - ku.CopyFrom (ex); - Assert.IsTrue (ku.Critical, "Critical"); - Assert.AreEqual (String.Empty, BitConverter.ToString (ku.RawData), "RawData"); - Assert.AreEqual ("1.2.3", ku.Oid.Value, "Oid.Value"); - Assert.IsNull (ku.Oid.FriendlyName, "Oid.FriendlyName"); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void WrongExtension_X509Extension_KeyUsages () - { - X509Extension ex = new X509Extension ("1.2.3", new byte[0], true); - X509KeyUsageExtension ku = new X509KeyUsageExtension (); - ku.CopyFrom (ex); - Assert.AreEqual (0, ku.KeyUsages, "KeyUsages"); - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void WrongAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new byte[0]); - X509KeyUsageExtension ku = new X509KeyUsageExtension (X509KeyUsageFlags.CrlSign, true); - ku.CopyFrom (aed); // note: not the same behaviour than using the constructor! - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void CopyFrom_Null () - { - X509KeyUsageExtension eku = new X509KeyUsageExtension (); - eku.CopyFrom (null); - } - - [Test] - public void CopyFrom_Self () - { - X509KeyUsageExtension ku = new X509KeyUsageExtension (X509KeyUsageFlags.CrlSign, true); - Assert.IsTrue (ku.Critical, "Critical"); - byte[] raw = ku.RawData; - Assert.AreEqual ("03-02-01-02", BitConverter.ToString (raw), "RawData"); - - AsnEncodedData aed = new AsnEncodedData (raw); - X509KeyUsageExtension copy = new X509KeyUsageExtension (aed, false); - Assert.IsFalse (copy.Critical, "Critical"); - Assert.AreEqual (4, copy.RawData.Length, "RawData"); // original Oid ignored - Assert.AreEqual (oid, copy.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, copy.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (X509KeyUsageFlags.CrlSign, copy.KeyUsages, "KeyUsages"); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509StoreTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509StoreTest.cs deleted file mode 100644 index 103b1ebeff0..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509StoreTest.cs +++ /dev/null @@ -1,259 +0,0 @@ -// -// X509StoreTest.cs - NUnit tests for X509Store -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// -// (C) 2003 Motus Technologies Inc. (http://www.motus.com) -// - -#if NET_2_0 - -using NUnit.Framework; - -using System; -using System.Collections; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography.X509Certificates { - - [TestFixture] - public class X509StoreTest : Assertion { - - [Test] - public void ConstructorEmpty () - { - X509Store xs = new X509Store (); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "MY", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - - [Test] - public void ConstructorStoreLocationCurrentUser () - { - X509Store xs = new X509Store (StoreLocation.CurrentUser); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "MY", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreLocationLocalMachine () - { - X509Store xs = new X509Store (StoreLocation.LocalMachine); - // default properties - AssertEquals ("Location", StoreLocation.LocalMachine, xs.Location); - AssertEquals ("Name", "MY", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - - [Test] - public void ConstructorStoreStringAddressBook () - { - X509Store xs = new X509Store ("AddressBook"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "AddressBook", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreStringAuthRoot () - { - X509Store xs = new X509Store ("AuthRoot"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "AuthRoot", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreStringCertificateAuthority () - { - X509Store xs = new X509Store ("CA"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "CA", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreStringDisallowed () - { - X509Store xs = new X509Store ("Disallowed"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "Disallowed", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreStringMy () - { - X509Store xs = new X509Store ("My"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "My", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreStringRoot () - { - X509Store xs = new X509Store ("Root"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "Root", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreStringTrustedPeople () - { - X509Store xs = new X509Store ("TrustedPeople"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "TrustedPeople", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreStringTrustedPublisher () - { - X509Store xs = new X509Store ("TrustedPublisher"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "TrustedPublisher", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreStringMono () - { - // mono isn't defined the StoreName - X509Store xs = new X509Store ("Mono"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "Mono", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreNameAddressBook () - { - X509Store xs = new X509Store (StoreName.AddressBook); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "AddressBook", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreNameAuthRoot () - { - X509Store xs = new X509Store (StoreName.AuthRoot); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "AuthRoot", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreNameCertificateAuthority () - { - X509Store xs = new X509Store (StoreName.CertificateAuthority); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "CA", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreNameDisallowed () - { - X509Store xs = new X509Store (StoreName.Disallowed); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "Disallowed", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreNameMy () { - X509Store xs = new X509Store (StoreName.My); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "My", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreNameRoot () - { - X509Store xs = new X509Store (StoreName.Root); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "Root", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreNameTrustedPeople () - { - X509Store xs = new X509Store (StoreName.TrustedPeople); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "TrustedPeople", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - [Test] - public void ConstructorStoreNameTrustedPublisher () - { - X509Store xs = new X509Store (StoreName.TrustedPublisher); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "TrustedPublisher", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - } - - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void AddEmptyCertificateToReadOnlyNonExistingStore () - { - // mono isn't defined the StoreName - X509Store xs = new X509Store ("NonExistingStore"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "NonExistingStore", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - xs.Open (OpenFlags.ReadOnly); - xs.Add (new X509Certificate2 ()); - xs.Close (); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void AddEmptyCertificateToReadWriteNonExistingStore () - { - // mono isn't defined the StoreName - X509Store xs = new X509Store ("NonExistingStore"); - // default properties - AssertEquals ("Location", StoreLocation.CurrentUser, xs.Location); - AssertEquals ("Name", "NonExistingStore", xs.Name); - AssertNotNull ("Certificates", xs.Certificates); - xs.Open (OpenFlags.ReadWrite); - xs.Add (new X509Certificate2 ()); - xs.Close (); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509SubjectKeyIdentifierExtensionTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509SubjectKeyIdentifierExtensionTest.cs deleted file mode 100644 index f1868f2ebad..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.X509Certificates/X509SubjectKeyIdentifierExtensionTest.cs +++ /dev/null @@ -1,292 +0,0 @@ -// -// X509SubjectKeyIdentifierExtensionTest.cs -// - NUnit tests for X509SubjectKeyIdentifierExtension -// -// 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.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography.X509Certificates { - - [TestFixture] - public class X509SubjectKeyIdentifierExtensionTest { - - private const string oid = "2.5.29.14"; - private const string fname = "Subject Key Identifier"; - - [Test] - public void ConstructorEmpty () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (); - Assert.IsFalse (ski.Critical, "Critical"); - Assert.IsNull (ski.RawData, "RawData"); - Assert.AreEqual (oid, ski.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, ski.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (String.Empty, ski.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, ski.Format (false), "Format(false)"); - } - - [Test] - public void ConstructorEmpty_SubjectKeyIdentifier () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (); - Assert.IsNull (ski.SubjectKeyIdentifier, "SubjectKeyIdentifier"); - } - - [Test] - public void ConstructorAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x04, 0x08, 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (aed, true); - Assert.IsTrue (ski.Critical, "Critical"); - Assert.AreEqual (oid, ski.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, ski.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual ("04-08-01-23-45-67-89-AB-CD-EF", BitConverter.ToString (ski.RawData), "RawData"); - Assert.AreEqual ("0123456789ABCDEF", ski.SubjectKeyIdentifier, "SubjectKeyIdentifier"); - Assert.AreEqual ("01 23 45 67 89 ab cd ef" + Environment.NewLine, ski.Format (true), "Format(true)"); - Assert.AreEqual ("01 23 45 67 89 ab cd ef", ski.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsn () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[0]); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (aed, true); - Assert.AreEqual (String.Empty, ski.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, ski.Format (false), "Format(false)"); - string s = ski.SubjectKeyIdentifier; - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsnTag () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x05, 0x00 }); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (aed, true); - Assert.AreEqual ("0500", ski.Format (true), "Format(true)"); - Assert.AreEqual ("0500", ski.Format (false), "Format(false)"); - string s = ski.SubjectKeyIdentifier; - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void ConstructorAsnEncodedData_BadAsnLength () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x30, 0x01 }); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (aed, true); - Assert.AreEqual ("3001", ski.Format (true), "Format(true)"); - Assert.AreEqual ("3001", ski.Format (false), "Format(false)"); - string s = ski.SubjectKeyIdentifier; - } - - [Test] - public void ConstructorAsnEncodedData_SmallestValid () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", new byte[] { 0x04, 0x00 }); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (aed, true); - Assert.AreEqual (String.Empty, ski.SubjectKeyIdentifier, "SubjectKeyIdentifier"); - Assert.AreEqual ("04-00", BitConverter.ToString (ski.RawData), "RawData"); - Assert.AreEqual ("Information Not Available", ski.Format (true), "Format(true)"); - Assert.AreEqual ("Information Not Available", ski.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (NullReferenceException))] - public void ConstructorAsnEncodedData_Null () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ((AsnEncodedData)null, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorByteArray_Null () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ((byte[])null, true); - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void ConstructorByteArray_Empty () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (new byte[0], true); - } - - [Test] - public void ConstructorByteArray_20 () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (new byte[20], true); - Assert.IsTrue (ski.Critical, "Critical"); - Assert.AreEqual ("04-14-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString (ski.RawData), "RawData"); - Assert.AreEqual (oid, ski.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, ski.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual ("0000000000000000000000000000000000000000", ski.SubjectKeyIdentifier, "SubjectKeyIdentifier"); - Assert.AreEqual ("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" + Environment.NewLine, ski.Format (true), "Format(true)"); - Assert.AreEqual ("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00", ski.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorString_Null () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ((String)null, true); - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void ConstructorString_Empty () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (String.Empty, true); - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void ConstructorString_Single () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ("f", false); - } - - [Test] - public void ConstructorString () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ("ffFFfFFf", false); - Assert.IsFalse (ski.Critical, "Critical"); - Assert.AreEqual ("04-04-FF-FF-FF-FF", BitConverter.ToString (ski.RawData), "RawData"); - Assert.AreEqual (oid, ski.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, ski.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual ("FFFFFFFF", ski.SubjectKeyIdentifier, "SubjectKeyIdentifier"); - Assert.AreEqual ("ff ff ff ff" + Environment.NewLine, ski.Format (true), "Format(true)"); - Assert.AreEqual ("ff ff ff ff", ski.Format (false), "Format(false)"); - } - - [Test] - public void ConstructorString_NotHex () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ("Mono::", true); - Assert.IsTrue (ski.Critical, "Critical"); - Assert.AreEqual ("04-03-FF-FF-FF", BitConverter.ToString (ski.RawData), "RawData"); - Assert.AreEqual (oid, ski.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, ski.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual ("FFFFFF", ski.SubjectKeyIdentifier, "SubjectKeyIdentifier"); - Assert.AreEqual ("ff ff ff" + Environment.NewLine, ski.Format (true), "Format(true)"); - Assert.AreEqual ("ff ff ff", ski.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorPublicKey_Null () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ((PublicKey)null, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorPublicKeyHash_Null () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (null, X509SubjectKeyIdentifierHashAlgorithm.Sha1, true); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void WrongExtension_X509KeyUsageExtension () - { - X509KeyUsageExtension ku = new X509KeyUsageExtension (); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (); - ski.CopyFrom (ku); - } - - [Test] - public void WrongExtension_X509Extension () - { - X509Extension ex = new X509Extension ("1.2.3", new byte[0], true); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ("www.go-mono.com", false); // odd length - Assert.IsFalse (ski.Critical, "Critical"); - Assert.AreEqual ("FFFFFFFFFFFFFF", ski.SubjectKeyIdentifier, "SubjectKeyIdentifier"); - Assert.AreEqual ("ff ff ff ff ff ff ff" + Environment.NewLine, ski.Format (true), "Format(true)"); - Assert.AreEqual ("ff ff ff ff ff ff ff", ski.Format (false), "Format(false)"); - - ski.CopyFrom (ex); - Assert.IsTrue (ski.Critical, "Critical"); - Assert.AreEqual (String.Empty, BitConverter.ToString (ski.RawData), "RawData"); - Assert.AreEqual ("1.2.3", ski.Oid.Value, "Oid.Value"); - Assert.IsNull (ski.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (String.Empty, ski.Format (true), "Format(true)"); - Assert.AreEqual (String.Empty, ski.Format (false), "Format(false)"); - } - - [Test] - [ExpectedException (typeof (CryptographicException))] - public void WrongExtension_X509Extension_CertificateAuthority () - { - X509Extension ex = new X509Extension ("1.2.3", new byte[0], true); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (); - ski.CopyFrom (ex); - string s = ski.SubjectKeyIdentifier; - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void WrongAsnEncodedData () - { - AsnEncodedData aed = new AsnEncodedData (new byte[0]); - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ("www.mono-project.com", false); - ski.CopyFrom (aed); // note: not the same behaviour than using the constructor! - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void CopyFrom_Null () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension (); - ski.CopyFrom (null); - } - - [Test] - public void CopyFrom_Self () - { - X509SubjectKeyIdentifierExtension ski = new X509SubjectKeyIdentifierExtension ("ff", true); - Assert.IsTrue (ski.Critical, "Critical"); - byte[] raw = ski.RawData; - Assert.AreEqual ("04-01-FF", BitConverter.ToString (raw), "RawData"); - - AsnEncodedData aed = new AsnEncodedData (raw); - X509SubjectKeyIdentifierExtension copy = new X509SubjectKeyIdentifierExtension (aed, false); - Assert.IsFalse (copy.Critical, "Critical"); - Assert.AreEqual ("04-01-FF", BitConverter.ToString (copy.RawData), "copy.RawData"); - Assert.AreEqual (oid, copy.Oid.Value, "Oid.Value"); - Assert.AreEqual (fname, copy.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual ("FF", copy.SubjectKeyIdentifier, "SubjectKeyIdentifier"); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/AsnEncodedDataTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography/AsnEncodedDataTest.cs deleted file mode 100644 index 1caab680a2a..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography/AsnEncodedDataTest.cs +++ /dev/null @@ -1,280 +0,0 @@ -// -// AsnEncodedDataTest.cs - NUnit tests for AsnEncodedData -// -// Author: -// Sebastien Pouliot <sebastien@ximian.com> -// -// (C) 2003 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. -// - -#if NET_2_0 - -using NUnit.Framework; - -using System; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace MonoTests.System.Security.Cryptography { - - [TestFixture] - public class AsnEncodedDataTest { - - static byte[] asnNullBytes = { 0x05, 0x00 }; - static string asnNullString = "05 00"; - static byte[] asnLongBytes = { 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 }; - static string asnLongString = "30 5c 02 55 2d 58 e9 bf f0 31 cd 79 06 50 5a d5 9e 0e 2c e6 c2 f7 f9 d2 ce 55 64 85 b1 90 9a 92 b3 36 c1 bc ea c8 23 b7 ab 3a a7 64 63 77 5f 84 22 8e e5 b6 45 dd 46 ae 0a dd 00 c2 1f ba d9 ad c0 75 62 f8 95 82 a2 80 b1 82 69 fa e1 af 7f bc 7d e2 7c 76 d5 bc 2a 80 fb 02 03 01 00 01"; - - [Test] - public void Constructor_StringData () - { - AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes); - Assert.AreEqual ("oid", aed.Oid.Value, "Oid.Value"); - Assert.IsNull (aed.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (BitConverter.ToString (asnNullBytes), BitConverter.ToString (aed.RawData), "RawData"); - Assert.AreEqual (asnNullString, aed.Format (true), "Format"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void Constructor_StringNullData () - { - string oid = null; // do not confuse compiler - AsnEncodedData aed = new AsnEncodedData (oid, asnNullBytes); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void Constructor_StringDataNull () - { - AsnEncodedData aed = new AsnEncodedData ("oid", null); - } - - [Test] - public void Constructor_OidData () - { - Oid o = new Oid ("1.0"); - AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes); - Assert.AreEqual ("1.0", aed.Oid.Value, "Oid.Value"); - Assert.IsNull (aed.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (BitConverter.ToString (asnNullBytes), BitConverter.ToString (aed.RawData), "RawData"); - Assert.AreEqual (asnNullString, aed.Format (true), "Format"); - } - - [Test] - public void Constructor_OidNullData () - { - // this is legal - http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=38336cfa-3b97-47da-ad4e-9522d557f001 - Oid o = null; - AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes); - Assert.IsNull (aed.Oid, "Oid"); - Assert.AreEqual (BitConverter.ToString (asnNullBytes), BitConverter.ToString (aed.RawData), "RawData"); - Assert.AreEqual (asnNullString, aed.Format (true), "Format"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void Constructor_OidDataNull () - { - Oid o = new Oid ("1.0"); - AsnEncodedData aed = new AsnEncodedData (o, null); - } - - [Test] - public void Constructor_Asn () - { - AsnEncodedData aed = new AsnEncodedData ("oid", asnNullBytes); - AsnEncodedData aed2 = new AsnEncodedData (aed); - Assert.AreEqual (aed.Oid.Value, aed2.Oid.Value, "Oid.Value"); - Assert.AreEqual (aed.Oid.FriendlyName, aed2.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (BitConverter.ToString (aed.RawData), BitConverter.ToString (aed2.RawData), "RawData"); - string s1 = aed.Format (false); - string s2 = aed.Format (true); - Assert.AreEqual (s1, s2, "Format"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void Constructor_ByteArrayNull () - { - byte[] array = null; - AsnEncodedData aed = new AsnEncodedData (array); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void Constructor_AsnNull () - { - AsnEncodedData asn = null; - AsnEncodedData aed = new AsnEncodedData (asn); - } - - [Test] - public void Oid_CreatedNull () - { - AsnEncodedData aed = new AsnEncodedData ((Oid)null, asnNullBytes); - Assert.IsNull (aed.Oid, "Oid 1"); - Oid o = new Oid ("1.2.3"); - aed.Oid = o; - Assert.AreEqual ("1.2.3", aed.Oid.Value, "Oid 2"); - o.Value = "1.2.4"; - Assert.AreEqual ("1.2.3", aed.Oid.Value, "Oid 3"); // didn't change (copy) - aed.Oid = null; - Assert.IsNull (aed.Oid, "Oid 4"); - } - - [Test] - public void Oid () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.3", asnNullBytes); - Assert.AreEqual ("1.2.3", aed.Oid.Value, "Oid 1"); - aed.Oid.Value = "1.2.4"; - Assert.AreEqual ("1.2.4", aed.Oid.Value, "Oid 2"); // didn't change (copy) - aed.Oid = null; - Assert.IsNull (aed.Oid, "Oid 3"); - } - - [Test] - public void RawData_CanModify () - { - byte[] data = (byte[])asnNullBytes.Clone (); - AsnEncodedData aed = new AsnEncodedData ("1.2.3", data); - Assert.AreEqual (asnNullString, aed.Format (true), "Format 1"); - data[0] = 0x06; - Assert.AreEqual (asnNullString, aed.Format (true), "Format 2"); ; // didn't change (copy) - aed.RawData[0] = 0x07; - Assert.AreEqual ("07 00", aed.Format (true), "Format 3"); // changed! - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void RawData () - { - AsnEncodedData aed = new AsnEncodedData ((Oid)null, asnNullBytes); - Assert.AreEqual (asnNullString, aed.Format (true), "Format 1"); - aed.RawData = null; - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void CopyFrom_Null () - { - AsnEncodedData aed = new AsnEncodedData ((Oid)null, asnNullBytes); - aed.CopyFrom (null); - } - - [Test] - public void CopyFrom () - { - Oid o = new Oid ("1.2.3"); - byte[] data = (byte[])asnNullBytes.Clone (); - AsnEncodedData aed = new AsnEncodedData (o, asnNullBytes); - AsnEncodedData copy = new AsnEncodedData ((Oid)null, new byte [0]); - copy.CopyFrom (aed); - - Assert.AreEqual (aed.Oid.Value, copy.Oid.Value, "Oid 1"); - Assert.AreEqual (aed.Format (true), copy.Format (true), "Format 1"); - - aed.Oid = new Oid ("1.2.4"); - aed.RawData = new byte[1]; - - Assert.AreEqual ("1.2.3", copy.Oid.Value, "Oid 2"); - Assert.AreEqual (asnNullString, copy.Format (true), "Format 2"); - } - - [Test] - public void Format () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes); - Assert.AreEqual ("1.2.840.113549.1.1.1", aed.Oid.Value, "Oid.Value"); - Assert.AreEqual ("RSA", aed.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (BitConverter.ToString (asnLongBytes), BitConverter.ToString (aed.RawData), "RawData"); - string result = aed.Format (false); - Assert.AreEqual (asnLongString, result, "Format(false)"); - } - - [Test] - public void FormatMultiline () - { - AsnEncodedData aed = new AsnEncodedData ("1.2.840.113549.1.1.1", asnLongBytes); - Assert.AreEqual ("1.2.840.113549.1.1.1", aed.Oid.Value, "Oid.Value"); - Assert.AreEqual ("RSA", aed.Oid.FriendlyName, "Oid.FriendlyName"); - Assert.AreEqual (BitConverter.ToString (asnLongBytes), BitConverter.ToString (aed.RawData), "RawData"); - string result = aed.Format (true); - Assert.AreEqual (asnLongString, result, "Format(true)"); - } - - [Test] - public void Build_X509EnhancedKeyUsageExtension () - { - AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x05, 0x06, 0x03, 0x2A, 0x03, 0x04 }); - Assert.AreEqual ("30 05 06 03 2a 03 04", aed.Format (true), "Format(true)"); - Assert.AreEqual ("30 05 06 03 2a 03 04", aed.Format (false), "Format(false)"); - aed.Oid = new Oid ("2.5.29.37"); - // and now "AsnEncodedData" knows how to (magically) decode the data without involving the class - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, aed.Format (true), "aed.Format(true)"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", aed.Format (false), "aed.Format(false)"); - // compare with the output of the "appropriate" class - X509EnhancedKeyUsageExtension eku = new X509EnhancedKeyUsageExtension (aed, false); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)" + Environment.NewLine, eku.Format (true), "eku.Format(true)"); - Assert.AreEqual ("Unknown Key Usage (1.2.3.4)", eku.Format (false), "eku.Format(false)"); - } - - [Test] - // note: important to emulate in Mono because we need it for SSL/TLS - public void Build_NetscapeCertTypeExtension () - { - AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x03, 0x02, 0x01, 0x06 }); - Assert.AreEqual ("03 02 01 06", aed.Format (true), "Format(true)"); - Assert.AreEqual ("03 02 01 06", aed.Format (false), "Format(false)"); - aed.Oid = new Oid ("2.16.840.1.113730.1.1"); - // and now "AsnEncodedData" knows how to (magically) decode the data without involving the class - Assert.AreEqual ("SSL CA, SMIME CA (06)", aed.Format (true), "aed.Format(true)"); - Assert.AreEqual ("SSL CA, SMIME CA (06)", aed.Format (false), "aed.Format(false)"); - // note that the Fx doesn't "really" support this extension - // and strangely no NewLine is being appended to Format(true) - // finally this also means that the Oid "knowns" about oid not used in the Fx itself - Assert.AreEqual ("Netscape Cert Type", aed.Oid.FriendlyName, "FriendlyName"); - // anyway the answer is most probably CryptoAPI - } - - [Test] - // note: important to emulate in Mono because we need it for SSL/TLS - public void Build_SubjectAltNameExtension () - { - AsnEncodedData aed = new AsnEncodedData (new byte[] { 0x30, 0x16, 0x82, 0x14, 0x77, 0x77, 0x77, 0x2E, 0x6D, 0x6F, 0x6E, 0x6F, 0x2D, 0x70, 0x72, 0x6F, 0x6A, 0x65, 0x63, 0x74, 0x2E, 0x63, 0x6F, 0x6D }); - Assert.AreEqual ("30 16 82 14 77 77 77 2e 6d 6f 6e 6f 2d 70 72 6f 6a 65 63 74 2e 63 6f 6d", aed.Format (true), "Format(true)"); - Assert.AreEqual ("30 16 82 14 77 77 77 2e 6d 6f 6e 6f 2d 70 72 6f 6a 65 63 74 2e 63 6f 6d", aed.Format (false), "Format(false)"); - aed.Oid = new Oid ("2.5.29.17"); - // and now "AsnEncodedData" knows how to (magically) decode the data without involving the class - Assert.AreEqual ("DNS Name=www.mono-project.com" + Environment.NewLine, aed.Format (true), "aed.Format(true)"); - Assert.AreEqual ("DNS Name=www.mono-project.com", aed.Format (false), "aed.Format(false)"); - // note that the Fx doesn't "really" support this extension - // finally this also means that the Oid "knowns" about oid not used in the Fx itself - Assert.AreEqual ("Subject Alternative Name", aed.Oid.FriendlyName, "FriendlyName"); - // anyway the answer is most probably CryptoAPI - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/ChangeLog b/mcs/class/System.Security/Test/System.Security.Cryptography/ChangeLog index c0a6be97648..1a3ca8f748b 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography/ChangeLog +++ b/mcs/class/System.Security/Test/System.Security.Cryptography/ChangeLog @@ -1,3 +1,7 @@ +2005-09-26 Sebastien Pouliot <sebastien@ximian.com> + + * Asn*.cs, Oid*.cs: Moved to System.dll + 2005-04-27 Sebastien Pouliot <sebastien@ximian.com> * ProtectedDataTest.cs: Updated to NUnit 2.2 API to use Ignore it the @@ -9,32 +13,10 @@ * CryptographicAttributeTest.cs: Changed class names to match beta2. -2005-01-20 Sebastien Pouliot <sebastien@ximian.com> - - * AsnEncodedDataTest.cs: Added test case for SubjectAltName extension. - -2005-01-17 Sebastien Pouliot <sebastien@ximian.com> - - * AsnEncodedDataTest.cs: Added tests decode Fx supported Enhanced Key - Usage extension and Fx "officially" unsupported Netscape Cert Type - extension. Both are docoded sucessfully at this level. - 2005-01-13 Sebastien Pouliot <sebastien@ximian.com> - * AsnEncodedDataTest.cs: Added tests for Oid, RawData properties and - for CopyFrom method. * CryptographicAttributeTest.cs: Updated to NUnit 2.2 tests. 2004-07-09 Sebastien Pouliot <sebastien@ximian.com> - * AsnEncodedDataTest.cs: Fixed for Fx 2.0 beta1. * CryptographicAttributeTest.cs: New. Moved from S.S.C.Pkcs. - * OidTest.cs: Fixed for Fx 2.0 beta1. - -2003-11-06 Sebastien Pouliot <spouliot@videotron.ca> - - * AsnEncodedDataTest.cs: New. Unit tests for AsnEncodedData (.NET 1.2). - * OidTest.cs: New. Unit tests for Oid (.NET 1.2). - * OidCollectionTest.cs: New. Unit tests for OidCollection (.NET 1.2). - * OidEnumeratorTest.cs: New. Unit tests for OidEnumerator (.NET 1.2). - diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/OidCollectionTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography/OidCollectionTest.cs deleted file mode 100644 index da0e7066ba9..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography/OidCollectionTest.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// OidCollectionTest.cs - NUnit tests for OidCollection -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// -// (C) 2003 Motus Technologies Inc. (http://www.motus.com) -// - -#if NET_2_0 - -using NUnit.Framework; - -using System; -using System.Security.Cryptography; - -namespace MonoTests.System.Security.Cryptography { - - [TestFixture] - public class OidCollectionTest : Assertion { - - [Test] - public void Constructor () - { - OidCollection oc = new OidCollection (); - // default properties - AssertEquals ("Count", 0, oc.Count); - Assert ("IsSynchronized", !oc.IsSynchronized); - AssertNotNull ("SyncRoot", oc.SyncRoot); - AssertNotNull ("GetEnumerator", oc.GetEnumerator ()); - } - - [Test] - public void Add () - { - OidCollection oc = new OidCollection (); - oc.Add (new Oid ("1.0")); - AssertEquals ("Count", 1, oc.Count); - AssertEquals ("[0]", "1.0", oc [0].Value); - AssertEquals ("['1.0']", "1.0", oc ["1.0"].Value); - } - - [Test] - //BUG [ExpectedException (typeof (ArgumentNullException))] - public void AddNull () - { - OidCollection oc = new OidCollection (); - oc.Add (null); - AssertEquals ("Count", 1, oc.Count); - // AssertNull ("[0]", oc); throw NullReferenceException - } - - [Test] - public void CopyToOid () - { - OidCollection oc = new OidCollection (); - oc.Add (new Oid ("1.0")); - Oid[] array = new Oid [1]; - oc.CopyTo (array, 0); - AssertEquals ("CopyTo(Oid)", "1.0", array [0].Value); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void CopyToOidNull () - { - OidCollection oc = new OidCollection (); - oc.Add (new Oid ("1.0")); - Oid[] array = null; - oc.CopyTo (array, 0); - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/OidEnumeratorTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography/OidEnumeratorTest.cs deleted file mode 100644 index 72e45b20d55..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography/OidEnumeratorTest.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -// OidEnumeratorTest.cs - NUnit tests for OidEnumerator -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// -// (C) 2003 Motus Technologies Inc. (http://www.motus.com) -// - -#if NET_2_0 - -using NUnit.Framework; - -using System; -using System.Security.Cryptography; - -namespace MonoTests.System.Security.Cryptography { - - [TestFixture] - public class OidEnumeratorTest : Assertion { - - private OidEnumerator GetEnumerator () - { - OidCollection oc = new OidCollection (); - oc.Add (new Oid ("1.0")); - oc.Add (new Oid ("1.1")); - oc.Add (new Oid ("1.2")); - return oc.GetEnumerator (); - } - - [Test] - [ExpectedException (typeof (ArgumentOutOfRangeException))] - public void Current_BeforeFirstElement () - { - OidEnumerator enumerator = GetEnumerator (); - Oid oid = enumerator.Current; - } - - [Test] - public void Current () - { - OidEnumerator enumerator = GetEnumerator (); - enumerator.MoveNext (); - Oid oid = enumerator.Current; - AssertNotNull ("Current", oid); - } - - [Test] - public void Current_AfterLastElement () - { - OidEnumerator enumerator = GetEnumerator (); - while (enumerator.MoveNext ()); - Oid oid = enumerator.Current; - AssertNotNull ("Current_AfterLastElement", oid); - AssertEquals ("Current==last", "1.2", oid.Value); - } - - [Test] - public void MoveNext () - { - OidEnumerator enumerator = GetEnumerator (); - int n = 0; - while (enumerator.MoveNext ()) { - n++; - } - AssertEquals ("MoveNext", 3, n); - } - - [Test] - [ExpectedException (typeof (ArgumentOutOfRangeException))] - public void Reset () - { - OidEnumerator enumerator = GetEnumerator (); - enumerator.MoveNext (); - AssertNotNull ("Current before reset", enumerator.Current); - enumerator.Reset (); - AssertNotNull ("Current after reset", enumerator.Current); - } - } -} - -#endif
\ No newline at end of file diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography/OidTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography/OidTest.cs deleted file mode 100644 index d9d35826206..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Cryptography/OidTest.cs +++ /dev/null @@ -1,184 +0,0 @@ -// -// OidTest.cs - NUnit tests for Oid -// -// Author: -// Sebastien Pouliot <sebastien@ximian.com> -// -// (C) 2003 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. -// - -#if NET_2_0 - -using NUnit.Framework; - -using System; -using System.Security.Cryptography; - -namespace MonoTests.System.Security.Cryptography { - - [TestFixture] - public class OidTest { - - static string invalidOid = "1.0"; - static string invalidName = "friendlyName"; - static string validOid = "1.2.840.113549.1.1.1"; - static string validName = "RSA"; - - [Test] - public void ConstructorEmpty () - { - Oid o = new Oid (); - Assert.IsNull (o.FriendlyName, "FriendlyName"); - Assert.IsNull (o.Value, "Value"); - } - - [Test] - public void ConstructorValidString () - { - Oid o = new Oid (validOid); - Assert.AreEqual (validName, o.FriendlyName, "FriendlyName"); - Assert.AreEqual (validOid, o.Value, "Value"); - } - - [Test] - public void ConstructorInvalidString () - { - Oid o = new Oid (invalidOid); - Assert.IsNull (o.FriendlyName, "FriendlyName"); - Assert.AreEqual (invalidOid, o.Value, "Value"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorNullString () - { - string oid = null; // do not confuse compiler - Oid o = new Oid (oid); - } - - [Test] - public void ConstructorStringString () - { - Oid o = new Oid (validOid, invalidName); - Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName"); - Assert.AreEqual (validOid, o.Value, "Value"); - } - - [Test] - //BUG [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorStringNullString () - { - Oid o = new Oid (null, validName); - Assert.AreEqual (validName, o.FriendlyName, "FriendlyName"); - Assert.IsNull (o.Value, "Value"); - } - - [Test] - public void ConstructorStringStringNull () - { - Oid o = new Oid (validOid, null); - Assert.IsNull (o.FriendlyName, "FriendlyName"); - Assert.AreEqual (validOid, o.Value, "Value"); - } - - [Test] - public void ConstructorOid () - { - Oid o = new Oid (validOid, invalidName); - Oid o2 = new Oid (o); - Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName==invalid"); - Assert.AreEqual (o.FriendlyName, o2.FriendlyName, "FriendlyName"); - Assert.AreEqual (o.Value, o2.Value, "Value"); - } - - [Test] - [ExpectedException (typeof (ArgumentNullException))] - public void ConstructorOidNull () - { - Oid onull = null; // do not confuse compiler - Oid o = new Oid (onull); - } - - [Test] - public void FriendlyName () - { - Oid o = new Oid (invalidOid, invalidName); - Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName-1"); - Assert.AreEqual (invalidOid, o.Value, "Value-1"); - o.FriendlyName = validName; - Assert.AreEqual (validName, o.FriendlyName, "FriendlyName-2"); - Assert.AreEqual (validOid, o.Value, "Value-2"); // surprise! - } - - [Test] - public void FriendlyNameNull () - { - Oid o = new Oid (validOid, invalidName); - Assert.AreEqual (invalidName, o.FriendlyName, "FriendlyName"); - o.FriendlyName = null; - Assert.IsNull (o.FriendlyName, "FriendlyName-Null"); - } - - [Test] - public void Value () - { - Oid o = new Oid (validOid, invalidName); - Assert.AreEqual (validOid, o.Value, "Value-1"); - o.Value = invalidName; - Assert.AreEqual (invalidName, o.Value, "Value-2"); - } - - [Test] - public void ValueNull () - { - Oid o = new Oid (validOid, invalidName); - Assert.AreEqual (validOid, o.Value, "Value"); - o.Value = null; - Assert.IsNull (o.Value, "Value-Null"); - } - - [Test] - public void WellKnownOid () - { - Oid o = new Oid ("1.2.840.113549.1.1.1"); - Assert.AreEqual ("1.2.840.113549.1.1.1", o.Value, "RSA Value"); - Assert.AreEqual ("RSA", o.FriendlyName, "RSA FriendlyName"); - - o = new Oid ("1.2.840.113549.1.7.1"); - Assert.AreEqual ("1.2.840.113549.1.7.1", o.Value, "PKCS 7 Data Value"); - Assert.AreEqual ("PKCS 7 Data", o.FriendlyName, "PKCS 7 Data FriendlyName"); - - o = new Oid ("1.2.840.113549.1.9.5"); - Assert.AreEqual ("1.2.840.113549.1.9.5", o.Value, "Signing Time Value"); - Assert.AreEqual ("Signing Time", o.FriendlyName, "Signing Time FriendlyName"); - - o = new Oid ("1.2.840.113549.3.7"); - Assert.AreEqual ("1.2.840.113549.3.7", o.Value, "3des Value"); - Assert.AreEqual ("3des", o.FriendlyName, "3des FriendlyName"); - - // TODO: add other well known oid as we find them - } - } -} - -#endif diff --git a/mcs/class/System.Security/Test/System.Security.Permissions/ChangeLog b/mcs/class/System.Security/Test/System.Security.Permissions/ChangeLog index 6f0cc3317b3..814042b712b 100644 --- a/mcs/class/System.Security/Test/System.Security.Permissions/ChangeLog +++ b/mcs/class/System.Security/Test/System.Security.Permissions/ChangeLog @@ -1,3 +1,7 @@ +2005-09-26 Sebastien Pouliot <sebastien@ximian.com> + + * StorePermissionAttributeTest.cs: Moved in System.dll + 2005-09-22 Sebastien Pouliot <sebastien@ximian.com> * DataProtectionPermissionAttributeTest.cs: Removed *Choice security diff --git a/mcs/class/System.Security/Test/System.Security.Permissions/StorePermissionAttributeTest.cs b/mcs/class/System.Security/Test/System.Security.Permissions/StorePermissionAttributeTest.cs deleted file mode 100644 index f060dfc78de..00000000000 --- a/mcs/class/System.Security/Test/System.Security.Permissions/StorePermissionAttributeTest.cs +++ /dev/null @@ -1,249 +0,0 @@ -// -// StorePermissionAttributeTest.cs - -// NUnit Test Cases for StorePermissionAttributeTest -// -// 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.Security; -using System.Security.Permissions; - -namespace MonoTests.System.Security.Permissions { - - [TestFixture] - public class StorePermissionAttributeTest { - - [Test] - public void Default () - { - StorePermissionAttribute a = new StorePermissionAttribute (SecurityAction.Assert); - Assert.IsFalse (a.AddToStore, "AddToStore"); - Assert.IsFalse (a.CreateStore, "CreateStore"); - Assert.IsFalse (a.DeleteStore, "DeleteStore"); - Assert.IsFalse (a.EnumerateCertificates, "EnumerateCertificates"); - Assert.IsFalse (a.EnumerateStores, "EnumerateStores"); - Assert.IsFalse (a.OpenStore, "OpenStore"); - Assert.IsFalse (a.RemoveFromStore, "RemoveFromStore"); - - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags"); - Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId"); - - StorePermission perm = (StorePermission)a.CreatePermission (); - Assert.AreEqual (StorePermissionFlags.NoFlags, perm.Flags, "CreatePermission.Flags"); - } - - [Test] - public void Action () - { - StorePermissionAttribute a = new StorePermissionAttribute (SecurityAction.Assert); - Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert"); - a.Action = SecurityAction.Demand; - Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand"); - a.Action = SecurityAction.Deny; - Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny"); - a.Action = SecurityAction.InheritanceDemand; - Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand"); - a.Action = SecurityAction.LinkDemand; - Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand"); - a.Action = SecurityAction.PermitOnly; - Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly"); - a.Action = SecurityAction.RequestMinimum; - Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum"); - a.Action = SecurityAction.RequestOptional; - Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional"); - a.Action = SecurityAction.RequestRefuse; - Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse"); - } - - [Test] - public void Action_Invalid () - { - StorePermissionAttribute a = new StorePermissionAttribute ((SecurityAction)Int32.MinValue); - // no validation in attribute - } - - private StorePermissionAttribute Empty () - { - StorePermissionAttribute a = new StorePermissionAttribute (SecurityAction.Assert); - a.AddToStore = false; - a.CreateStore = false; - a.DeleteStore = false; - a.EnumerateCertificates = false; - a.EnumerateStores = false; - a.OpenStore = false; - a.RemoveFromStore = false; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags"); - return a; - } - - [Test] - public void AddToStore () - { - StorePermissionAttribute a = Empty (); - a.AddToStore = true; - Assert.AreEqual (StorePermissionFlags.AddToStore, a.Flags, "Flags=AddToStore"); - a.AddToStore = false; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags=NoFlags"); - } - - [Test] - public void CreateStore () - { - StorePermissionAttribute a = Empty (); - a.CreateStore = true; - Assert.AreEqual (StorePermissionFlags.CreateStore, a.Flags, "Flags=CreateStore"); - a.CreateStore = false; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags=NoFlags"); - } - - [Test] - public void DeleteStore () - { - StorePermissionAttribute a = Empty (); - a.DeleteStore = true; - Assert.AreEqual (StorePermissionFlags.DeleteStore, a.Flags, "Flags=DeleteStore"); - a.DeleteStore = false; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags=NoFlags"); - } - - [Test] - public void EnumerateCertificates () - { - StorePermissionAttribute a = Empty (); - a.EnumerateCertificates = true; - Assert.AreEqual (StorePermissionFlags.EnumerateCertificates, a.Flags, "Flags=EnumerateCertificates"); - a.EnumerateCertificates = false; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags=NoFlags"); - } - - [Test] - public void EnumerateStores () - { - StorePermissionAttribute a = Empty (); - a.EnumerateStores = true; - Assert.AreEqual (StorePermissionFlags.EnumerateStores, a.Flags, "Flags=EnumerateStores"); - a.EnumerateStores = false; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags=NoFlags"); - } - - [Test] - public void OpenStore () - { - StorePermissionAttribute a = Empty (); - a.OpenStore = true; - Assert.AreEqual (StorePermissionFlags.OpenStore, a.Flags, "Flags=OpenStore"); - a.OpenStore = false; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags=NoFlags"); - } - - [Test] - public void RemoveFromStore () - { - StorePermissionAttribute a = Empty (); - a.RemoveFromStore = true; - Assert.AreEqual (StorePermissionFlags.RemoveFromStore, a.Flags, "Flags=RemoveFromStore"); - a.RemoveFromStore = false; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Flags=NoFlags"); - } - - [Test] - public void Unrestricted () - { - StorePermissionAttribute a = Empty (); - a.Unrestricted = true; - Assert.AreEqual (StorePermissionFlags.NoFlags, a.Flags, "Unrestricted"); - - StorePermission perm = (StorePermission)a.CreatePermission (); - Assert.AreEqual (StorePermissionFlags.AllFlags, perm.Flags, "CreatePermission.Flags"); - } - - [Test] - public void Flags () - { - StorePermissionAttribute a = Empty (); - a.Flags = StorePermissionFlags.AddToStore; - Assert.IsTrue (a.AddToStore, "AddToStore"); - a.Flags |= StorePermissionFlags.CreateStore; - Assert.IsTrue (a.CreateStore, "CreateStore"); - a.Flags |= StorePermissionFlags.DeleteStore; - Assert.IsTrue (a.DeleteStore, "DeleteStore"); - a.Flags |= StorePermissionFlags.EnumerateCertificates; - Assert.IsTrue (a.EnumerateCertificates, "EnumerateCertificates"); - a.Flags |= StorePermissionFlags.EnumerateStores; - Assert.IsTrue (a.EnumerateStores, "EnumerateStores"); - a.Flags |= StorePermissionFlags.OpenStore; - Assert.IsTrue (a.OpenStore, "OpenStore"); - a.Flags |= StorePermissionFlags.RemoveFromStore; - Assert.IsTrue (a.RemoveFromStore, "RemoveFromStore"); - - Assert.IsFalse (a.Unrestricted, "Unrestricted"); - Assert.AreEqual (StorePermissionFlags.AllFlags, a.Flags, "Flags=AllFlags"); - - a.Flags &= ~StorePermissionFlags.AddToStore; - Assert.IsFalse (a.AddToStore, "AddToStore"); - a.Flags &= ~StorePermissionFlags.CreateStore; - Assert.IsFalse (a.CreateStore, "CreateStore"); - a.Flags &= ~StorePermissionFlags.DeleteStore; - Assert.IsFalse (a.DeleteStore, "DeleteStore"); - a.Flags &= ~StorePermissionFlags.EnumerateCertificates; - Assert.IsFalse (a.EnumerateCertificates, "EnumerateCertificates"); - a.Flags &= ~StorePermissionFlags.EnumerateStores; - Assert.IsFalse (a.EnumerateStores, "EnumerateStores"); - a.Flags &= ~StorePermissionFlags.OpenStore; - Assert.IsFalse (a.OpenStore, "OpenStore"); - a.Flags &= ~StorePermissionFlags.RemoveFromStore; - Assert.IsFalse (a.RemoveFromStore, "RemoveFromStore"); - } - - [Test] - [ExpectedException (typeof (ArgumentException))] - public void Flags_Invalid () - { - StorePermissionAttribute a = Empty (); - a.Flags = ((StorePermissionFlags)Int32.MinValue); - } - - [Test] - public void Attributes () - { - Type t = typeof (StorePermissionAttribute); - Assert.IsTrue (t.IsSerializable, "IsSerializable"); - - object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false); - Assert.AreEqual (1, attrs.Length, "AttributeUsage"); - AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0]; - Assert.IsTrue (aua.AllowMultiple, "AllowMultiple"); - Assert.IsFalse (aua.Inherited, "Inherited"); - AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method); - Assert.AreEqual (at, aua.ValidOn, "ValidOn"); - } - } -} - -#endif |