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,32 @@
2005-11-22 Sebastien Pouliot <sebastien@ximian.com>
* ResourcePermissionBaseCas.cs: New. CAS tests.
* ResourcePermissionBaseEntryCas.cs: New. CAS tests.
* StorePermissionAttributeCas.cs: New (2.0). CAS tests.
* StorePermissionCas.cs: New (2.0). CAS tests.
* StorePermissionTest.cs: New (2.0). Unit tests.
2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
* StorePermissionAttributeTest.cs: Moved from System.Security.dll
2005-09-22 Sebastien Pouliot <sebastien@ximian.com>
* StorePermissionAttributeTest.cs: Removed *Choice security actions.
2005-05-31 Sebastien Pouliot <sebastien@ximian.com>
* ResourcePermissionBaseTest.cs: Fx 2.0 now has better arguments
checking (i.e. FDBK15131 was fixed).
2005-05-18 Sebastien Pouliot <sebastien@ximian.com>
* StorePermissionAttributeTest.cs: New. Unit tests for
StorePermissionAttribute.
2004-09-10 Sebastien Pouliot <sebastien@ximian.com>
* ResourcePermissionBaseEntryTest.cs: New. Unit tests for
ResourcePermissionBaseEntry.
* ResourcePermissionBaseTest.cs: New. Unit tests for
ResourcePermissionBase.

View File

