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,256 @@
2009-06-20 Zoltan Varga <vargaz@gmail.com>
* *.cs: Convert all tests to new-style nunit classes/methods.
2009-05-01 Sebastien Pouliot <sebastien@ximian.com>
* SecurityStateTest.cs: New. Unit tests for IsStateAvailable
2008-01-02 Sebastien Pouliot <sebastien@ximian.com>
* SecureStringTest.cs: Add test case for InsertAt (#350820)
2008-01-02 Sebastien Pouliot <sebastien@ximian.com>
* SecureStringTest.cs: Add test cases for Copy (#350840)
2007-11-07 Gert Driesen <drieseng@users.sourceforge.net>
* SecurityElementTest.cs: Allow TestToString to pass on 1.0 profile.
2007-11-07 Atsushi Enomoto <atsushi@ximian.com>
* SecurityElementTest.cs : enabled test for #333699 and added
couple more.
2007-10-14 Gert Driesen <drieseng@users.sourceforge.net>
* SecurityElementTest.cs: Added tests for using single quotes as
delimiter of which one passes on Mono and one on MS (due to bug).
2007-10-14 Gert Driesen <drieseng@users.sourceforge.net>
* SecurityElementTest.cs: Modified test for bug #333699 to use double
quote as delimiter to work around MS bug. Added test for bug #333725.
2007-10-14 Gert Driesen <drieseng@users.sourceforge.net>
* SecurityElementTest.cs: No longer derive from Assertion. Added and
improved ctor tests. Improved AddAttribute and AddChild tests.
Added comment to mono's Attributes test and added test that passes
on MS (to track fix for MS bug). Improved IsValid* tests. Added tests
for Tag and Text. Improved FromString test to verify behavior wrt
namespace prefixes. Added test for bug #333699.
2005-10-28 Sebastien Pouliot <sebastien@ximian.com>
* SecureStringCas.cs: New. CAS unit tests for SecureString.
* SecureStringTest.cs: New. Unit tests for SecureString.
2005-06-22 Sebastien Pouliot <sebastien@ximian.com>
* CodeAccessPermissionCas.cs: New. CAS unit tests for using the
stack modifiers (mostly assert) on permissions.
* SecurityManagerCas.cs: New. CAS unit tests for SecurityManager.
* SecurityManagerTest.cs: Moved a policy resolution test to
SecurityManagerCas as it required CheckExecutionRights to be on.
2005-06-20 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs: Added tests for AddPermission with non-CAS
permissions. Added tests for ContainsNonCodeAccessPermissions.
2005-06-16 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs: Added tests for AddPermission and IsSubsetOf.
2005-06-16 Sebastien Pouliot <sebastien@ximian.com>
* NamedPermissionSetTest.cs: Added more extensive constructor and
default values testing.
2005-06-10 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs: Added tests for GetPermission with null and
when using a subclass of a permission. Also some new (not working)
tests for NET_2_0.
2005-05-30 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs: Added unification tests for permissions inside
an ECMA signed assembly.
2005-05-28 Sebastien Pouliot <sebastien@ximian.com>
* HostSecurityManagerTest.cs: Remove NotWorking from tests.
2005-05-27 Sebastien Pouliot <sebastien@ximian.com>
* NamedPermissionSetTest.cs: Re-enable the "NotWorking" unit test.
* PermissionSetCas.cs: New. Moved RevertAssert unit tests from
PermissionSetTest to here as they require --security to work.
* PermissionSetTest.cs: Re-enable the "NotWorking" NET_2_0 unit tests.
* SecurityContextCas.cs: Fixed namespace.
2005-04-28 Sebastien Pouliot <sebastien@ximian.com>
* SecurityContextCas.cs: New. CAS unit tests for SecurityContext.
* SecurityContextTest.cs: New. Unit tests for SecurityContext.
* SecurityCriticalAttributeTest.cs: New. Unit tests for
SecurityCriticalAttribute.
* SecurityTransparentAttributeTest.cs: New. Unit tests for
SecurityTransparentAttribute.
2005-04-25 Sebastien Pouliot <sebastien@ximian.com>
* HostSecurityManagerTest.cs: Renamed HostSecurityManagerFlags to
HostSecurityManagerOptions to match beta2.
* PermissionSetCollectionTest.cs: Removed "set" tests for the
PermissionSets property (removed in beta2).
2005-03-31 Sebastien Pouliot <sebastien@ximian.com>
* SecurityExceptionCas.cs: Added new tests for GetObjectData.
2005-01-30 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs: Changed [Ignore] to [Category("NotDotNet")] to
reduce nunit logs.
* SecurityElementTest.cs: Changed [Ignore] to [Category("NotDotNet")]
to reduce nunit logs.
* SecurityManagerTest.cs: Changed [Ignore] to [Category("NotDotNet")]
to reduce nunit logs.
2005-01-28 Sebastien Pouliot <sebastien@ximian.com>
* SecurityExceptionCas.cs: New. Permission tests for SecurityException.
2005-01-19 Sebastien Pouliot <sebastien@ximian.com>
* SecurityManagerTest.cs: Added new tests for 2.0. Fixed a test to work
even if the SecurityManager.CheckExecutionRights is false.
2005-01-10 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetCollectionTest.cs: Added tests for to see if alternates
IList implementation (e.g. non-ArrayList) are supported as this
affects where we must check for exceptions.
* SecurityElementTest.cs: Add new tests for 2.0 methods. Adapted
existing tests to deal with the fact that 2.0 doesn't indent the XML
attributes and child elements.
2005-01-09 Sebastien Pouliot <sebastien@ximian.com>
* HostSecurityManagerTest.cs: New. Unit tests for HostSecurityManager.
* PermissionSetCollectionTest.cs: New. Unit tests for PermissionSet
Collection.
2005-01-04 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs, SecurityManagerTest.cs: Adjusted unit tests so
they now execute without errors on 2.0 Dec CTP.
2003-09-01 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs: Fixed tests so they execute without errors on
both Fx 1.1 and Fx 2.0 (beta 1).
* SecurityManagerTest.cs: Fixed tests so they execute without errors
on both Fx 1.1 and Fx 2.0 (beta 1).
2003-09-01 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs: Added tests for IsEmpty which can return true
even when Count > 0. Added tests for FromXml to see if class names
requires to be resolved when loaded from policy files.
* SecurityManagerTest.cs: Minor changes to tests so they succeed with
both Fx 1.1 and Fx 2.0 (beta 1).
2003-08-31 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetTest.cs: Fixed two typos than changed the behaviour of
Intersect and RemovePermission.
2003-08-30 Sebastien Pouliot <sebastien@ximian.com>
* NamedPermissionTest.cs: Added unit tests for Copy(), Copy(name),
more tests for From/ToXml and Equals/GetHashCode (for NET_2_0).
* PermissionSetTest.cs: Added new unit tests for AddPermission,
ContainsNonCodeAccessPermissions, partial tests for undocumented
ConvertPermissionSet, Copy, CopyTo, GetHashCode (for NET_2_0),
GetPermission, Intersect, IsSubset, RemovePermission, SetPermission
and Union.
2003-08-12 Sebastien Pouliot <sebastien@ximian.com>
* SecurityManagerTest.cs: More policy resolution tests when using host
or assembly provided evidences.
2003-08-04 Sebastien Pouliot <sebastien@ximian.com>
* SecurityManagerTest.cs: Added more unit tests.
2003-08-02 Sebastien Pouliot <sebastien@ximian.com>
* SecurityManagerTest.cs: Added bunch of tests for null usage.
Converted to NUnit 2.2.
2003-05-20 Sebastien Pouliot <sebastien@ximian.com>
* SecurityElementTest.cs: SetUp is now public (required for new nunit).
2004-01-27 Sebastien Pouliot <spouliot@videotron.ca>
* SecurityElementTest.cs: Added new tests for duplicate attributes
and multiple attribute order and ToString representation.
2004-01-24 David Sheldon <dave-mono@earth.li>
* CodeAccessPermissionTest.cs (To_String): Compared
Environment.NewLine rather than "\r\n"
2004-01-11 Sebastien Pouliot <spouliot@videotron.ca>
* CodeAccessPermissionTest.cs: Fixed CustomCAS test under Windows.
2004-01-06 Sebastien Pouliot <spouliot@videotron.ca>
* CodeAccessPermissionTest.cs: Added a new test for calling Demand on
custom code access permission.
Ref: http://bugzilla.ximian.com/show_bug.cgi?id=52626
* SecurityExceptionTest.cs: New. Unit tests for SecurityException.
2004-01-05 Sebastien Pouliot <spouliot@videotron.ca>
* CodeAccessPermissionTest.cs: New. Unit tests on a non-abstract
CodeAccessPermission class.
* SecurityManagerTest.cs: Removed .Policy from namespace.
2004-01-03 Sebastien Pouliot <spouliot@videotron.ca>
* SecurityManagerTest.cs: New. Added VERY minimal unit tests that I
used to validate some behaviors.
2004-01-02 Sebastien Pouliot <spouliot@videotron.ca>
* SecurityElementTest.cs: Added new tests, constructors and null
related, and converted to NUnit2.
2003-06-28 Sebastien Pouliot <spouliot@videotron.ca>
* PermissionSetTest.cs: New. Partial unit tests for PermissionSet.
* NamedPermissionSetTest.cs: New. Complete unit tests.
2002-12-21 Nick Drochak <ndrochak@gol.com>
* all: make tests build and run under nunit2
2002-06-11 Nick Drochak <ndrochak@gol.com>
* SecurityElementTest.cs: Catch and report unexpected exceptions.
2002-04-27 Lawrence Pit <loz@cable.a2000.nl>
* ChangeLog: added
* AllTests.cs: added
* SecurityElementTest.cs: added

View File

@@ -0,0 +1,335 @@
//
// CodeAccessPermissionCas.cs -
// CAS unit tests for System.Security.CodeAccessPermission
//
// 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.Collections;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System.Security {
[TestFixture]
[Category ("CAS")]
public class CodeAccessPermissionCas {
private const SecurityPermissionFlag Both = SecurityPermissionFlag.RemotingConfiguration | SecurityPermissionFlag.UnmanagedCode;
private bool result;
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
result = false;
}
[SecurityPermission (SecurityAction.Demand, Assertion = true)]
private void DemandAssertion ()
{
result = true;
}
[Test]
[SecurityPermission (SecurityAction.Deny, Assertion = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyAssertion_Assert ()
{
DemandAssertion ();
}
[SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
private void DemandUnmanagedCode ()
{
result = true;
}
[SecurityPermission (SecurityAction.Demand, RemotingConfiguration = true)]
private void DemandRemotingConfiguration ()
{
result = true;
}
[SecurityPermission (SecurityAction.Demand, UnmanagedCode = true, RemotingConfiguration = true)]
private void DemandBoth ()
{
result = true;
}
private void AssertSecurity (SecurityPermissionFlag flag)
{
bool unmanaged = ((flag & SecurityPermissionFlag.UnmanagedCode) != 0);
bool remoting = ((flag & SecurityPermissionFlag.RemotingConfiguration) != 0);
if (unmanaged && remoting)
DemandBoth ();
else if (unmanaged)
DemandUnmanagedCode ();
else if (remoting)
DemandRemotingConfiguration ();
else
Assert.Fail ("Invalid demand");
}
[SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
private void AssertUnmanagedCode (SecurityPermissionFlag flag)
{
AssertSecurity (flag);
}
[SecurityPermission (SecurityAction.Assert, RemotingConfiguration = true)]
private void AssertRemotingConfiguration (SecurityPermissionFlag flag)
{
AssertSecurity (flag);
}
[SecurityPermission (SecurityAction.Assert, UnmanagedCode = true, RemotingConfiguration = true)]
private void AssertBoth (SecurityPermissionFlag flag)
{
AssertSecurity (flag);
}
[SecurityPermission (SecurityAction.Assert, Unrestricted = true)]
private void AssertUnrestricted (SecurityPermissionFlag flag)
{
AssertSecurity (flag);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertUnmanaged_DemandUnmanaged ()
{
AssertUnmanagedCode (SecurityPermissionFlag.UnmanagedCode);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyUnrestricted_AssertUnmanaged_DemandRemoting ()
{
AssertUnmanagedCode (SecurityPermissionFlag.RemotingConfiguration);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyUnrestricted_AssertUnmanaged_DemandBoth ()
{
AssertUnmanagedCode (Both);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyUnrestricted_AssertRemoting_DemandUnmanaged ()
{
AssertRemotingConfiguration (SecurityPermissionFlag.UnmanagedCode);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertRemoting_DemandRemoting ()
{
AssertRemotingConfiguration (SecurityPermissionFlag.RemotingConfiguration);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyUnrestricted_AssertRemoting_DemandBoth ()
{
AssertRemotingConfiguration (Both);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertBoth_DemandUnmanaged ()
{
AssertBoth (SecurityPermissionFlag.UnmanagedCode);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertBoth_DemandRemoting ()
{
AssertBoth (SecurityPermissionFlag.RemotingConfiguration);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertBoth_DemandBoth ()
{
AssertBoth (Both);
Assert.IsTrue (result);
}
[SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
private void Assert_UnmanagedCode_RemotingConfiguration (SecurityPermissionFlag flag)
{
AssertRemotingConfiguration (flag);
}
[SecurityPermission (SecurityAction.Assert, RemotingConfiguration = true)]
private void Assert_RemotingConfiguration_UnmanagedCode (SecurityPermissionFlag flag)
{
AssertUnmanagedCode (flag);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyUnrestricted_AssertUnmanagedRemoting_DemandBoth ()
{
// no single stack frame can assert the whole SecurityPermission
// which is different from a PermissionSet
Assert_UnmanagedCode_RemotingConfiguration (Both);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertUnmanagedRemoting_DemandUnmanaged ()
{
Assert_UnmanagedCode_RemotingConfiguration (SecurityPermissionFlag.UnmanagedCode);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertUnmanagedRemoting_DemandRemoting ()
{
Assert_UnmanagedCode_RemotingConfiguration (SecurityPermissionFlag.RemotingConfiguration);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyUnrestricted_AssertRemotingUnmanaged_DemandBoth ()
{
// no single stack frame can assert the whole SecurityPermission
// which is different from a PermissionSet
Assert_RemotingConfiguration_UnmanagedCode (Both);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertRemotingUnmanaged_DemandUnmanaged ()
{
Assert_RemotingConfiguration_UnmanagedCode (SecurityPermissionFlag.UnmanagedCode);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertRemotingUnmanaged_DemandRemoting ()
{
Assert_RemotingConfiguration_UnmanagedCode (SecurityPermissionFlag.RemotingConfiguration);
Assert.IsTrue (result);
}
[SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
[ReflectionPermission (SecurityAction.Demand, ReflectionEmit = true)]
private void Demand_Reflection_Unmanaged ()
{
result = true;
}
[SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
private void Assert_Unmanaged (bool call)
{
if (call)
Demand_Reflection_Unmanaged ();
else
Assert_Reflection (true);
}
[ReflectionPermission (SecurityAction.Assert, ReflectionEmit = true)]
private void Assert_Reflection (bool call)
{
if (call)
Demand_Reflection_Unmanaged ();
else
Assert_Unmanaged (true);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ReflectionPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertReflectionUnmanaged_DemandUnmanagedReflection ()
{
Assert_Reflection (false);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ReflectionPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyUnrestricted_AssertReflection_DemandUnmanagedReflection ()
{
Assert_Reflection (true);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ReflectionPermission (SecurityAction.Deny, Unrestricted = true)]
public void Declarative_DenyUnrestricted_AssertUnmanagedReflection_DemandUnmanagedReflection ()
{
Assert_Unmanaged (false);
Assert.IsTrue (result);
}
[Test]
[SecurityPermission (SecurityAction.Deny, Unrestricted = true)]
[ReflectionPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void Declarative_DenyUnrestricted_AssertUnmanaged_DemandUnmanagedReflection ()
{
Assert_Unmanaged (true);
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void Declarative_PermitOnly_Unrestricted ()
{
// permitonly unrestricted is (technically) a no-op
DemandBoth ();
Assert.IsTrue (result);
}
}
}

View File

@@ -0,0 +1,91 @@
//
// CodeAccessPermissionTest.cs - NUnit Test Cases for CodeAccessPermission
//
// Author:
// Sebastien Pouliot (spouliot@motus.com)
//
// (C) 2004 Motus Technologies Inc. (http://www.motus.com)
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Text;
namespace MonoTests.System.Security {
// Almost minimal CAS class for unit tests
[Serializable]
public class NonAbstractCodeAccessPermission : CodeAccessPermission {
private string _tag;
private string _text;
public NonAbstractCodeAccessPermission (string tag, string text)
{
_tag = tag;
_text = text;
}
public override IPermission Copy ()
{
return new NonAbstractCodeAccessPermission (_tag, _text);
}
public override void FromXml (SecurityElement elem) {}
public override IPermission Intersect (IPermission target)
{
return null;
}
public override bool IsSubsetOf (IPermission target)
{
return true;
}
public override SecurityElement ToXml ()
{
if (_tag == null)
return null;
return new SecurityElement (_tag, _text);
}
}
[TestFixture]
[Category ("CAS")]
public class CodeAccessPermissionTest {
[Test]
public void CustomCAS ()
{
// test for http://bugzilla.ximian.com/show_bug.cgi?id=52626
NonAbstractCodeAccessPermission p = new NonAbstractCodeAccessPermission ("custom", null);
p.Demand ();
}
[Test]
public void Union ()
{
NonAbstractCodeAccessPermission cap = new NonAbstractCodeAccessPermission (null, null);
IPermission p = cap.Union (null);
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void To_String_Exception ()
{
NonAbstractCodeAccessPermission cap = new NonAbstractCodeAccessPermission (null, null);
string s = cap.ToString ();
}
[Test]
public void To_String ()
{
NonAbstractCodeAccessPermission cap = new NonAbstractCodeAccessPermission ("CodeAccessPermission", "NonAbstract");
string s = cap.ToString ();
Assert.AreEqual ("<CodeAccessPermission>NonAbstract</CodeAccessPermission>" + Environment.NewLine, s, "ToString");
}
}
}

View File

@@ -0,0 +1,157 @@
//
// HostSecurityManagerTest.cs - NUnit Test Cases for HostSecurityManager
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
// Copyright 2011 Xamarin Inc (http://www.xamarin.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.
//
// NET_2_1 profile lacks some (of the few) CAS features required to execute those tests
#if NET_2_0 && !NET_2_1
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Policy;
namespace MonoTests.System.Security {
[TestFixture]
public class HostSecurityManagerTest {
[Test]
public void Defaults ()
{
HostSecurityManager hsm = new HostSecurityManager ();
Assert.IsNull (hsm.DomainPolicy, "DomainPolicy");
Assert.AreEqual (HostSecurityManagerOptions.AllFlags, hsm.Flags, "Flags");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void DetermineApplicationTrust_Null_Evidence_TrustManagerContext ()
{
HostSecurityManager hsm = new HostSecurityManager ();
hsm.DetermineApplicationTrust (null, new Evidence (), new TrustManagerContext ());
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DetermineApplicationTrust_Evidence_Null_TrustManagerContext ()
{
HostSecurityManager hsm = new HostSecurityManager ();
hsm.DetermineApplicationTrust (new Evidence (), null, new TrustManagerContext ());
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DetermineApplicationTrust_Evidence_Evidence_Null ()
{
HostSecurityManager hsm = new HostSecurityManager ();
hsm.DetermineApplicationTrust (new Evidence (), new Evidence (), null);
}
[Test]
public void ProvideAppDomainEvidence ()
{
HostSecurityManager hsm = new HostSecurityManager ();
Assert.IsNull (hsm.ProvideAppDomainEvidence (null), "null");
Evidence e = new Evidence ();
Evidence result = hsm.ProvideAppDomainEvidence (e);
Assert.IsNotNull (result, "empty");
Assert.AreEqual (0, result.Count, "Count-0");
e.AddHost (new Zone (SecurityZone.Untrusted));
result = hsm.ProvideAppDomainEvidence (e);
Assert.AreEqual (1, result.Count, "Count-1");
}
[Test]
public void ProvideAssemblyEvidence ()
{
HostSecurityManager hsm = new HostSecurityManager ();
Assembly a = Assembly.GetExecutingAssembly ();
Evidence result = hsm.ProvideAssemblyEvidence (a, null);
Assert.IsNull (result, "null");
Evidence e = new Evidence ();
result = hsm.ProvideAssemblyEvidence (a, e);
Assert.AreEqual (0, result.Count, "Count-empty");
e.AddHost (new Zone (SecurityZone.Untrusted));
result = hsm.ProvideAssemblyEvidence (a, e);
Assert.AreEqual (1, result.Count, "Count-1");
}
[Test]
public void ProvideAssemblyEvidence_NullAssembly ()
{
HostSecurityManager hsm = new HostSecurityManager ();
Evidence result = hsm.ProvideAssemblyEvidence (null, null);
Assert.IsNull (result, "null");
Evidence e = new Evidence ();
result = hsm.ProvideAssemblyEvidence (null, e);
Assert.AreEqual (0, result.Count, "Count-empty");
e.AddHost (new Zone (SecurityZone.Untrusted));
result = hsm.ProvideAssemblyEvidence (null, e);
Assert.AreEqual (1, result.Count, "Count-1");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void ResolvePolicy_Null ()
{
HostSecurityManager hsm = new HostSecurityManager ();
PermissionSet ps = hsm.ResolvePolicy (null);
}
[Test]
public void ResolvePolicy_Empty ()
{
HostSecurityManager hsm = new HostSecurityManager ();
PermissionSet ps = hsm.ResolvePolicy (new Evidence ());
Assert.AreEqual (0, ps.Count, "Count");
Assert.IsFalse (ps.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void ResolvePolicy_CurrentAssemblyEvidence ()
{
HostSecurityManager hsm = new HostSecurityManager ();
Assembly a = Assembly.GetExecutingAssembly ();
PermissionSet ps = hsm.ResolvePolicy (a.Evidence);
PermissionSet expected = SecurityManager.ResolvePolicy (a.Evidence);
Assert.AreEqual (expected.ToString (), ps.ToString (), "PermissionSet");
}
}
}
#endif

View File

@@ -0,0 +1,449 @@
//
// NamedPermissionSetTest.cs - NUnit Test Cases for NamedPermissionSet
//
// 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 !MOBILE
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security {
[TestFixture]
public class NamedPermissionSetTest {
private static string name = "mono";
private static string sentinel = "go mono!";
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorNameNull ()
{
string s = null; // we don't want to confuse the compiler
NamedPermissionSet nps = new NamedPermissionSet (s);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorNameEmpty ()
{
NamedPermissionSet nps = new NamedPermissionSet ("");
}
[Test]
public void ConstructorName ()
{
NamedPermissionSet nps = new NamedPermissionSet ("name");
Assert.AreEqual ("name", nps.Name, "Name");
Assert.IsNull (nps.Description, "Description");
Assert.IsTrue (nps.IsUnrestricted (), "IsUnrestricted");
Assert.IsTrue (!nps.IsEmpty (), "IsEmpty");
Assert.IsTrue (!nps.IsReadOnly, "IsReadOnly");
Assert.IsTrue (!nps.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, nps.Count, "Count");
}
[Test]
public void ConstructorNameReserved ()
{
NamedPermissionSet nps = new NamedPermissionSet ("FullTrust");
Assert.AreEqual ("FullTrust", nps.Name, "Name");
Assert.IsNull (nps.Description, "Description");
Assert.IsTrue (nps.IsUnrestricted (), "IsUnrestricted");
Assert.IsTrue (!nps.IsEmpty (), "IsEmpty");
Assert.IsTrue (!nps.IsReadOnly, "IsReadOnly");
Assert.IsTrue (!nps.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, nps.Count, "Count");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void ConstructorNamedPermissionSetNull ()
{
NamedPermissionSet nullps = null;
NamedPermissionSet nps = new NamedPermissionSet (nullps);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorNameNullPermissionState ()
{
new NamedPermissionSet (null, PermissionState.None);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorNameEmptyPermissionState ()
{
new NamedPermissionSet (String.Empty, PermissionState.None);
}
[Test]
public void ConstructorNamePermissionStateNone ()
{
NamedPermissionSet nps = new NamedPermissionSet ("name", PermissionState.None);
Assert.AreEqual ("name", nps.Name, "Name");
Assert.IsNull (nps.Description, "Description");
Assert.IsTrue (!nps.IsUnrestricted (), "IsUnrestricted");
Assert.IsTrue (nps.IsEmpty (), "IsEmpty");
Assert.IsTrue (!nps.IsReadOnly, "IsReadOnly");
Assert.IsTrue (!nps.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, nps.Count, "Count");
}
[Test]
public void ConstructorNamePermissionStateUnrestricted ()
{
NamedPermissionSet nps = new NamedPermissionSet ("name", PermissionState.Unrestricted);
Assert.AreEqual ("name", nps.Name, "Name");
Assert.IsNull (nps.Description, "Description");
Assert.IsTrue (nps.IsUnrestricted (), "IsUnrestricted");
Assert.IsTrue (!nps.IsEmpty (), "IsEmpty");
Assert.IsTrue (!nps.IsReadOnly, "IsReadOnly");
Assert.IsTrue (!nps.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, nps.Count, "Count");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorNameNullPermissionSet ()
{
new NamedPermissionSet (null, new PermissionSet (PermissionState.None));
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorNameEmptyPermissionSet ()
{
new NamedPermissionSet (String.Empty, new PermissionSet (PermissionState.None));
}
[Test]
public void ConstructorNamePermissionSetNull ()
{
NamedPermissionSet nps = new NamedPermissionSet ("name", null);
Assert.AreEqual ("name", nps.Name, "Name");
Assert.IsNull (nps.Description, "Description");
#if NET_2_0
Assert.IsTrue (!nps.IsUnrestricted (), "IsUnrestricted");
Assert.IsTrue (nps.IsEmpty (), "IsEmpty");
#else
Assert.IsTrue (nps.IsUnrestricted (), "IsUnrestricted");
Assert.IsTrue (!nps.IsEmpty (), "IsEmpty");
#endif
Assert.IsTrue (!nps.IsReadOnly, "IsReadOnly");
Assert.IsTrue (!nps.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, nps.Count, "Count");
}
[Test]
public void Description ()
{
NamedPermissionSet nps = new NamedPermissionSet (name);
// null by default (not empty)
Assert.IsNull (nps.Description, "Description");
// is null-able (without exception)
nps.Description = null;
Assert.IsNull (nps.Description, "Description(null)");
nps.Description = sentinel;
Assert.AreEqual (sentinel, nps.Description, "Description");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void NameNull ()
{
NamedPermissionSet nps = new NamedPermissionSet (name);
nps.Name = null;
// strangely this isn't a ArgumentNullException (but so says the doc)
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void NameEmpty ()
{
NamedPermissionSet nps = new NamedPermissionSet (name);
nps.Name = "";
}
[Test]
public void Name ()
{
NamedPermissionSet nps = new NamedPermissionSet (name);
nps.Name = sentinel;
Assert.AreEqual (sentinel, nps.Name, "Name");
}
[Test]
public void Copy ()
{
NamedPermissionSet nps = new NamedPermissionSet (name);
nps.Description = sentinel;
nps.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion));
NamedPermissionSet copy = (NamedPermissionSet)nps.Copy ();
Assert.AreEqual (nps.Name, copy.Name, "Name");
Assert.AreEqual (nps.Description, copy.Description, "Description");
Assert.AreEqual (nps.Count, copy.Count, "Count");
}
[Test]
public void Copy_Name ()
{
NamedPermissionSet nps = new NamedPermissionSet (name);
nps.Description = sentinel;
nps.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion));
NamedPermissionSet copy = (NamedPermissionSet)nps.Copy ("Copy");
Assert.AreEqual ("Copy", copy.Name, "Name");
Assert.AreEqual (nps.Description, copy.Description, "Description");
Assert.AreEqual (nps.Count, copy.Count, "Count");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Copy_Name_Null ()
{
NamedPermissionSet nps = new NamedPermissionSet (name);
NamedPermissionSet copy = (NamedPermissionSet)nps.Copy (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Copy_Name_Empty ()
{
NamedPermissionSet nps = new NamedPermissionSet (name);
NamedPermissionSet copy = (NamedPermissionSet)nps.Copy (String.Empty);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
nps.FromXml (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_InvalidPermission ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
SecurityElement se = nps.ToXml ();
// can't modify - so we create our own
SecurityElement se2 = new SecurityElement ("InvalidPermissionSet", se.Text);
se2.AddAttribute ("class", se.Attribute ("class"));
se2.AddAttribute ("version", se.Attribute ("version"));
se2.AddAttribute ("Name", se.Attribute ("Name"));
nps.FromXml (se2);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongTagCase ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
SecurityElement se = nps.ToXml ();
se.Tag = se.Tag.ToUpper (); // instead of PermissionSet
nps.FromXml (se);
}
[Test]
public void FromXml_WrongClass ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
SecurityElement se = nps.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
w.AddAttribute ("version", se.Attribute ("version"));
w.AddAttribute ("Name", se.Attribute ("Name"));
nps.FromXml (w);
// doesn't care of the class name at that stage
// anyway the class has already be created so...
}
[Test]
public void FromXml_NoClass ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
SecurityElement se = nps.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
nps.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
// [ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongVersion ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
SecurityElement se = nps.ToXml ();
// can't modify - so we create our own
SecurityElement se2 = new SecurityElement (se.Tag, se.Text);
se2.AddAttribute ("class", se.Attribute ("class"));
se2.AddAttribute ("version", "2");
se2.AddAttribute ("Name", se.Attribute ("Name"));
nps.FromXml (se2);
// wow - here we accept a version 2 !!!
}
[Test]
public void FromXml_NoVersion ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
SecurityElement se = nps.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("Name", se.Attribute ("Name"));
nps.FromXml (w);
}
[Test]
public void FromXml_NoName ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
SecurityElement se = nps.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
w.AddAttribute ("version", "1");
nps.FromXml (w);
// having a null name can badly influence the rest of the class code
Assert.IsNull (nps.Name, "Name");
NamedPermissionSet copy = (NamedPermissionSet) nps.Copy ();
Assert.IsNull (copy.Name, "Copy.Name");
copy = nps.Copy ("name");
Assert.AreEqual ("name", copy.Name, "Copy(Name).Name");
se = nps.ToXml ();
Assert.IsNull (se.Attribute ("Name"), "Name attribute");
#if NET_2_0
Assert.AreEqual (0, nps.GetHashCode (), "GetHashCode");
Assert.IsTrue (nps.Equals (nps), "Equals-self");
#endif
}
[Test]
public void FromXml ()
{
NamedPermissionSet nps = new NamedPermissionSet (name, PermissionState.None);
SecurityElement se = nps.ToXml ();
Assert.IsNotNull (se, "ToXml()");
NamedPermissionSet nps2 = (NamedPermissionSet) nps.Copy ();
nps2.FromXml (se);
Assert.AreEqual (name, nps2.Name, "FromXml-Copy.Name");
// strangely it's empty when converted from XML (but null when created)
Assert.AreEqual ("", nps2.Description, "FromXml-Copy.Description");
Assert.IsTrue (!nps2.IsUnrestricted () , "FromXml-Copy.IsUnrestricted");
se.AddAttribute ("Description", sentinel);
nps2.FromXml (se);
Assert.AreEqual (name, nps2.Name, "FromXml-Add1.Name");
Assert.AreEqual (sentinel, nps2.Description, "FromXml-Add1.Description");
Assert.IsTrue (!nps2.IsUnrestricted () , "FromXml-Add1.IsUnrestricted");
se.AddAttribute ("Unrestricted", "true");
nps2.FromXml (se);
Assert.AreEqual (name, nps2.Name, "FromXml-Add2.Name");
Assert.AreEqual (sentinel, nps2.Description, "FromXml-Add2.Description");
Assert.IsTrue (nps2.IsUnrestricted () , "FromXml-Add2.IsUnrestricted");
}
[Test]
public void ToXml_None ()
{
NamedPermissionSet ps = new NamedPermissionSet (name, PermissionState.None);
ps.Description = sentinel;
SecurityElement se = ps.ToXml ();
Assert.IsTrue (ps.ToString().StartsWith ("<PermissionSet"), "None.ToString().StartsWith");
Assert.AreEqual ("System.Security.NamedPermissionSet", (se.Attributes ["class"] as string), "None.class");
Assert.AreEqual ("1", (se.Attributes ["version"] as string), "None.version");
Assert.AreEqual (name, (se.Attributes ["Name"] as string), "None.Name");
Assert.AreEqual (sentinel, (se.Attributes ["Description"] as string), "None.Description");
Assert.IsNull ((se.Attributes ["Unrestricted"] as string), "None.Unrestricted");
}
[Test]
public void ToXml_Unrestricted ()
{
NamedPermissionSet ps = new NamedPermissionSet (name, PermissionState.Unrestricted);
SecurityElement se = ps.ToXml ();
Assert.IsTrue (ps.ToString().StartsWith ("<PermissionSet"), "Unrestricted.ToString().StartsWith");
Assert.AreEqual ("System.Security.NamedPermissionSet", (se.Attributes ["class"] as string), "Unrestricted.class");
Assert.AreEqual ("1", (se.Attributes ["version"] as string), "Unrestricted.version");
Assert.AreEqual (name, (se.Attributes ["Name"] as string), "Unrestricted.Name");
Assert.IsNull ((se.Attributes ["Description"] as string), "Unrestricted.Description");
Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "Unrestricted.Unrestricted");
}
#if NET_2_0
[Test]
public void Equals ()
{
NamedPermissionSet psn = new NamedPermissionSet (name, PermissionState.None);
NamedPermissionSet psu = new NamedPermissionSet (name, PermissionState.Unrestricted);
Assert.IsTrue (!psn.Equals (psu), "psn!=psu");
Assert.IsTrue (!psu.Equals (psn), "psu!=psn");
NamedPermissionSet cpsn = (NamedPermissionSet) psn.Copy ();
Assert.IsTrue (cpsn.Equals (psn), "cpsn==psn");
Assert.IsTrue (psn.Equals (cpsn), "psn==cpsn");
NamedPermissionSet cpsu = (NamedPermissionSet) psu.Copy ();
Assert.IsTrue (cpsu.Equals (psu), "cpsu==psu");
Assert.IsTrue (psu.Equals (cpsu), "psu==cpsu");
cpsn.Description = sentinel;
Assert.IsTrue (cpsn.Equals (psn), "cpsn+desc==psn");
Assert.IsTrue (psn.Equals (cpsn), "psn==cpsn+desc");
cpsn.Description = sentinel;
Assert.IsTrue (cpsu.Equals (psu), "cpsu+desc==psu");
Assert.IsTrue (psu.Equals (cpsu), "psu==cpsu+desc");
}
[Test]
public void GetHashCode_ ()
{
NamedPermissionSet psn = new NamedPermissionSet (name, PermissionState.None);
int nhc = psn.GetHashCode ();
NamedPermissionSet psu = new NamedPermissionSet (name, PermissionState.Unrestricted);
int uhc = psu.GetHashCode ();
Assert.IsTrue (nhc != uhc, "GetHashCode-1");
psn.Description = sentinel;
Assert.IsTrue (psn.GetHashCode () == nhc, "GetHashCode-2");
psu.Description = sentinel;
Assert.IsTrue (psu.GetHashCode () == uhc, "GetHashCode-3");
}
#endif
}
}
#endif

View File

@@ -0,0 +1,65 @@
//
// PermissionSetCas.cs - CAS Unit Tests for PermissionSet
//
// 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 System;
using System.Security;
using System.Security.Permissions;
using NUnit.Framework;
namespace MonoCasTests.System.Security {
[TestFixture]
[Category ("CAS")]
public class PermissionSetCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager isn't enabled");
}
#if NET_2_0
[Test]
[ExpectedException (typeof (ExecutionEngineException))]
public void RevertAssert_WithoutAssertion ()
{
PermissionSet.RevertAssert ();
}
[Test]
public void RevertAssert_WithAssertion ()
{
PermissionSet ups = new PermissionSet (PermissionState.Unrestricted);
ups.Assert ();
PermissionSet.RevertAssert ();
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,88 @@
//
// SecureStringCas.cs - CAS unit tests for System.Security.SecureString
//
// 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 System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using NUnit.Framework;
using MonoTests.System.Security;
namespace MonoCasTests.System.Security {
[TestFixture]
[Category ("CAS")]
public class SecureStringCas {
private const string NotSupported = "Not supported before Windows 2000 Service Pack 3";
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTest ()
{
try {
SecureStringTest unit = new SecureStringTest ();
unit.DefaultConstructor ();
#if !TARGET_JVM
unit.UnsafeConstructor ();
#endif
unit.ReadOnly ();
unit.Disposed ();
}
catch (NotSupportedException) {
Assert.Ignore (NotSupported);
}
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
try {
ConstructorInfo ci = typeof (SecureString).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
catch (NotSupportedException) {
Assert.Ignore (NotSupported);
}
}
}
}
#endif

View File

@@ -0,0 +1,412 @@
//
// SecureStringTest.cs - Unit tests for System.Security.SecureString
//
// 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 System;
using System.Security;
using System.Runtime.InteropServices;
using NUnit.Framework;
namespace MonoTests.System.Security {
[TestFixture]
public class SecureStringTest {
private const string NotSupported = "Not supported before Windows 2000 Service Pack 3";
[Test]
public void DefaultConstructor ()
{
try {
SecureString ss = new SecureString ();
Assert.IsFalse (ss.IsReadOnly (), "IsReadOnly");
Assert.AreEqual (0, ss.Length, "0");
ss.AppendChar ('a');
Assert.AreEqual (1, ss.Length, "1");
ss.Clear ();
Assert.AreEqual (0, ss.Length, "0b");
ss.InsertAt (0, 'b');
Assert.AreEqual (1, ss.Length, "1b");
ss.SetAt (0, 'c');
Assert.AreEqual (1, ss.Length, "1c");
Assert.AreEqual ("System.Security.SecureString", ss.ToString (), "ToString");
ss.RemoveAt (0);
Assert.AreEqual (0, ss.Length, "0c");
ss.Dispose ();
}
catch (NotSupportedException) {
Assert.Ignore (NotSupported);
}
}
#if !TARGET_JVM
[Test]
public unsafe void UnsafeConstructor ()
{
try {
SecureString ss = null;
char[] data = new char[] { 'a', 'b', 'c' };
fixed (char* p = &data[0]) {
ss = new SecureString (p, data.Length);
}
Assert.IsFalse (ss.IsReadOnly (), "IsReadOnly");
Assert.AreEqual (3, ss.Length, "3");
ss.AppendChar ('a');
Assert.AreEqual (4, ss.Length, "4");
ss.Clear ();
Assert.AreEqual (0, ss.Length, "0b");
ss.InsertAt (0, 'b');
Assert.AreEqual (1, ss.Length, "1b");
ss.SetAt (0, 'c');
Assert.AreEqual (1, ss.Length, "1c");
ss.RemoveAt (0);
Assert.AreEqual (0, ss.Length, "0c");
ss.Dispose ();
}
catch (NotSupportedException) {
Assert.Ignore (NotSupported);
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public unsafe void UnsafeConstructor_Null ()
{
new SecureString (null, 0);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public unsafe void UnsafeConstructor_Negative ()
{
char[] data = new char[] { 'a', 'b', 'c' };
fixed (char* p = &data[0]) {
new SecureString (p, -1);
}
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public unsafe void UnsafeConstructor_BiggerThanMax ()
{
char[] data = new char[] { 'a', 'b', 'c' };
fixed (char* p = &data[0]) {
new SecureString (p, UInt16.MaxValue + 2);
}
}
private SecureString max;
private unsafe SecureString GetMaxLength ()
{
if (max == null) {
int maxlength = UInt16.MaxValue + 1;
char[] data = new char[maxlength];
fixed (char* p = &data[0]) {
max = new SecureString (p, maxlength);
}
// note: don't try a loop of AppendChar with that size ;-)
}
return max;
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void AppendChar_BiggerThanMax ()
{
SecureString ss = GetMaxLength ();
ss.AppendChar ('a');
}
#endif
[Test]
public void Copy_Empty ()
{
SecureString empty = new SecureString ();
Assert.AreEqual (0, empty.Length, "Empty.Length");
SecureString empty_copy = empty.Copy ();
Assert.AreEqual (0, empty_copy.Length, "EmptyCopy.Length");
}
[Test]
public void Copy ()
{
SecureString ss = new SecureString ();
ss.AppendChar ('a');
Assert.AreEqual (1, ss.Length, "Length");
SecureString ss2 = ss.Copy();
Assert.AreEqual (1, ss2.Length, "Copy.Length");
Assert.IsFalse (ss2.IsReadOnly (), "Copy.IsReadOnly");
ss2.MakeReadOnly ();
Assert.IsTrue (ss2.IsReadOnly (), "Copy.IsReadOnly-2");
SecureString ss3 = ss2.Copy ();
Assert.IsFalse (ss3.IsReadOnly (), "Copy.IsReadOnly-3");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void InsertAt_Negative ()
{
SecureString ss = new SecureString ();
ss.InsertAt (-1, 'a');
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void InsertAt_BiggerThanLength ()
{
SecureString ss = new SecureString ();
ss.InsertAt (1, 'a');
}
[Test]
public void InsertAt_UsedLikeAppendChar () // #350820
{
SecureString ss = new SecureString ();
ss.AppendChar ('T');
Assert.AreEqual (1, ss.Length, "AppendChar");
ss.InsertAt (1, 'e');
Assert.AreEqual (2, ss.Length, "InsertAt");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetAt_Negative ()
{
SecureString ss = new SecureString ();
ss.SetAt (-1, 'a');
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void SetAt_BiggerThanLength ()
{
SecureString ss = new SecureString ();
ss.SetAt (1, 'a');
}
[Test]
public void RemoveAt ()
{
string test_string = "test string";
string expected, actual;
SecureString ss = new SecureString ();
foreach (char c in test_string) {
ss.AppendChar (c);
}
ss.RemoveAt (0);
expected = "est string";
actual = ReadSecureString (ss);
Assert.AreEqual (expected, actual, "RemoveAt begining");
ss.RemoveAt (4);
expected = "est tring";
actual = ReadSecureString (ss);
Assert.AreEqual (expected, actual, "RemoveAt middle");
ss.RemoveAt (8);
expected = "est trin";
actual = ReadSecureString (ss);
Assert.AreEqual (expected, actual, "RemoveAt end");
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void RemoveAt_Negative ()
{
SecureString ss = new SecureString ();
ss.RemoveAt (-1);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void RemoveAt_BiggerThanLength ()
{
SecureString ss = new SecureString ();
ss.RemoveAt (1);
}
#if !TARGET_JVM
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void InsertAt_BiggerThanMax ()
{
SecureString ss = GetMaxLength ();
ss.InsertAt (ss.Length, 'a');
}
#endif
private SecureString GetReadOnly ()
{
SecureString ss = new SecureString ();
ss.MakeReadOnly ();
return ss;
}
[Test]
public void ReadOnly ()
{
try {
SecureString ss = GetReadOnly ();
Assert.IsTrue (ss.IsReadOnly (), "IsReadOnly");
Assert.AreEqual (0, ss.Length, "0");
ss.Dispose ();
}
catch (NotSupportedException) {
Assert.Ignore (NotSupported);
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ReadOnly_AppendChar ()
{
SecureString ss = GetReadOnly ();
ss.AppendChar ('a');
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ReadOnly_Clear ()
{
SecureString ss = GetReadOnly ();
ss.Clear ();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ReadOnly_InsertAt ()
{
SecureString ss = GetReadOnly ();
ss.InsertAt (0, 'a');
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ReadOnly_SetAt ()
{
SecureString ss = GetReadOnly ();
ss.SetAt (0, 'a');
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ReadOnly_RemoveAt ()
{
SecureString ss = GetReadOnly ();
ss.RemoveAt (0);
}
private SecureString GetDisposed ()
{
SecureString ss = new SecureString ();
ss.Dispose ();
return ss;
}
[Test]
public void Disposed ()
{
try {
SecureString ss = GetDisposed ();
ss.Dispose ();
}
catch (NotSupportedException) {
Assert.Ignore (NotSupported);
}
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Disposed_AppendChar ()
{
SecureString ss = GetDisposed ();
ss.AppendChar ('a');
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Disposed_Clear ()
{
SecureString ss = GetDisposed ();
ss.Clear ();
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Disposed_InsertAt ()
{
SecureString ss = GetDisposed ();
ss.InsertAt (0, 'a');
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Disposed_IsReadOnly ()
{
SecureString ss = GetDisposed ();
Assert.IsFalse (ss.IsReadOnly (), "IsReadOnly");
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Disposed_Length ()
{
SecureString ss = GetDisposed ();
Assert.AreEqual (0, ss.Length, "Length");
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Disposed_SetAt ()
{
SecureString ss = GetDisposed ();
ss.SetAt (0, 'a');
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void Disposed_RemoveAt ()
{
SecureString ss = GetDisposed ();
ss.RemoveAt (0);
}
// helper function
private static string ReadSecureString(SecureString aSecureString)
{
var strPtr = Marshal.SecureStringToGlobalAllocUnicode (aSecureString);
var str = Marshal.PtrToStringUni(strPtr);
Marshal.ZeroFreeGlobalAllocUnicode (strPtr);
return str;
}
}
}
#endif

View File

@@ -0,0 +1,172 @@
//
// SecurityContextCas.cs - CAS Unit Tests for SecurityContext
//
// 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 System;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using NUnit.Framework;
namespace MonoCasTests.System.Security {
[TestFixture]
[Category ("CAS")]
public class SecurityContextCas {
static bool success;
static void Callback (object o)
{
new SecurityPermission (SecurityPermissionFlag.UnmanagedCode).Demand ();
success = (bool)o;
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager isn't enabled");
success = false;
}
[TearDown]
public void TearDown ()
{
if (SecurityContext.IsFlowSuppressed () || SecurityContext.IsWindowsIdentityFlowSuppressed ())
SecurityContext.RestoreFlow ();
}
private void Thread_Run_Empty ()
{
Assert.IsFalse (success, "pre-check");
SecurityContext.Run (SecurityContext.Capture (), new ContextCallback (Callback), true);
Assert.IsTrue (success, "post-check");
}
[Test]
public void Run_Empty ()
{
Thread t = new Thread (new ThreadStart (Thread_Run_Empty));
t.Start ();
t.Join ();
}
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
private SecurityContext GetSecurityContextUnmanaged ()
{
return SecurityContext.Capture ();
// the Deny disappears with this stack frame but we got a capture of it
}
private void Thread_Run_UnmanagedCode ()
{
bool result = false;
Assert.IsFalse (success, "pre-check");
try {
SecurityContext sc = GetSecurityContextUnmanaged ();
// run with the captured security stack (i.e. deny unmanaged)
SecurityContext.Run (sc, new ContextCallback (Callback), true);
}
catch (SecurityException) {
result = true;
}
finally {
Assert.IsFalse (success, "post-check");
Assert.IsTrue (result, "Result");
}
}
[Test]
public void Run_UnmanagedCode ()
{
Thread t = new Thread (new ThreadStart (Thread_Run_UnmanagedCode));
t.Start ();
t.Join ();
}
private void Thread_Run_UnmanagedCode_SuppressFlow_BeforeCapture ()
{
bool result = false;
Assert.IsFalse (success, "pre-check");
AsyncFlowControl afc = SecurityContext.SuppressFlow ();
try {
SecurityContext sc = GetSecurityContextUnmanaged ();
SecurityContext.Run (sc, new ContextCallback (Callback), true);
}
catch (InvalidOperationException) {
result = true;
}
finally {
Assert.IsFalse (success, "post-check");
afc.Undo ();
Assert.IsTrue (result, "Result");
}
}
[Test]
public void Run_UnmanagedCode_SuppressFlow_BeforeCapture ()
{
Thread t = new Thread (new ThreadStart (Thread_Run_UnmanagedCode_SuppressFlow_BeforeCapture));
t.Start ();
t.Join ();
}
private void Thread_Run_UnmanagedCode_SuppressFlow_AfterCapture ()
{
bool result = false;
Assert.IsFalse (success, "pre-check");
SecurityContext sc = GetSecurityContextUnmanaged ();
AsyncFlowControl afc = SecurityContext.SuppressFlow ();
try {
SecurityContext.Run (sc, new ContextCallback (Callback), true);
}
catch (SecurityException) {
result = true;
}
finally {
Assert.IsFalse (success, "post-check");
afc.Undo ();
Assert.IsTrue (result, "Result");
}
}
[Test]
public void Run_UnmanagedCode_SuppressFlow_AfterCapture ()
{
Thread t = new Thread (new ThreadStart (Thread_Run_UnmanagedCode_SuppressFlow_AfterCapture));
t.Start ();
t.Join ();
}
}
}
#endif

View File

@@ -0,0 +1,290 @@
//
// SecurityContextTest.cs - NUnit tests for SecurityContext
//
// 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 !MOBILE
using System;
using System.Security;
using System.Security.Principal;
using System.Threading;
using NUnit.Framework;
namespace MonoTests.System.Security {
[TestFixture]
public class SecurityContextTest {
static bool success;
static void Callback (object o)
{
success = (bool) o;
}
[SetUp]
public void SetUp ()
{
success = false;
}
[TearDown]
public void TearDown ()
{
if (SecurityContext.IsFlowSuppressed () || SecurityContext.IsWindowsIdentityFlowSuppressed ())
SecurityContext.RestoreFlow ();
}
[Test]
public void Capture ()
{
SecurityContext sc = SecurityContext.Capture ();
Assert.IsNotNull (sc, "Capture");
AsyncFlowControl afc = SecurityContext.SuppressFlow ();
Assert.IsTrue (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-1");
try {
sc = SecurityContext.Capture ();
Assert.IsNull (sc, "Capture with SuppressFlow");
}
finally {
afc.Undo ();
}
afc = SecurityContext.SuppressFlowWindowsIdentity ();
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-1");
try {
sc = SecurityContext.Capture ();
Assert.IsNotNull (sc, "Capture with SuppressFlowWindowsIdentity");
}
finally {
afc.Undo ();
}
}
[Test]
public void Copy ()
{
SecurityContext sc = SecurityContext.Capture ();
Assert.IsNotNull (sc, "Capture");
SecurityContext copy = sc.CreateCopy ();
Assert.IsNotNull (copy, "Copy of Capture");
Assert.IsFalse (sc.Equals (copy));
Assert.IsFalse (copy.Equals (sc));
Assert.IsFalse (Object.ReferenceEquals (sc, copy));
SecurityContext copy2nd = copy.CreateCopy ();
Assert.IsNotNull (copy2nd, "2nd level copy of Capture");
}
[Test]
public void IsFlowSuppressed ()
{
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-1");
AsyncFlowControl afc = SecurityContext.SuppressFlowWindowsIdentity ();
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
afc.Undo ();
afc = SecurityContext.SuppressFlow ();
Assert.IsTrue (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-3");
afc.Undo ();
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-4");
}
[Test]
public void IsWindowsIdentityFlowSuppressed ()
{
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-1");
AsyncFlowControl afc = SecurityContext.SuppressFlow ();
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
afc.Undo ();
afc = SecurityContext.SuppressFlowWindowsIdentity ();
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-3");
afc.Undo ();
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-4");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void RestoreFlow_None ()
{
SecurityContext.RestoreFlow ();
}
[Test]
public void RestoreFlow_SuppressFlow ()
{
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-1");
SecurityContext.SuppressFlow ();
Assert.IsTrue (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
SecurityContext.RestoreFlow ();
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-3");
}
[Test]
public void RestoreFlow_SuppressFlowWindowsIdentity ()
{
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-1");
SecurityContext.SuppressFlowWindowsIdentity ();
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
SecurityContext.RestoreFlow ();
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-3");
}
[Test]
public void Run ()
{
Assert.IsFalse (success, "pre-check");
SecurityContext.Run (SecurityContext.Capture (), new ContextCallback (Callback), true);
Assert.IsTrue (success, "post-check");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void Run_SuppressFlow ()
{
Assert.IsFalse (SecurityContext.IsFlowSuppressed ());
AsyncFlowControl afc = SecurityContext.SuppressFlow ();
Assert.IsTrue (SecurityContext.IsFlowSuppressed ());
try {
SecurityContext.Run (SecurityContext.Capture (), new ContextCallback (Callback), "Hello world.");
}
finally {
afc.Undo ();
}
}
[Test]
public void SuppressFlow ()
{
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-1");
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-1");
AsyncFlowControl afc = SecurityContext.SuppressFlow ();
Assert.IsTrue (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-3");
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-3");
afc.Undo ();
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-4");
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-4");
}
[Test]
public void SuppressFlowWindowsIdentity ()
{
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-1");
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-1");
AsyncFlowControl afc = SecurityContext.SuppressFlowWindowsIdentity ();
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
afc.Undo ();
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-4");
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-4");
}
[Test]
public void SuppressFlow_Both ()
{
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-1");
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-1");
AsyncFlowControl afc = SecurityContext.SuppressFlowWindowsIdentity ();
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
AsyncFlowControl afc2 = SecurityContext.SuppressFlow ();
Assert.IsTrue (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
afc2.Undo ();
// note: afc2 Undo return to the original (not the previous) state
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void SuppressFlow_Both_Undo ()
{
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-1");
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-1");
AsyncFlowControl afc = SecurityContext.SuppressFlowWindowsIdentity ();
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
AsyncFlowControl afc2 = SecurityContext.SuppressFlow ();
Assert.IsTrue (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
Assert.IsTrue (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
afc2.Undo ();
// note: afc2 Undo return to the original (not the previous) state
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
Assert.IsFalse (SecurityContext.IsWindowsIdentityFlowSuppressed (), "IsWindowsIdentityFlowSuppressed-2");
// we can't use the first AsyncFlowControl
afc.Undo ();
}
// effects of ExecutionContext on SecurityContext
[Test]
public void ExecutionContext_SuppressFlow ()
{
Assert.IsFalse (ExecutionContext.IsFlowSuppressed (), "IsFlowSuppressed-1");
AsyncFlowControl afc = ExecutionContext.SuppressFlow ();
try {
Assert.IsTrue (ExecutionContext.IsFlowSuppressed (), "IsFlowSuppressed-2");
Assert.IsFalse (SecurityContext.IsFlowSuppressed (), "IsFlowSuppressed-3");
Assert.IsNotNull (SecurityContext.Capture (), "Capture");
}
finally {
afc.Undo ();
}
}
[Test]
public void WindowsIdentity_ ()
{
Thread.CurrentPrincipal = new WindowsPrincipal (WindowsIdentity.GetCurrent ());
SecurityContext sc = SecurityContext.Capture ();
Assert.IsNotNull (sc, "Capture");
}
}
}
#endif

View File

@@ -0,0 +1,87 @@
//
// SecurityCriticalAttributeTest.cs -
// NUnit Test Cases for SecurityCriticalAttribute
//
// 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.Security;
namespace MonoTests.System.Security {
[TestFixture]
public class SecurityCriticalAttributeTest {
#if !MOBILE
[Test]
public void Constructor_Default ()
{
SecurityCriticalAttribute sca = new SecurityCriticalAttribute ();
Assert.AreEqual (SecurityCriticalScope.Explicit, sca.Scope);
}
[Test]
public void Constructor_Scope_Everything ()
{
SecurityCriticalAttribute sca = new SecurityCriticalAttribute (SecurityCriticalScope.Everything);
Assert.AreEqual (SecurityCriticalScope.Everything, sca.Scope);
}
[Test]
public void Constructor_Scope_Explicit ()
{
SecurityCriticalAttribute sca = new SecurityCriticalAttribute (SecurityCriticalScope.Explicit);
Assert.AreEqual (SecurityCriticalScope.Explicit, sca.Scope);
}
[Test]
public void Constructor_Scope_Bad ()
{
SecurityCriticalScope scs = (SecurityCriticalScope)UInt32.MinValue;
SecurityCriticalAttribute sca = new SecurityCriticalAttribute (scs);
Assert.AreEqual (SecurityCriticalScope.Explicit, sca.Scope);
}
#endif
[Test]
public void Attributes ()
{
Type t = typeof (SecurityCriticalAttribute);
Assert.IsFalse (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsFalse (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
#if NET_4_0 && !MOBILE
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Delegate);
#else
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate);
#endif
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,436 @@
//
// SecurityExceptionCas.cs - CAS unit tests for
// System.Security.SecurityException
//
// 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.Runtime.Serialization;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System.Security {
[TestFixture]
[Category ("CAS")]
public class SecurityExceptionCas {
private SecurityException se;
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
se = new SecurityException ();
}
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void GetAction ()
{
SecurityAction sa = se.Action;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetAction ()
{
se.Action = SecurityAction.RequestRefuse;
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetDemanded_Pass ()
{
object o = se.Demanded;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetDemanded_Fail_ControlEvidence ()
{
object o = se.Demanded;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetDemanded_Fail_ControlPolicy ()
{
object o = se.Demanded;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetDemanded ()
{
se.Demanded = new PermissionSet (PermissionState.None);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetDenySetInstance_Pass ()
{
object o = se.DenySetInstance;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetDenySetInstance_Fail_ControlEvidence ()
{
object o = se.DenySetInstance;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetDenySetInstance_Fail_ControlPolicy ()
{
object o = se.DenySetInstance;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetDenySetInstance ()
{
se.DenySetInstance = new PermissionSet (PermissionState.None);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetFailedAssemblyInfo_Pass ()
{
AssemblyName an = se.FailedAssemblyInfo;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetFailedAssemblyInfo_Fail_ControlEvidence ()
{
AssemblyName an = se.FailedAssemblyInfo;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetFailedAssemblyInfo_Fail_ControlPolicy ()
{
AssemblyName an = se.FailedAssemblyInfo;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetFailedAssemblyInfo ()
{
se.FailedAssemblyInfo = null;
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetFirstPermissionThatFailed_Pass ()
{
IPermission p = se.FirstPermissionThatFailed;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetFirstPermissionThatFailed_Fail_ControlEvidence ()
{
IPermission p = se.FirstPermissionThatFailed;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetFirstPermissionThatFailed_Fail_ControlPolicy ()
{
IPermission p = se.FirstPermissionThatFailed;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetFirstPermissionThatFailed ()
{
se.FirstPermissionThatFailed = null;
}
#endif
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetGrantedSet_Pass ()
{
string s = se.GrantedSet;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetGrantedSet_Fail_ControlEvidence ()
{
string s = se.GrantedSet;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetGrantedSet_Fail_ControlPolicy ()
{
string s = se.GrantedSet;
}
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetGrantedSet ()
{
se.GrantedSet = String.Empty;
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetMethod_Pass ()
{
MethodInfo mi = se.Method;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetMethod_Fail_ControlEvidence ()
{
MethodInfo mi = se.Method;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetMethod_Fail_ControlPolicy ()
{
MethodInfo mi = se.Method;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetMethod ()
{
se.Method = null;
}
#endif
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetPermissionState_Pass ()
{
string s = se.PermissionState;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetPermissionState_Fail_ControlEvidence ()
{
string s = se.PermissionState;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetPermissionState_Fail_ControlPolicy ()
{
string s = se.PermissionState;
}
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetPermissionState ()
{
se.PermissionState = String.Empty;
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetPermitOnlySetInstance_Pass ()
{
object s = se.PermitOnlySetInstance;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetPermitOnlySetInstance_Fail_ControlEvidence ()
{
object s = se.PermitOnlySetInstance;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetPermitOnlySetInstance_Fail_ControlPolicy ()
{
object s = se.PermitOnlySetInstance;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetPermitOnlySetInstance ()
{
se.PermitOnlySetInstance = null;
}
#endif
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetRefusedSet_Pass ()
{
string s = se.RefusedSet;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetRefusedSet_Fail_ControlEvidence ()
{
string s = se.RefusedSet;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetRefusedSet_Fail_ControlPolicy ()
{
string s = se.RefusedSet;
}
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetRefusedSet ()
{
se.RefusedSet = String.Empty;
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void GetUrl_Pass ()
{
string s = se.Url;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void GetUrl_Fail_ControlEvidence ()
{
string s = se.Url;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void GetUrl_Fail_ControlPolicy ()
{
string s = se.Url;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetUrl ()
{
se.Url = "http://www.mono-project.com/";
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void GetZone ()
{
SecurityZone sz = se.Zone;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void SetZone ()
{
se.Zone = SecurityZone.Untrusted;
}
#endif
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ToString_Empty ()
{
string s = se.ToString ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ToString_WithSuppliedSensitiveInformation1 ()
{
// here we supply something *sensitive* as the state
string sensitive = "*SENSITIVE*";
SecurityException se = new SecurityException ("message", typeof (Object), sensitive);
// and we don't expect it to be shown in the output
Assert.IsTrue (se.ToString ().IndexOf (sensitive) == -1, sensitive);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true, ControlPolicy = true)]
public void ToString_WithSuppliedSensitiveInformation2 ()
{
// here we supply something *sensitive* as the state
string sensitive = "*SENSITIVE*";
SecurityException se = new SecurityException ("message", typeof (Object), sensitive);
// and we EXPECT it to be shown in the output
// as we pass the security checks for PermissionState property
Assert.IsFalse (se.ToString ().IndexOf (sensitive) == -1, sensitive);
}
[Test]
public void GetObjectData ()
{
SecurityException se = new SecurityException ("message", typeof (string), "state");
SerializationInfo info = new SerializationInfo (typeof (SecurityException), new FormatterConverter ());
se.GetObjectData (info, new StreamingContext (StreamingContextStates.All));
Assert.AreEqual ("state", info.GetValue ("PermissionState", typeof (string)), "PermissionState");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SerializationException))]
public void GetObjectData_Deny_Unrestricted ()
{
SecurityException se = new SecurityException ("message", typeof (string), "state");
SerializationInfo info = new SerializationInfo (typeof (SecurityException), new FormatterConverter ());
se.GetObjectData (info, new StreamingContext (StreamingContextStates.All));
// "PermissionState" hasn't been serialized because it's access was restricted
info.GetValue ("PermissionState", typeof (string));
}
}
}

View File

@@ -0,0 +1,90 @@
//
// SecurityExceptionTest.cs - NUnit Test Cases for SecurityException
//
// Author:
// Sebastien Pouliot (spouliot@motus.com)
//
// (C) 2004 Motus Technologies Inc. (http://www.motus.com)
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security {
[TestFixture]
public class SecurityExceptionTest {
[Test]
public void Constructor_Empty ()
{
SecurityException se = new SecurityException ();
#if ! NET_1_0
Assert.IsNull (se.GrantedSet, "GrantedSet");
Assert.IsNull (se.RefusedSet, "RefusedSet");
#endif
Assert.IsNull (se.PermissionState, "PermissionState");
Assert.IsNull (se.PermissionType, "PermissionType");
Assert.IsTrue (se.ToString ().StartsWith ("System.Security.SecurityException: "), "ToString()");
}
[Test]
public void Constructor_Message ()
{
SecurityException se = new SecurityException ("message");
#if ! NET_1_0
Assert.IsNull (se.GrantedSet, "GrantedSet");
Assert.IsNull (se.RefusedSet, "RefusedSet");
#endif
Assert.IsNull (se.PermissionState, "PermissionState");
Assert.IsNull (se.PermissionType, "PermissionType");
Assert.AreEqual ("System.Security.SecurityException: message", se.ToString (), "ToString()");
}
[Test]
public void Constructor_MessageInner ()
{
SecurityException se = new SecurityException ("message", new Exception ());
#if ! NET_1_0
Assert.IsNull (se.GrantedSet, "GrantedSet");
Assert.IsNull (se.RefusedSet, "RefusedSet");
#endif
Assert.IsNull (se.PermissionState, "PermissionState");
Assert.IsNull (se.PermissionType, "PermissionType");
Assert.IsTrue (se.ToString ().StartsWith ("System.Security.SecurityException: message"), "ToString().Starts");
Assert.IsTrue ((se.ToString ().IndexOf ("System.Exception") > 0), "ToString().Include");
}
[Test]
public void Constructor_MessageType ()
{
SecurityException se = new SecurityException ("message", typeof (EnvironmentPermission));
#if ! NET_1_0
Assert.IsNull (se.GrantedSet, "GrantedSet");
Assert.IsNull (se.RefusedSet, "RefusedSet");
#endif
Assert.IsNull (se.PermissionState, "PermissionState");
Assert.AreEqual (typeof (EnvironmentPermission), se.PermissionType, "PermissionType");
Assert.IsTrue (se.ToString ().StartsWith ("System.Security.SecurityException: message"), "ToString().Starts");
// note: can't check for PermissionType as it's not shown with MS class lib
}
[Test]
public void Constructor_MessageTypeState ()
{
SecurityException se = new SecurityException ("message", typeof (EnvironmentPermission), "mono");
Assert.IsNull (se.GrantedSet, "GrantedSet");
Assert.IsNull (se.RefusedSet, "RefusedSet");
Assert.AreEqual ("mono", se.PermissionState, "PermissionState");
Assert.AreEqual (typeof (EnvironmentPermission), se.PermissionType, "PermissionType");
#if !MOBILE
Assert.IsTrue ((se.ToString ().IndexOf ("mono") > 0), "ToString().Include(mono)");
#endif
// note: can't check for PermissionType as it's not shown with MS class lib
}
}
}

View File

@@ -0,0 +1,151 @@
//
// SecurityManagerCas.cs - CAS unit tests for System.Security.SecurityManager
//
// 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.Collections;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoCasTests.System.Security {
[TestFixture]
[Category ("CAS")]
public class SecurityManagerCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
public void IsGranted_Null ()
{
// null is always granted
Assert.IsTrue (SecurityManager.IsGranted (null));
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
[ExpectedException (typeof (SecurityException))]
public void CheckExecutionRights_DenyControlPolicy ()
{
SecurityManager.CheckExecutionRights = SecurityManager.CheckExecutionRights;
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlPolicy = true)]
public void CheckExecutionRights_PermitOnlyControlPolicy ()
{
SecurityManager.CheckExecutionRights = SecurityManager.CheckExecutionRights;
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlPolicy = true)]
#if NET_2_0
// it seems that this was removed in 2.0 - maybe because you can't turn CAS off ?!?
#else
[ExpectedException (typeof (SecurityException))]
#endif
public void SecurityEnabled_DenyControlPolicy ()
{
SecurityManager.SecurityEnabled = false;
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlPolicy = true)]
public void SecurityEnabled_PermitOnlyControlPolicy ()
{
SecurityManager.SecurityEnabled = SecurityManager.SecurityEnabled;
}
// identities permission are unrestricted since 2.0
// the Deny shows that IsGranted only checks for assembly
// granted set (and not the stack modifiers)
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void IsGranted_GacIdentityPermission ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
Assert.IsTrue (SecurityManager.IsGranted (gip));
}
#endif
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void IsGranted_ZoneIdentityPermission ()
{
ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.Internet);
#if NET_2_0
Assert.IsTrue (SecurityManager.IsGranted (zip));
#else
Assert.IsFalse (SecurityManager.IsGranted (zip));
#endif
}
[Test]
[ExpectedException (typeof (PolicyException))]
public void ResolvePolicy_Evidence_AllNull ()
{
Assert.IsTrue (SecurityManager.CheckExecutionRights, "CheckExecutionRights");
PermissionSet denied = null;
// null (2nd) is missing the Execution right
SecurityManager.ResolvePolicy (null, null, null, null, out denied);
}
[Test]
[ExpectedException (typeof (PolicyException))]
public void ResolvePolicy_Evidence_MinExec ()
{
Assert.IsTrue (SecurityManager.CheckExecutionRights, "CheckExecutionRights");
PermissionSet ps = new PermissionSet (PermissionState.None);
ps.AddPermission (new SecurityPermission (SecurityPermissionFlag.Execution));
PermissionSet denied = null;
SecurityManager.ResolvePolicy (null, ps, null, null, out denied);
// the security manager doesn't try the optional permissions to find the execution right
}
[Test]
[ExpectedException (typeof (PolicyException))]
public void ResolvePolicy_Evidence_MinNullExecOpt ()
{
Assert.IsTrue (SecurityManager.CheckExecutionRights, "CheckExecutionRights");
PermissionSet ps = new PermissionSet (PermissionState.None);
ps.AddPermission (new SecurityPermission (SecurityPermissionFlag.Execution));
PermissionSet denied = null;
// null (2nd) is missing the Execution right
SecurityManager.ResolvePolicy (null, null, ps, null, out denied);
}
}
}

View File

@@ -0,0 +1,289 @@
//
// SecurityManagerTest.cs - NUnit Test Cases for SecurityManager
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2004 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.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoTests.System.Security {
[TestFixture]
public class SecurityManagerTest {
static Evidence CurrentEvidence;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
CurrentEvidence = Assembly.GetExecutingAssembly ().Evidence;
}
[TearDown]
public void TearDown ()
{
SecurityManager.CheckExecutionRights = true;
}
[Test]
public void IsGranted_Null ()
{
// null is always granted
Assert.IsTrue (SecurityManager.IsGranted (null));
}
[Test]
#if MOBILE
[ExpectedException (typeof (NotSupportedException))]
#else
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void LoadPolicyLevelFromFile_Null ()
{
SecurityManager.LoadPolicyLevelFromFile (null, PolicyLevelType.AppDomain);
}
[Test]
#if MOBILE
[ExpectedException (typeof (NotSupportedException))]
#else
[ExpectedException (typeof (ArgumentNullException))]
#endif
public void LoadPolicyLevelFromString_Null ()
{
SecurityManager.LoadPolicyLevelFromString (null, PolicyLevelType.AppDomain);
}
[Test]
#if MOBILE
[ExpectedException (typeof (NotSupportedException))]
#endif
public void PolicyHierarchy ()
{
IEnumerator e = SecurityManager.PolicyHierarchy ();
Assert.IsNotNull (e, "PolicyHierarchy");
}
#if !MOBILE
private void ResolveEvidenceHost (SecurityZone zone, bool unrestricted, bool empty)
{
string prefix = zone.ToString () + "-";
Evidence e = new Evidence ();
e.AddHost (new Zone (zone));
PermissionSet ps = SecurityManager.ResolvePolicy (e);
// as 2.0 use Unrestricted for Identity permissions they have no need to be
// kept in resolved permission set
Assert.IsTrue ((unrestricted || (ps.Count > 0)), prefix + "Count");
Assert.AreEqual (empty, ps.IsEmpty (), prefix + "IsEmpty");
Assert.AreEqual (unrestricted, ps.IsUnrestricted (), prefix + "IsUnrestricted");
if (unrestricted)
Assert.IsNull (ps.GetPermission (typeof (ZoneIdentityPermission)), prefix + "GetPermission(ZoneIdentityPermission)");
else
Assert.IsNotNull (ps.GetPermission (typeof (ZoneIdentityPermission)), prefix + "GetPermission(ZoneIdentityPermission)");
}
[Category ("NotWorking")]
[Test]
public void ResolvePolicy_Evidence_Host_Zone ()
{
ResolveEvidenceHost (SecurityZone.Internet, false, false);
ResolveEvidenceHost (SecurityZone.Intranet, false, false);
ResolveEvidenceHost (SecurityZone.MyComputer, true, false);
ResolveEvidenceHost (SecurityZone.Trusted, false, false);
ResolveEvidenceHost (SecurityZone.Untrusted, false, false);
ResolveEvidenceHost (SecurityZone.NoZone, false, true);
}
private void ResolveEvidenceAssembly (SecurityZone zone)
{
string prefix = zone.ToString () + "-";
Evidence e = new Evidence ();
e.AddAssembly (new Zone (zone));
PermissionSet ps = SecurityManager.ResolvePolicy (e);
Assert.AreEqual (0, ps.Count, prefix + "Count");
Assert.IsTrue (ps.IsEmpty (), prefix + "IsEmpty");
Assert.IsFalse (ps.IsUnrestricted (), prefix + "IsUnrestricted");
}
[Test]
public void ResolvePolicy_Evidence_Assembly_Zone ()
{
ResolveEvidenceAssembly (SecurityZone.Internet);
ResolveEvidenceAssembly (SecurityZone.Intranet);
ResolveEvidenceAssembly (SecurityZone.MyComputer);
ResolveEvidenceAssembly (SecurityZone.Trusted);
ResolveEvidenceAssembly (SecurityZone.Untrusted);
ResolveEvidenceAssembly (SecurityZone.NoZone);
}
[Test]
public void ResolvePolicy_Evidence_Null ()
{
Evidence e = null;
PermissionSet ps = SecurityManager.ResolvePolicy (e);
// no exception thrown
Assert.IsNotNull (ps);
Assert.IsFalse (ps.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void ResolvePolicy_Evidence_CurrentAssembly ()
{
PermissionSet granted = SecurityManager.ResolvePolicy (CurrentEvidence);
Assert.IsNotNull (granted);
Assert.IsTrue (granted.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void ResolvePolicy_Evidences_Null ()
{
Evidence[] e = null;
PermissionSet ps = SecurityManager.ResolvePolicy (e);
// no exception thrown
Assert.IsNotNull (ps);
Assert.IsFalse (ps.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void ResolvePolicy_Evidence_AllNull_NoExecution ()
{
PermissionSet denied = null;
SecurityManager.CheckExecutionRights = false;
PermissionSet granted = SecurityManager.ResolvePolicy (null, null, null, null, out denied);
Assert.IsNull (denied, "Denied");
Assert.AreEqual (0, granted.Count, "Granted.Count");
Assert.IsFalse (granted.IsUnrestricted (), "!Granted.IsUnrestricted");
}
[Test]
public void ResolvePolicy_Evidence_NullRequests_CurrentAssembly ()
{
PermissionSet denied = null;
PermissionSet granted = SecurityManager.ResolvePolicy (CurrentEvidence, null, null, null, out denied);
Assert.IsNull (denied, "Denied");
Assert.IsTrue (granted.IsUnrestricted (), "Granted.IsUnrestricted");
}
[Test]
[ExpectedException (typeof (PolicyException))]
[Category ("NotWorking")]
public void ResolvePolicy_Evidence_DenyUnrestricted_CurrentAssembly ()
{
PermissionSet deny = new PermissionSet (PermissionState.Unrestricted);
PermissionSet denied = null;
PermissionSet granted = SecurityManager.ResolvePolicy (CurrentEvidence, null, null, deny, out denied);
}
[Test]
[Category ("NotDotNet")] // MS bug - throws a NullReferenceException
public void ResolvePolicy_Evidence_DenyUnrestricted_NoExecution ()
{
PermissionSet deny = new PermissionSet (PermissionState.Unrestricted);
PermissionSet denied = null;
SecurityManager.CheckExecutionRights = false;
PermissionSet granted = SecurityManager.ResolvePolicy (CurrentEvidence, null, null, deny, out denied);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ResolvePolicyGroups_Null ()
{
IEnumerator e = SecurityManager.ResolvePolicyGroups (null);
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void SavePolicyLevel_Null ()
{
SecurityManager.SavePolicyLevel (null);
}
[Test]
[ExpectedException (typeof (PolicyException))]
public void SavePolicyLevel_AppDomain ()
{
PolicyLevel adl = PolicyLevel.CreateAppDomainLevel ();
SecurityManager.SavePolicyLevel (adl);
}
[Test]
public void GetZoneAndOrigin ()
{
ArrayList zone = null;
ArrayList origin = null;
SecurityManager.GetZoneAndOrigin (out zone, out origin);
Assert.IsNotNull (zone, "Zone");
Assert.AreEqual (0, zone.Count, "Zone.Count");
Assert.IsNotNull (origin, "Origin");
Assert.AreEqual (0, origin.Count, "Origin.Count");
}
[Test]
public void ResolvePolicy_Evidence_ArrayNull ()
{
Evidence[] e = null;
PermissionSet ps = SecurityManager.ResolvePolicy (e);
Assert.IsNotNull (ps, "PermissionSet");
Assert.IsFalse (ps.IsUnrestricted (), "IsUnrestricted");
Assert.AreEqual (0, ps.Count, "Count");
}
[Test]
public void ResolvePolicy_Evidence_ArrayEmpty ()
{
Evidence[] e = new Evidence [0];
PermissionSet ps = SecurityManager.ResolvePolicy (e);
Assert.IsNotNull (ps, "PermissionSet");
Assert.IsFalse (ps.IsUnrestricted (), "IsUnrestricted");
Assert.AreEqual (0, ps.Count, "Count");
}
[Test]
public void ResolvePolicy_Evidence_Array ()
{
Evidence[] e = new Evidence[] { new Evidence () };
PermissionSet ps = SecurityManager.ResolvePolicy (e);
Assert.IsNotNull (ps, "PermissionSet");
Assert.IsFalse (ps.IsUnrestricted (), "IsUnrestricted");
Assert.AreEqual (0, ps.Count, "Count");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
[Category ("NotWorking")]
public void ResolveSystemPolicy_Null ()
{
SecurityManager.ResolveSystemPolicy (null);
}
#endif
}
}

View File

@@ -0,0 +1,58 @@
//
// SecurityStateTest.cs - NUnit Test Cases for SecurityState
//
// Author:
// Sebastien Pouliot (sebastien@ximian.com)
//
// Copyright (C) 2009 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 System;
using System.Security;
using NUnit.Framework;
namespace MonoTests.System.Security {
[TestFixture]
public class SecurityStateTest {
class ContreteSecurityState : SecurityState {
public override void EnsureState ()
{
throw new NotImplementedException ();
}
}
[Test]
public void Defaults ()
{
ContreteSecurityState ss = new ContreteSecurityState ();
Assert.IsFalse (ss.IsStateAvailable (), "IsStateAvailable");
}
}
}
#endif

View File

@@ -0,0 +1,57 @@
//
// SecurityTransparentAttributeTest.cs -
// NUnit Test Cases for SecurityTransparentAttribute
//
// 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;
namespace MonoTests.System.Security {
[TestFixture]
public class SecurityTransparentAttributeTest {
[Test]
public void Attributes ()
{
Type t = typeof (SecurityTransparentAttribute);
Assert.IsFalse (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsFalse (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
Assert.AreEqual (AttributeTargets.Assembly, aua.ValidOn, "ValidOn");
}
}
}
#endif