Imported Upstream version 3.6.0

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

View File

@@ -0,0 +1,34 @@
2005-10-20 Sebastien Pouliot <sebastien@ximian.com>
* CryptographicAttributeObjectCas.cs: New. CAS unit tests.
* CryptographicAttributeObjectEnumeratorCas.cs: New. CAS unit tests.
* CryptographicAttributeObjectEnumeratorTest.cs: New. Unit tests.
* CryptographicAttributeObjectCollectionCas.cs: New. CAS unit tests.
* CryptographicAttributeObjectCollectionTest.cs: New. Unit tests.
* ProtectedDataCas.cs: New. CAS unit tests.
* ProtectedDataTest.cs: Reworked/complete unit tests.
* ProtectedMemoryCas.cs: New. CAS unit tests.
* ProtectedMemoryTest.cs: Reworked/complete unit tests.
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
platform doesn't support ProtectedData.
* ProtectedMemoryTest.cs: Updated to NUnit 2.2 API to use Ignore it
the platform doesn't support ProtectedData.
2005-04-23 Sebastien Pouliot <sebastien@ximian.com>
* CryptographicAttributeTest.cs: Changed class names to match beta2.
2005-01-13 Sebastien Pouliot <sebastien@ximian.com>
* CryptographicAttributeTest.cs: Updated to NUnit 2.2 tests.
2004-07-09 Sebastien Pouliot <sebastien@ximian.com>
* CryptographicAttributeTest.cs: New. Moved from S.S.C.Pkcs.

View File