@@ -0,0 +1,88 @@
//
// ResourcePermissionBaseCas.cs -
// CAS unit tests for System.Security.Permissions.ResourcePermissionBase
//
// 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.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Security.Permissions;
namespace MonoCasTests.System.Security.Permissions {
[TestFixture]
[Category ("CAS")]
public class ResourcePermissionBaseCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
ResourcePermissionBaseTest unit = new ResourcePermissionBaseTest ();
unit.Constants ();
unit.Constructor_Empty ();
unit.Constructor_None ();
unit.Constructor_Unrestricted ();
unit.PermissionAccessType ();
unit.TagNames ();
unit.AddPermissionAccess ();
unit.AddPermissionAccess_SemiDuplicates ();
unit.Clear ();
unit.Copy ();
unit.FromXml_WrongClass ();
unit.FromXml_NoClass ();
unit.FromXml_NoVersion ();
unit.GetPermissionEntries ();
unit.IsSubsetOf_DifferentPermissions ();
unit.RemovePermissionAccess ();
unit.ToXml ();
unit.ToXml_Unrestricted ();
unit.Union ();
unit.Unrestricted_AddRemove ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (NonAbstractResourcePermissionBase).GetConstructor (new Type [0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,71 @@
//
// ResourcePermissionBaseEntryCas.cs - CAS unit tests for
// System.Security.Permissions.ResourcePermissionBaseEntry
//
// 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.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.Security.Permissions;
namespace MonoCasTests.System.Security.Permissions {
[TestFixture]
[Category ("CAS")]
public class ResourcePermissionBaseEntryCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
ResourcePermissionBaseEntryTest unit = new ResourcePermissionBaseEntryTest ();
unit.Constructor_Default ();
unit.Constructor_Negative ();
unit.Constructor_IntString ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (ResourcePermissionBaseEntry).GetConstructor (new Type [0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,70 @@
//
// ResourcePermissionBaseEntryTest.cs -
// NUnit Test Cases for ResourcePermissionBaseEntry
//
// Author:
// Sebastien Pouliot <sebastien@ximian.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.
//
using NUnit.Framework;
using System;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class ResourcePermissionBaseEntryTest {
[Test]
public void Constructor_Default ()
{
ResourcePermissionBaseEntry rpbe = new ResourcePermissionBaseEntry ();
Assert.AreEqual (0, rpbe.PermissionAccess, "PermissionAccess");
Assert.AreEqual (0, rpbe.PermissionAccessPath.Length, "PermissionAccessPath");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor_Null ()
{
ResourcePermissionBaseEntry rpbe = new ResourcePermissionBaseEntry (0, null);
}
[Test]
public void Constructor_Negative ()
{
ResourcePermissionBaseEntry rpbe = new ResourcePermissionBaseEntry (Int32.MinValue, new string [1]);
Assert.AreEqual (Int32.MinValue, rpbe.PermissionAccess, "PermissionAccess");
Assert.AreEqual (1, rpbe.PermissionAccessPath.Length, "PermissionAccessPath");
}
[Test]
public void Constructor_IntString ()
{
ResourcePermissionBaseEntry rpbe = new ResourcePermissionBaseEntry (Int32.MaxValue, new string [10]);
Assert.AreEqual (Int32.MaxValue, rpbe.PermissionAccess, "PermissionAccess");
Assert.AreEqual (10, rpbe.PermissionAccessPath.Length, "PermissionAccessPath");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,86 @@
//
// StorePermissionAttributeCas.cs - CAS unit tests for
// System.Security.Permissions.StorePermissionAttribute
//
// 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.Permissions;
using MonoTests.System.Security.Permissions;
namespace MonoCasTests.System.Security.Permissions {
[TestFixture]
[Category ("CAS")]
public class StorePermissionAttributeCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests_Deny_Unrestricted ()
{
StorePermissionAttributeTest unit = new StorePermissionAttributeTest ();
unit.Default ();
unit.Action ();
unit.Action_Invalid ();
unit.AddToStore ();
unit.CreateStore ();
unit.DeleteStore ();
unit.EnumerateCertificates ();
unit.EnumerateStores ();
unit.OpenStore ();
unit.RemoveFromStore ();
unit.Unrestricted ();
unit.Flags ();
unit.Attributes ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Type[] types = new Type[1] { typeof (SecurityAction) };
ConstructorInfo ci = typeof (StorePermissionAttribute).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(SecurityAction)");
Assert.IsNotNull (ci.Invoke (new object[1] { SecurityAction.Demand }), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,249 @@
//
// 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

View File

@@ -0,0 +1,99 @@
//
// StorePermissionCas.cs -
// CAS unit tests for System.Security.Permissions.StorePermission
//
// 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.Permissions;
using MonoTests.System.Security.Permissions;
namespace MonoCasTests.System.Security.Permissions {
[TestFixture]
[Category ("CAS")]
public class StorePermissionCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ConstructorLevel_Deny_Unrestricted ()
{
StorePermission p = new StorePermission (StorePermissionFlags.AllFlags);
Assert.AreEqual (StorePermissionFlags.AllFlags, p.Flags, "Flags");
Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
Assert.IsNotNull (p.Copy (), "Copy");
SecurityElement se = p.ToXml ();
Assert.IsNotNull (se, "ToXml");
p.FromXml (se);
Assert.IsNotNull (p.Intersect (p), "Intersect");
Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
Assert.IsNotNull (p.Union (p), "Union");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ConstructorState_Deny_Unrestricted ()
{
StorePermission p = new StorePermission (PermissionState.None);
Assert.AreEqual (StorePermissionFlags.NoFlags, p.Flags, "Flags");
Assert.IsFalse (p.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = p.ToXml ();
Assert.IsNotNull (se, "ToXml");
p.FromXml (se);
Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
// strange behaviour of Copy under MS fx 2.0 (returns null for NoFlags)
p.Copy ();
p.Intersect (p);
p.Union (p);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Type[] types = new Type[1] { typeof (PermissionState) };
ConstructorInfo ci = typeof (StorePermission).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(PermissionState)");
Assert.IsNotNull (ci.Invoke (new object[1] { PermissionState.None }), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,479 @@
//
// StorePermissionTest.cs - NUnit Test Cases for StorePermissionTest
//
// 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 StorePermissionTest {
[Test]
public void PermissionState_None ()
{
PermissionState ps = PermissionState.None;
StorePermission sp = new StorePermission (ps);
Assert.AreEqual (StorePermissionFlags.NoFlags, sp.Flags, "Flags");
Assert.IsFalse (sp.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = sp.ToXml ();
// only class and version are present
Assert.AreEqual ("NoFlags", se.Attribute ("Flags"), "Xml-Flags");
Assert.IsNull (se.Children, "Xml-Children");
StorePermission copy = (StorePermission) sp.Copy ();
Assert.IsNull (copy, "Copy");
}
[Test]
[Ignore ("2.0 final bug reported as FDBK40928")]
public void PermissionState_None_Copy ()
{
// both will return null under 2.0 final
// StorePermission sp1 = new StorePermission (PermissionState.None).Copy();
// StorePermission sp2 = new StorePermission (StorePermissionFlags.NoFlags).Copy ();
StorePermission sp = new StorePermission (PermissionState.None);
StorePermission copy = (StorePermission) sp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
Assert.AreEqual (sp.Flags, copy.Flags, "Copy Flags");
Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
}
[Test]
public void PermissionState_Unrestricted ()
{
PermissionState ps = PermissionState.Unrestricted;
StorePermission sp = new StorePermission (ps);
Assert.AreEqual (StorePermissionFlags.AllFlags, sp.Flags, "Flags");
Assert.IsTrue (sp.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = sp.ToXml ();
Assert.IsNotNull (se.Attribute ("Unrestricted"), "Xml-Unrestricted");
Assert.IsNull (se.Attribute ("Level"), "Xml-Flags");
Assert.IsNull (se.Children, "Xml-Children");
StorePermission copy = (StorePermission) sp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
Assert.AreEqual (sp.Flags, copy.Flags, "Copy Flags");
Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void PermissionState_Bad ()
{
PermissionState ps = (PermissionState) Int32.MinValue;
StorePermission sp = new StorePermission (ps);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void StorePermissionFlags_Bad ()
{
StorePermissionFlags spf = (StorePermissionFlags) Int32.MinValue;
StorePermission sp = new StorePermission (spf);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void StorePermissionFlags_BadEight ()
{
StorePermissionFlags spf = (StorePermissionFlags) 8; // unassigned
StorePermission sp = new StorePermission (spf);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Flags_StorePermissionFlags_Bad ()
{
StorePermission sp = new StorePermission (PermissionState.None);
sp.Flags = (StorePermissionFlags) Int32.MinValue;
}
[Test]
public void Copy ()
{
StorePermission sp = new StorePermission (PermissionState.None);
// i==0 would return null for MS
for (int i=1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp.Flags = (StorePermissionFlags) i;
StorePermission copy = (StorePermission) sp.Copy ();
Assert.AreEqual (i, (int) copy.Flags, sp.Flags.ToString ());
}
}
[Test]
public void Intersect_Null ()
{
StorePermission sp = new StorePermission (PermissionState.None);
// No intersection with null
for (int i = 0; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp.Flags = (StorePermissionFlags) i;
Assert.IsNull (sp.Intersect (null), sp.Flags.ToString ());
}
}
[Test]
public void Intersect_None ()
{
StorePermission sp1 = new StorePermission (PermissionState.None);
StorePermission sp2 = new StorePermission (PermissionState.None);
for (int i = 0; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp1.Flags = (StorePermissionFlags) i;
// 1. Intersect None with ppl
StorePermission result = (StorePermission) sp1.Intersect (sp2);
Assert.IsNull (result, "None N " + sp1.Flags.ToString ());
// 2. Intersect ppl with None
result = (StorePermission) sp2.Intersect (sp1);
Assert.IsNull (result, sp1.Flags.ToString () + "N None");
}
}
[Test]
public void Intersect_Self ()
{
StorePermission sp = new StorePermission (PermissionState.None);
sp.Flags = StorePermissionFlags.NoFlags; // 0
StorePermission result = (StorePermission) sp.Intersect (sp);
Assert.IsNull (result, "NoFlags");
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp.Flags = (StorePermissionFlags) i;
result = (StorePermission) sp.Intersect (sp);
Assert.AreEqual (sp.Flags, result.Flags, sp.Flags.ToString ());
}
}
[Test]
public void Intersect_Unrestricted ()
{
// Intersection with unrestricted == Copy
// a. source (this) is unrestricted
StorePermission sp1 = new StorePermission (PermissionState.Unrestricted);
StorePermission sp2 = new StorePermission (PermissionState.None);
StorePermission result = (StorePermission) sp1.Intersect (sp2);
Assert.IsNull (result, "target NoFlags");
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
result = (StorePermission) sp1.Intersect (sp2);
Assert.AreEqual (sp2.Flags, result.Flags, "target " + sp2.Flags.ToString ());
}
// b. destination (target) is unrestricted
sp2.Flags = StorePermissionFlags.NoFlags;
result = (StorePermission) sp2.Intersect (sp1);
Assert.IsNull (result, "target NoFlags");
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
result = (StorePermission) sp2.Intersect (sp1);
Assert.AreEqual (sp2.Flags, result.Flags, "source " + sp2.Flags.ToString ());
}
}
[Test]
public void IsSubset_Null ()
{
StorePermission sp = new StorePermission (PermissionState.None);
Assert.IsTrue (sp.IsSubsetOf (null), "NoFlags"); // 0
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp.Flags = (StorePermissionFlags) i;
Assert.IsFalse (sp.IsSubsetOf (null), sp.Flags.ToString ());
}
}
[Test]
public void IsSubset_None ()
{
// IsSubset with none
// a. source (this) is none -> target is never a subset
StorePermission sp1 = new StorePermission (PermissionState.None);
StorePermission sp2 = new StorePermission (PermissionState.None);
for (int i = 0; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
Assert.IsTrue (sp1.IsSubsetOf (sp2), "target " + sp2.Flags.ToString ());
}
// b. destination (target) is none -> target is always a subset
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
Assert.IsFalse (sp2.IsSubsetOf (sp1), "source " + sp2.Flags.ToString ());
}
// exception of NoFlags
sp2.Flags = StorePermissionFlags.NoFlags;
Assert.IsTrue (sp2.IsSubsetOf (sp1), "source NoFlags");
}
[Test]
public void IsSubset_Self ()
{
StorePermission sp = new StorePermission (PermissionState.None);
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp.Flags = (StorePermissionFlags) i;
Assert.IsTrue (sp.IsSubsetOf (sp), sp.Flags.ToString ());
}
}
[Test]
public void IsSubset_Unrestricted ()
{
// IsSubset with unrestricted
// a. source (this) is unrestricted -> target is never a subset
StorePermission sp1 = new StorePermission (PermissionState.Unrestricted);
StorePermission sp2 = new StorePermission (PermissionState.None);
for (int i = 0; i < (int) StorePermissionFlags.AllFlags - 1; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
Assert.IsFalse (sp1.IsSubsetOf (sp2), "target " + sp2.Flags.ToString ());
}
// exception of AllLevel
sp2.Flags = StorePermissionFlags.AllFlags;
Assert.IsTrue (sp1.IsSubsetOf (sp2), "target AllLevel");
// b. destination (target) is unrestricted -> target is always a subset
for (int i = 0; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
Assert.IsTrue (sp2.IsSubsetOf (sp1), "source " + sp2.Flags.ToString ());
}
}
[Test]
public void Union_Null ()
{
StorePermission sp = new StorePermission (PermissionState.None);
// Union with null is a simple copy
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp.Flags = (StorePermissionFlags) i;
StorePermission union = (StorePermission) sp.Union (null);
Assert.AreEqual (sp.Flags, union.Flags, sp.Flags.ToString ());
}
// except fot NoFlags (which returns null)
sp.Flags = StorePermissionFlags.NoFlags;
Assert.IsNull (sp.Union (null), "NoFlags");
}
[Test]
public void Union_None ()
{
// Union with none is same
StorePermission sp1 = new StorePermission (PermissionState.None);
StorePermission sp2 = new StorePermission (PermissionState.None);
StorePermission union = (StorePermission) sp1.Union (sp1);
Assert.IsNull (union, "NoFlags");
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
union = (StorePermission) sp1.Union (sp2);
Assert.IsFalse (union.IsUnrestricted (), "target.Unrestricted " + sp2.Flags.ToString ());
Assert.AreEqual (sp2.Flags, union.Flags, "target.Level " + sp2.Flags.ToString ());
union = (StorePermission) sp2.Union (sp1);
Assert.IsFalse (union.IsUnrestricted (), "source.Unrestricted " + sp2.Flags.ToString ());
Assert.AreEqual (sp2.Flags, union.Flags, "source.Level " + sp2.Flags.ToString ());
}
sp2.Flags = StorePermissionFlags.AllFlags;
union = (StorePermission) sp1.Union (sp2);
Assert.IsTrue (union.IsUnrestricted (), "target.Unrestricted Unrestricted");
Assert.AreEqual (StorePermissionFlags.AllFlags, union.Flags, "target.Level Unrestricted");
union = (StorePermission) sp2.Union (sp1);
Assert.IsTrue (union.IsUnrestricted (), "source.Unrestricted Unrestricted");
Assert.AreEqual (StorePermissionFlags.AllFlags, union.Flags, "source.Level Unrestricted");
}
[Test]
public void Union_Self ()
{
StorePermission sp = new StorePermission (PermissionState.None);
StorePermission union = (StorePermission) sp.Union (sp);
Assert.IsNull (union, "NoFlags");
for (int i = 1; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp.Flags = (StorePermissionFlags) i;
union = (StorePermission) sp.Union (sp);
Assert.AreEqual (sp.Flags, union.Flags, sp.Flags.ToString ());
}
}
[Test]
public void Union_Unrestricted ()
{
// Union with unrestricted is unrestricted
StorePermission sp1 = new StorePermission (PermissionState.Unrestricted);
StorePermission sp2 = new StorePermission (PermissionState.None);
// a. source (this) is unrestricted
for (int i = 0; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
StorePermission union = (StorePermission) sp1.Union (sp2);
Assert.IsTrue (union.IsUnrestricted (), "target " + sp2.Flags.ToString ());
}
// b. destination (target) is unrestricted
for (int i = 0; i < (int) StorePermissionFlags.AllFlags; i++) {
// 8 isn't a valid value (so we exclude it from the rest of the loop)
if ((i & 8) == 8)
continue;
sp2.Flags = (StorePermissionFlags) i;
StorePermission union = (StorePermission) sp2.Union (sp1);
Assert.IsTrue (union.IsUnrestricted (), "source " + sp2.Flags.ToString ());
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
StorePermission sp = new StorePermission (PermissionState.None);
sp.FromXml (null);
}
[Test]
public void FromXml_WrongTag ()
{
StorePermission sp = new StorePermission (PermissionState.None);
SecurityElement se = sp.ToXml ();
se.Tag = "IMono";
sp.FromXml (se);
// note: normally IPermission classes (in corlib) DO care about the
// IPermission tag
}
[Test]
public void FromXml_WrongTagCase ()
{
StorePermission sp = new StorePermission (PermissionState.None);
SecurityElement se = sp.ToXml ();
se.Tag = "IPERMISSION"; // instead of IPermission
sp.FromXml (se);
// note: normally IPermission classes (in corlib) DO care about the
// IPermission tag
}
[Test]
public void FromXml_WrongClass ()
{
StorePermission sp = new StorePermission (PermissionState.None);
SecurityElement se = sp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
w.AddAttribute ("version", se.Attribute ("version"));
sp.FromXml (w);
// doesn't care of the class name at that stage
// anyway the class has already be created so...
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_NoClass ()
{
StorePermission sp = new StorePermission (PermissionState.None);
SecurityElement se = sp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
sp.FromXml (w);
// note: normally IPermission classes (in corlib) DO NOT care about
// attribute "class" name presence in the XML
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongVersion ()
{
StorePermission sp = new StorePermission (PermissionState.None);
SecurityElement se = sp.ToXml ();
se.Attributes.Remove ("version");
se.Attributes.Add ("version", "2");
sp.FromXml (se);
}
[Test]
public void FromXml_NoVersion ()
{
StorePermission sp = new StorePermission (PermissionState.None);
SecurityElement se = sp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
sp.FromXml (w);
// version is optional (in this case)
}
}
}
#endif