@@ -0,0 +1,77 @@
//
// CryptographicAttributeObjectCas.cs - CAS unit tests for
// System.Security.Cryptography.CryptographicAttributeObject
//
// 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.Reflection;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using MonoTests.System.Security.Cryptography;
namespace MonoCasTests.System.Security.Cryptography {
[TestFixture]
[Category ("CAS")]
public class CryptographicAttributeObjectCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void UnitTestReuse ()
{
CryptographicAttributeTest unit = new CryptographicAttributeTest ();
unit.ConstructorOid ();
unit.ConstructorOidCollection ();
unit.ConstructorOidAsnEncodedDataCollectionNull ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Type[] types = new Type[1] { typeof (Oid) };
ConstructorInfo ci = typeof (CryptographicAttributeObject).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(Oid)");
Assert.IsNotNull (ci.Invoke (new object[1] { new Oid () }), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,79 @@
//
// CryptographicAttributeObjectCollectionCas.cs - CAS unit tests for
// System.Security.Cryptography.CryptographicAttributeObjectCollection
//
// 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.Reflection;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using MonoTests.System.Security.Cryptography;
namespace MonoCasTests.System.Security.Cryptography {
[TestFixture]
[Category ("CAS")]
public class CryptographicAttributeObjectCollectionCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void UnitTestReuse ()
{
CryptographicAttributeObjectCollectionTest unit = new CryptographicAttributeObjectCollectionTest ();
unit.Constructor_Empty ();
unit.Constructor_CryptographicAttributeObject ();
unit.Add_MultipleSameOid ();
unit.Remove_MultipleSameOid_First ();
unit.Remove_MultipleSameOid_Last ();
unit.Remove_WithDifferentInstance ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (CryptographicAttributeObjectCollection).GetConstructor (new Type [0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,227 @@
//
// CryptographicAttributeObjectCollectionTest.cs - NUnit tests for
// System.Security.Cryptography.CryptographicAttributeObjectCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Collections;
using System.Security.Cryptography;
namespace MonoTests.System.Security.Cryptography {
[TestFixture]
public class CryptographicAttributeObjectCollectionTest {
static string defaultOid = "1.2.840.113549.1.7.1";
private void CommonStuff (CryptographicAttributeObjectCollection coll)
{
Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
Assert.AreSame (coll, coll.SyncRoot, "SyncRoot");
Assert.IsNotNull (coll.GetEnumerator (), "GetEnumerator");
int i = coll.Count;
Oid o1 = new Oid ("1.2.840.113549.1.7.3");
AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x05, 0x00 });
Assert.AreEqual (i, coll.Add (aed), "Add(AsnEncodedData)");
Assert.IsTrue ((coll[i++] is CryptographicAttributeObject), "converted");
Oid o2 = new Oid ("1.2.840.113549.1.7.2");
CryptographicAttributeObject cao = new CryptographicAttributeObject (o2);
Assert.AreEqual (i, coll.Add (cao), "Add(CryptographicAttributeObject)");
CryptographicAttributeObject[] array = new CryptographicAttributeObject [coll.Count];
coll.CopyTo (array, 0);
Array a = (Array) new object [coll.Count];
ICollection c = (ICollection) coll;
c.CopyTo (a, 0);
IEnumerable e = (IEnumerable) coll;
Assert.IsNotNull (e.GetEnumerator (), "GetEnumerator");
coll.Remove (cao);
Assert.AreEqual (i, coll.Count, "Remove(CryptographicAttributeObject)");
}
[Test]
public void Constructor_Empty ()
{
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection ();
Assert.AreEqual (0, coll.Count, "Count");
CommonStuff (coll);
}
[Test]
public void Constructor_CryptographicAttributeObject ()
{
Oid o = new Oid (defaultOid);
CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao);
Assert.AreEqual (1, coll.Count, "Count");
Assert.AreSame (cao, coll[0], "this[int]");
CommonStuff (coll);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Add_AsnEncodedData_Null ()
{
AsnEncodedData aed = null;
new CryptographicAttributeObjectCollection ().Add (aed);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Add_CryptographicAttributeObject_Null ()
{
CryptographicAttributeObject cao = null;
new CryptographicAttributeObjectCollection ().Add (cao);
}
[Test]
public void Add_MultipleSameOid ()
{
Oid o = new Oid (defaultOid);
CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao);
int i = 0;
while (i < 10) {
Assert.AreEqual (1, coll.Count, String.Format ("Count-{0}", i));
Assert.AreEqual (i * 2, coll[0].Values.Count, String.Format ("Values.Count-{0}", i++));
Oid o1 = new Oid (defaultOid);
AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte)i });
coll.Add (aed);
aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte) i });
coll.Add (aed);
Oid o2 = new Oid (defaultOid);
coll.Add (new CryptographicAttributeObject (o2));
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CopyTo_Null ()
{
new CryptographicAttributeObjectCollection ().CopyTo (null, 0);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ICollection_CopyTo_Null ()
{
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection ();
ICollection c = (coll as ICollection);
c.CopyTo (null, 0);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Remove_Null ()
{
new CryptographicAttributeObjectCollection ().Remove (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Remove_Null_WithNullItem ()
{
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (null);
Assert.AreEqual (1, coll.Count, "Count");
Assert.IsNull (coll[0], "this[int]");
coll.Remove (null);
}
[Test]
public void Remove_MultipleSameOid_First ()
{
Oid o = new Oid (defaultOid);
CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao);
Oid o1 = new Oid (defaultOid);
AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte) 0 });
coll.Add (aed);
aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte) 0 });
coll.Add (aed);
Oid o2 = new Oid (defaultOid);
coll.Add (new CryptographicAttributeObject (o2));
Assert.AreEqual (1, coll.Count, "before Remove");
coll.Remove (cao);
Assert.AreEqual (0, coll.Count, "after Remove");
}
[Test]
public void Remove_MultipleSameOid_Last ()
{
Oid o = new Oid (defaultOid);
CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao);
Oid o1 = new Oid (defaultOid);
AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte) 0 });
coll.Add (aed);
aed = new AsnEncodedData (o1, new byte[] { 0x04, (byte) 0 });
coll.Add (aed);
Oid o2 = new Oid (defaultOid);
CryptographicAttributeObject last = new CryptographicAttributeObject (o2);
coll.Add (last);
Assert.AreEqual (1, coll.Count, "before Remove");
coll.Remove (last);
Assert.AreEqual (1, coll.Count, "after Remove");
}
[Test]
public void Remove_WithDifferentInstance ()
{
Oid o = new Oid (defaultOid);
CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao);
Assert.AreEqual (1, coll.Count, "before Remove");
cao = new CryptographicAttributeObject (o);
coll.Remove (cao);
Assert.AreEqual (1, coll.Count, "after Remove");
}
}
}
#endif

View File

@@ -0,0 +1,84 @@
//
// CryptographicAttributeObjectEnumeratorCas.cs - CAS unit tests for
// System.Security.Cryptography.CryptographicAttributeObjectEnumerator
//
// 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.Reflection;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using MonoTests.System.Security.Cryptography;
namespace MonoCasTests.System.Security.Cryptography {
[TestFixture]
[Category ("CAS")]
public class CryptographicAttributeObjectEnumeratorCas {
static string defaultOid = "1.2.840.113549.1.7.1";
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void UnitTestReuse ()
{
CryptographicAttributeObjectEnumeratorTest unit = new CryptographicAttributeObjectEnumeratorTest ();
unit.Empty ();
unit.One_CryptographicAttributeObject ();
unit.One_AsnEncodedData ();
unit.Two_Both ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Oid o = new Oid (defaultOid);
CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
CryptographicAttributeObjectCollection coll = new CryptographicAttributeObjectCollection (cao);
CryptographicAttributeObjectEnumerator e = coll.GetEnumerator ();
MethodInfo mi = typeof (CryptographicAttributeObjectEnumerator).GetMethod ("MoveNext");
Assert.IsNotNull (mi, "default .ctor()");
Assert.IsTrue ((bool)mi.Invoke (e, null), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,116 @@
//
// CryptographicAttributeObjectEnumeratorTest.cs - NUnit tests for
// System.Security.Cryptography.CryptographicAttributeObjectEnumerator
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Collections;
using System.Security.Cryptography;
namespace MonoTests.System.Security.Cryptography {
[TestFixture]
public class CryptographicAttributeObjectEnumeratorTest {
static string defaultOid = "1.2.840.113549.1.7.1";
private CryptographicAttributeObjectCollection coll;
private void Count (int count)
{
Assert.AreEqual (count, coll.Count, "Count");
int i = 0;
foreach (CryptographicAttributeObject cao in coll) {
i++;
}
Assert.AreEqual (count, i, "foreach");
i = 0;
CryptographicAttributeObjectEnumerator e = coll.GetEnumerator ();
while (e.MoveNext ()) {
if (e.Current is CryptographicAttributeObject)
i++;
}
Assert.AreEqual (count, i, "GetEnumerator");
i = 0;
e.Reset ();
while (e.MoveNext ()) {
if (e.Current is CryptographicAttributeObject)
i++;
}
Assert.AreEqual (count, i, "Reset");
}
[Test]
public void Empty ()
{
coll = new CryptographicAttributeObjectCollection ();
Count (0);
}
[Test]
public void One_CryptographicAttributeObject ()
{
Oid o = new Oid (defaultOid);
CryptographicAttributeObject cao = new CryptographicAttributeObject (o);
coll = new CryptographicAttributeObjectCollection (cao);
Count (1);
}
[Test]
public void One_AsnEncodedData ()
{
Oid o = new Oid (defaultOid);
AsnEncodedData aed = new AsnEncodedData (o, new byte[] { 0x05, 0x00 });
coll = new CryptographicAttributeObjectCollection ();
coll.Add (aed);
Count (1);
}
[Test]
public void Two_Both ()
{
coll = new CryptographicAttributeObjectCollection ();
Oid o1 = new Oid (defaultOid + ".1");
AsnEncodedData aed = new AsnEncodedData (o1, new byte[] { 0x05, 0x00 });
coll.Add (aed);
Oid o2 = new Oid (defaultOid + ".2");
coll.Add (new CryptographicAttributeObject (o2));
Count (2);
}
}
}
#endif

View File

@@ -0,0 +1,97 @@
//
// CryptographicAttributeTest.cs - NUnit tests for CryptographicAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Collections;
using System.Security.Cryptography;
namespace MonoTests.System.Security.Cryptography {
[TestFixture]
public class CryptographicAttributeTest {
static string defaultOid = "1.2.840.113549.1.7.1";
static string defaultName = "PKCS 7 Data";
[Test]
public void ConstructorOid ()
{
Oid o = new Oid (defaultOid);
CryptographicAttributeObject ca = new CryptographicAttributeObject (o);
Assert.AreEqual (defaultName, ca.Oid.FriendlyName, "Oid.FriendlyName");
Assert.AreEqual (defaultOid, ca.Oid.Value, "Oid.Value");
Assert.AreEqual (0, ca.Values.Count, "Values");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorOidNull ()
{
CryptographicAttributeObject ca = new CryptographicAttributeObject (null);
}
[Test]
public void ConstructorOidCollection ()
{
Oid o = new Oid (defaultOid);
AsnEncodedDataCollection coll = new AsnEncodedDataCollection ();
CryptographicAttributeObject ca = new CryptographicAttributeObject (o, coll);
Assert.AreEqual (defaultName, ca.Oid.FriendlyName, "Oid.FriendlyName");
Assert.AreEqual (defaultOid, ca.Oid.Value, "Oid.Value");
Assert.AreEqual (0, ca.Values.Count, "Values - 0");
coll.Add (new AsnEncodedData (new byte [0]));
Assert.AreEqual (1, ca.Values.Count, "Values - 1");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorOidNullCollection ()
{
AsnEncodedDataCollection coll = new AsnEncodedDataCollection ();
CryptographicAttributeObject ca = new CryptographicAttributeObject (null, coll);
}
[Test]
public void ConstructorOidAsnEncodedDataCollectionNull ()
{
Oid o = new Oid (defaultOid);
AsnEncodedDataCollection coll = null;
CryptographicAttributeObject ca = new CryptographicAttributeObject (o, coll);
Assert.AreEqual (defaultName, ca.Oid.FriendlyName, "Oid.FriendlyName");
Assert.AreEqual (defaultOid, ca.Oid.Value, "Oid.Value");
Assert.AreEqual (0, ca.Values.Count, "Values");
}
}
}
#endif

View File

@@ -0,0 +1,174 @@
//
// ProtectedDataCas.cs
// - CAS unit tests for System.Security.Cryptography.ProtectedData
//
// 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.Reflection;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using MonoTests.System.Security.Cryptography;
namespace MonoCasTests.System.Security.Cryptography {
[TestFixture]
[Category ("CAS")]
// problem with CSC when an assembly use permissions defined within itself
[Category ("NotWorking")]
public class ProtectedDataCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
private bool IsEmpty (byte[] array)
{
int total = 0;
for (int i = 0; i < array.Length; i++)
total += array[i];
return (total == 0);
}
[Test]
[DataProtectionPermission (SecurityAction.PermitOnly, ProtectData = true, UnprotectData = true)]
public void UnitTestReuse ()
{
ProtectedDataTest unit = new ProtectedDataTest ();
unit.ProtectCurrentUser ();
unit.ProtectLocalMachine ();
unit.DataProtectionScope_All ();
unit.ProtectNullEntropy ();
}
[Test]
[DataProtectionPermission (SecurityAction.PermitOnly, ProtectData = true)]
// note: this implies that UnmanagedCode isn't allowed
public void Protect_PermitOnly_Protect ()
{
byte[] data = new byte[8];
byte[] entropy = new byte[1];
try {
byte[] encdata = ProtectedData.Protect (data, null, DataProtectionScope.CurrentUser);
Assert.IsFalse (IsEmpty (encdata), "null-CurrentUser");
encdata = ProtectedData.Protect (data, entropy, DataProtectionScope.CurrentUser);
Assert.IsFalse (IsEmpty (encdata), "entropy-CurrentUser");
encdata = ProtectedData.Protect (data, null, DataProtectionScope.LocalMachine);
Assert.IsFalse (IsEmpty (encdata), "null-LocalMachine");
encdata = ProtectedData.Protect (data, entropy, DataProtectionScope.LocalMachine);
Assert.IsFalse (IsEmpty (encdata), "entropy-LocalMachine");
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[DataProtectionPermission (SecurityAction.Deny, ProtectData = true)]
[ExpectedException (typeof (SecurityException))]
public void Protect_Deny_Protect ()
{
try {
ProtectedData.Protect (new byte[8], null, DataProtectionScope.CurrentUser);
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[DataProtectionPermission (SecurityAction.PermitOnly, UnprotectData = true)]
// note: this implies that UnmanagedCode isn't allowed
[ExpectedException (typeof (CryptographicException))]
public void Unprotect_PermitOnly_Unprotect ()
{
try {
ProtectedData.Unprotect (new byte[8], null, DataProtectionScope.CurrentUser);
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[DataProtectionPermission (SecurityAction.Deny, UnprotectData = true)]
[ExpectedException (typeof (SecurityException))]
public void Unprotect_Deny_Unprotect ()
{
try {
ProtectedData.Unprotect (new byte[8], null, DataProtectionScope.CurrentUser);
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[DataProtectionPermission (SecurityAction.PermitOnly, ProtectData = true, UnprotectData = true)]
public void LinkDemand_PermitOnly_DataProtection ()
{
Type pd = typeof (ProtectedData);
object[] parameters = new object[3] { new byte[8], null, DataProtectionScope.CurrentUser };
try {
MethodInfo mi = pd.GetMethod ("Protect");
Assert.IsNotNull (mi, "Protect");
byte[] encdata = (byte[]) mi.Invoke (null, parameters);
Assert.IsNotNull (encdata, "Invoke Protect");
Assert.IsFalse (IsEmpty (encdata), "Encrypted");
mi = pd.GetMethod ("Unprotect");
Assert.IsNotNull (mi, "Unprotect");
parameters[0] = encdata;
byte[] decdata = (byte[]) mi.Invoke (null, parameters);
Assert.IsNotNull (decdata, "Invoke Unprotect");
Assert.IsTrue (IsEmpty (decdata), "Decrypted");
// so no LinkDemand are required (Demand are enough) and
// no check for UnmanagedCode are required
}
catch (TargetInvocationException tie) {
if (tie.InnerException is PlatformNotSupportedException)
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
}
}
#endif

View File

@@ -0,0 +1,160 @@
//
// ProtectedDataTest.cs - NUnit Test Cases for ProtectedData
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security.Cryptography;
namespace MonoTests.System.Security.Cryptography {
[TestFixture]
public class ProtectedDataTest {
private byte[] notMuchEntropy = new byte[16];
private bool IsEmpty (byte[] array)
{
int total = 0;
for (int i = 0; i < array.Length; i++)
total += array[i];
return (total == 0);
}
private void ProtectUnprotect (byte[] entropy, DataProtectionScope scope)
{
try {
byte[] data = new byte [16];
byte[] encdata = ProtectedData.Protect (data, entropy, scope);
Assert.IsFalse (IsEmpty (encdata), "Protect");
byte[] decdata = ProtectedData.Unprotect (encdata, entropy, scope);
Assert.IsTrue (IsEmpty (decdata), "Unprotect");
}
catch (CryptographicException ce) {
if (ce.InnerException is UnauthorizedAccessException)
Assert.Ignore ("The machine key store hasn't yet been created (as root).");
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
public void ProtectCurrentUser ()
{
// we're testing the DataProtectionScope definition but
// not if it's really limited to the scope specified
ProtectUnprotect (notMuchEntropy, DataProtectionScope.CurrentUser);
}
[Test]
public void ProtectLocalMachine ()
{
// we're testing the DataProtectionScope definition but
// not if it's really limited to the scope specified
ProtectUnprotect (notMuchEntropy, DataProtectionScope.LocalMachine);
}
[Test]
public void DataProtectionScope_All ()
{
byte[] data = new byte[16];
try {
foreach (DataProtectionScope dps in Enum.GetValues (typeof (DataProtectionScope))) {
byte[] encdata = ProtectedData.Protect (data, notMuchEntropy, dps);
Assert.IsFalse (IsEmpty (encdata), "Protect");
Assert.IsTrue (IsEmpty (data), "Protect(original unmodified)");
byte[] decdata = ProtectedData.Unprotect (encdata, notMuchEntropy, dps);
Assert.IsTrue (IsEmpty (decdata), "Unprotect");
}
}
catch (CryptographicException ce) {
if (ce.InnerException is UnauthorizedAccessException)
Assert.Ignore ("The machine key store hasn't yet been created (as root).");
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
[Category ("NotDotNet")]
public void Protect_InvalidDataProtectionScope ()
{
try {
byte[] data = new byte[16];
ProtectedData.Protect (data, notMuchEntropy, (DataProtectionScope) Int32.MinValue);
// MS doesn't throw an ArgumentException but returning from
// this method will throw an UnhandledException in NUnit
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ProtectNull ()
{
ProtectedData.Protect (null, notMuchEntropy, DataProtectionScope.CurrentUser);
}
[Test]
public void ProtectNullEntropy ()
{
// we're testing the DataProtectionScope definition but
// not if it's really limited to the scope specified
ProtectUnprotect (null, DataProtectionScope.CurrentUser);
}
[Test]
[ExpectedException (typeof (CryptographicException))]
public void UnprotectNotProtectedData ()
{
try {
byte[] baddata = new byte [16];
ProtectedData.Unprotect (baddata, notMuchEntropy, DataProtectionScope.CurrentUser);
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
[Category ("NotDotNet")]
public void Unprotect_InvalidDataProtectionScope ()
{
try {
byte[] data = new byte[16];
byte[] encdata = ProtectedData.Protect (data, notMuchEntropy, DataProtectionScope.CurrentUser);
ProtectedData.Unprotect (encdata, notMuchEntropy, (DataProtectionScope) Int32.MinValue);
// MS doesn't throw an ArgumentException but returning from
// this method will throw an UnhandledException in NUnit
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void UnprotectNull ()
{
ProtectedData.Unprotect (null, notMuchEntropy, DataProtectionScope.CurrentUser);
}
}
}
#endif

View File

@@ -0,0 +1,170 @@
//
// ProtectedMemoryCas.cs
// - CAS unit tests for System.Security.Cryptography.ProtectedMemory
//
// 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.Reflection;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using MonoTests.System.Security.Cryptography;
namespace MonoCasTests.System.Security.Cryptography {
[TestFixture]
[Category ("CAS")]
// problem with CSC when an assembly use permissions defined within itself
[Category ("NotWorking")]
public class ProtectedMemoryCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
private bool IsEmpty (byte[] array)
{
int total = 0;
for (int i = 0; i < array.Length; i++)
total += array[i];
return (total == 0);
}
[Test]
[DataProtectionPermission (SecurityAction.PermitOnly, ProtectMemory = true, UnprotectMemory = true)]
public void UnitTestReuse ()
{
ProtectedMemoryTest unit = new ProtectedMemoryTest ();
unit.ProtectSameProcess ();
unit.ProtectSameLogon ();
unit.ProtectCrossProcess ();
unit.MemoryProtectionScope_All ();
}
[Test]
[DataProtectionPermission (SecurityAction.PermitOnly, ProtectMemory = true)]
// note: this implies that UnmanagedCode isn't allowed
public void Protect_PermitOnly_Protect ()
{
try {
byte[] data = new byte[16];
ProtectedMemory.Protect (data, MemoryProtectionScope.SameProcess);
Assert.IsFalse (IsEmpty (data), "SameProcess");
data = new byte[16];
ProtectedMemory.Protect (data, MemoryProtectionScope.SameLogon);
Assert.IsFalse (IsEmpty (data), "SameLogon");
data = new byte[16];
ProtectedMemory.Protect (data, MemoryProtectionScope.CrossProcess);
Assert.IsFalse (IsEmpty (data), "CrossProcess");
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 SP3 and later");
}
}
[Test]
[DataProtectionPermission (SecurityAction.Deny, ProtectMemory = true)]
[ExpectedException (typeof (SecurityException))]
public void Protect_Deny_Protect ()
{
try {
ProtectedMemory.Protect (new byte[16], MemoryProtectionScope.SameProcess);
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 SP3 and later");
}
}
[Test]
[DataProtectionPermission (SecurityAction.PermitOnly, UnprotectMemory = true)]
// note: this implies that UnmanagedCode isn't allowed
public void Unprotect_PermitOnly_Unprotect ()
{
try {
byte[] data = new byte[16];
ProtectedMemory.Unprotect (data, MemoryProtectionScope.SameProcess);
Assert.IsFalse (IsEmpty (data), "Unprotect unprotected");
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 SP3 and later");
}
}
[Test]
[DataProtectionPermission (SecurityAction.Deny, UnprotectMemory = true)]
[ExpectedException (typeof (SecurityException))]
public void Unprotect_Deny_Unprotect ()
{
try {
ProtectedMemory.Unprotect (new byte[16], MemoryProtectionScope.SameProcess);
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 SP3 and later");
}
}
[Test]
[DataProtectionPermission (SecurityAction.PermitOnly, ProtectMemory = true, UnprotectMemory = true)]
public void LinkDemand_PermitOnly_DataProtection ()
{
Type pm = typeof (ProtectedMemory);
byte[] data = new byte[16];
object[] parameters = new object[2] { data, MemoryProtectionScope.SameProcess };
try {
MethodInfo mi = pm.GetMethod ("Protect");
Assert.IsNotNull (mi, "Protect");
mi.Invoke (null, parameters);
Assert.IsFalse (IsEmpty (data), "Encrypted");
mi = pm.GetMethod ("Unprotect");
Assert.IsNotNull (mi, "Unprotect");
mi.Invoke (null, parameters);
Assert.IsTrue (IsEmpty (data), "Decrypted");
// so no LinkDemand are required (Demand are enough) and
// no check for UnmanagedCode are required
}
catch (TargetInvocationException tie) {
if (tie.InnerException is PlatformNotSupportedException)
Assert.Ignore ("Only supported under Windows 2000 SP 3 and later");
}
}
}
}
#endif

View File

@@ -0,0 +1,145 @@
//
// ProtectedMemoryTest.cs - NUnit Test Cases for ProtectedMemory
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security.Cryptography;
namespace MonoTests.System.Security.Cryptography {
[TestFixture]
public class ProtectedMemoryTest {
private bool IsEmpty (byte[] array)
{
int total = 0;
for (int i = 0; i < array.Length; i++)
total += array [i];
return (total == 0);
}
private void ProtectUnprotect (MemoryProtectionScope scope)
{
try {
byte[] data = new byte [16];
ProtectedMemory.Protect (data, scope);
Assert.IsFalse (IsEmpty (data), "Protect");
ProtectedMemory.Unprotect (data, scope);
Assert.IsTrue (IsEmpty (data), "Unprotect");
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 SP3 and later");
}
}
[Test]
public void ProtectSameProcess ()
{
// we're testing the MemoryProtectionScope definition but
// not if it's really limited to the scope specified
ProtectUnprotect (MemoryProtectionScope.SameProcess);
}
[Test]
public void ProtectSameLogon ()
{
// we're testing the MemoryProtectionScope definition but
// not if it's really limited to the scope specified
ProtectUnprotect (MemoryProtectionScope.SameLogon);
}
[Test]
public void ProtectCrossProcess ()
{
// we're testing the MemoryProtectionScope definition but
// not if it's really limited to the scope specified
ProtectUnprotect (MemoryProtectionScope.CrossProcess);
}
[Test]
public void MemoryProtectionScope_All ()
{
byte[] data = new byte[16];
try {
foreach (MemoryProtectionScope mps in Enum.GetValues (typeof (MemoryProtectionScope))) {
ProtectedMemory.Protect (data, mps);
Assert.IsFalse (IsEmpty (data), "Protect");
ProtectedMemory.Unprotect (data, mps);
Assert.IsTrue (IsEmpty (data), "Unprotect");
}
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 SP3 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Protect_InvalidMemoryProtectionScope ()
{
byte[] data = new byte[16];
ProtectedMemory.Protect (data, (MemoryProtectionScope) Int32.MinValue);
}
[Test]
[ExpectedException (typeof (CryptographicException))]
public void ProtectBadDataLength ()
{
byte[] data = new byte [15];
try {
ProtectedMemory.Protect (data, MemoryProtectionScope.SameProcess);
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 SP3 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ProtectNull ()
{
ProtectedMemory.Protect (null, MemoryProtectionScope.SameProcess);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Unprotect_InvalidMemoryProtectionScope ()
{
byte[] data = new byte[16];
ProtectedMemory.Unprotect (data, (MemoryProtectionScope) Int32.MinValue);
}
[Test]
[ExpectedException (typeof (CryptographicException))]
public void UnprotectBadDataLength ()
{
byte[] data = new byte [15];
try {
ProtectedMemory.Unprotect (data, MemoryProtectionScope.SameProcess);
}
catch (PlatformNotSupportedException) {
Assert.Ignore ("Only supported under Windows 2000 SP3 and later");
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void UnprotectNull ()
{
ProtectedMemory.Unprotect (null, MemoryProtectionScope.SameProcess);
}
}
}
#endif