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,330 @@
2009-06-24 Zoltan Varga <vargaz@gmail.com>
* *.cs: Convert all tests to new-style nunit classes/methods.
2006-08-21 Sebastien Pouliot <sebastien@ximian.com>
* FileIOPermissionTest.cs: Added new test cases for union (#79118) and
subpath handling.
2006-04-07 Sebastien Pouliot <sebastien@ximian.com>
* FileIOPermissionTest.cs: Adjust test cases for wildcards (like *)
that are valid in filenames under UNIX.
2005-09-22 Sebastien Pouliot <sebastien@ximian.com>
* CodeAccessSecurityAttributeTest.cs,
EnvironmentPermissionAttributeTest.cs,
FileDialogPermissionAttributeTest.cs,
FileIOPermissionAttributeTest.cs,
GacIdentityPermissionAttributeTest.cs,
HostProtectionAttributeTest.cs,
IsolatedStorageFilePermissionAttributeTest.cs,
IsolatedStoragePermissionAttributeTest.cs,
KeyContainerPermissionAttributeTest.cs,
PermissionSetAttributeTest.cs, PrincipalPermissionAttributeTest.cs,
PublisherIdentityPermissionAttributeTest.cs,
ReflectionPermissionAttributeTest.cs,
RegistryPermissionAttributeTest.cs, SecurityAttributeTest.cs,
SecurityPermissionAttributeTest.cs,
SiteIdentityPermissionAttributeTest.cs,
StrongNameIdentityPermissionAttributeTest.cs,
UIPermissionAttributeTest.cs, UrlIdentityPermissionAttributeTest.cs,
ZoneIdentityPermissionAttributeTest.cs: Removed *Choice security
actions.
2005-06-16 Sebastien Pouliot <sebastien@ximian.com>
* PrincipalPermissionTest.cs: Added more tests for IsSubsetOf method.
2005-05-18 Sebastien Pouliot <sebastien@ximian.com>
* HostProtectionAttributeTest.cs: Added tests to check for individual
removal of flags.
* SecurityPermissionAttributeTest.cs: Added tests to check for
individual removal of flags.
2005-04-27 Sebastien Pouliot <sebastien@ximian.com>
* IBuiltInPermissionTest.cs: Fixed token index numbers wrt beta2.
* IsolatedStorageFilePermissionTest.cs: Change containment to match
beta2.
* UrlIdentityPermissionTest.cs: Fixed test case for 2.0.
* ZoneIdentityPermissionAttributeTest.cs: Tag unrestricted test as
NotWorking.
2005-03-31 Sebastien Pouliot <sebastien@ximian.com>
* FileIOPermissionTest.cs: Added a test case for a filename starting
with the "file://" scheme (which isn't valid).
2005-02-24 Sebastien Pouliot <sebastien@ximian.com>
* StrongNameIdentityPermissionTest.cs: Fixed some bad tests and
re-enabled the tests on NET_2_0 profile.
2005-01-08 Sebastien Pouliot <sebastien@ximian.com>
* PermissionSetAttributeTest.cs: Added unit tests for Hex property.
2005-01-06 Sebastien Pouliot <sebastien@ximian.com>
* PublisherIdentityPermissionTest.cs: Fixed tests for NET_1_1 profile.
* SiteIdentityPermissionTest.cs: Fixed tests for NET_1_1 profile.
* StrongNameIdentityPermissionTest.cs: Fixed tests for NET_1_1 profile.
* UrlIdentityPermissionTest.cs: Fixed tests for NET_1_1 profile.
2005-01-05 Sebastien Pouliot <sebastien@ximian.com>
* DataProtectionPermissionAttributeTest.cs: Moving to System.Security.
2005-01-04 Sebastien Pouliot <sebastien@ximian.com>
* GacIdentityPermissionTest.cs, IBuiltInPermissionTest.cs,
PublisherIdentityPermissionAttributeTest.cs,
PublisherIdentityPermissionTest.cs,
SiteIdentityPermissionAttributeTest.cs, SiteIdentityPermissionTest.cs,
StrongNameIdentityPermissionAttributeTest.cs,
StrongNameIdentityPermissionTest.cs,
UrlIdentityPermissionAttributeTest.cs, UrlIdentityPermissionTest.cs,
ZoneIdentityPermissionTest.cs: Adjusted unit tests so they now execute
without errors on 2.0 Dec CTP.
2004-10-15 Sebastien Pouliot <sebastien@ximian.com>
* PrincipalPermissionTest.cs: Added two new tests to check for nulls
during intersection.
2004-09-04 Sebastien Pouliot <sebastien@ximian.com>
* FileIOPermissionAttributeTest.cs: Added a new test to check that the
attribute class accept (and retains) non-c14n filenames while the
permission class accept, but c14n, filenames. Fixed other tests that
didn't check for c14n results from the created permission.
2004-09-03 Sebastien Pouliot <sebastien@ximian.com>
* RegistryPermissionTest.cs: New. Unit tests for RegistryPermission.
Added tests for subsets on keys (as this is valid).
* UrlIdentityPermissionTest.cs: Added a test for Copy an empty object
which results in a different behaviour in Fx 1.1 and 2.0.
2004-09-01 Sebastien Pouliot <sebastien@ximian.com>
* EnvironmentPermissionTest.cs: Fixed tests so they execute without
errors on both Fx 1.1 and Fx 2.0 (beta 1).
* PublisherIdentityPermissionTest.cs: Fixed tests so they execute
without errors on both Fx 1.1 and Fx 2.0 (beta 1).
* SiteIdentityPermissionTest.cs: Fixed tests so they execute without
errors on both Fx 1.1 and Fx 2.0 (beta 1). Fixed line endings.
* StrongNameIdentityPermissionTest.cs: Fixed tests so they execute
without errors on both Fx 1.1 and Fx 2.0 (beta 1).
* StrongNamePublicKeyBlobTest.cs: Fixed tests so they execute without
errors on both Fx 1.1 and Fx 2.0 (beta 1). Converted tests to NUnit
2.2 format.
* UrlIdentityPermissionTest.cs: Fixed tests so they execute without
errors on both Fx 1.1 and Fx 2.0 (beta 1).
2004-09-01 Sebastien Pouliot <sebastien@ximian.com>
* ZoneIdentityPermissionTest.cs: Ensure we aren't encoding NoZone in
the permission XML (ToXml).
2003-08-20 Sebastien Pouliot <sebastien@ximian.com>
* CodeAccessSecurityAttributeTest.cs: New unit tests for abstract
class CodeAccessSecurityAttribute.
* DataProtectionPermissionAttributeTest.cs: New unit tests for Fx 2.0
DataProtectionPermissionAttribute class.
* HostProtectionAttributeTest.cs: New unit tests for Fx 2.0
HostProtectionAttribute class.
* IsolatedStoragePermissionAttributeTest.cs: New unit tests for
abstract class IsolatedStoragePermissionAttribute.
* KeyContainerPermissionAttributeTest.cs: New unit tests for Fx 2.0
KeyContainerPermissionAttribute class.
* SecurityAttributeTest.cs: New unit tests for abstract class
SecurityAttribute.
* SiteIdentityPermissionTest.cs: New unit tests for
SiteIdentityPermission. Lacks tests for wilcards.
* UrlIdentityPermissionTest.cs: New unit tests for
UrlIdentityPermission. Lacks tests for wilcards.
2003-08-19 Sebastien Pouliot <sebastien@ximian.com>
* EnvironmentPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format. Fixed small
behaviour difference with Fx 2.0.
* FileDialogPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format.
* FileIOPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format. Added tests
for new Fx 2.0 properties.
* PermissionSetAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format. Added tests
for new Fx 2.0 properties.
* PrincipalPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format.
* PublisherIdentityPermissionAttributeTest.cs: Added tests to check
class's attributes. Converted existing tests to NUnit 2.2 format.
* ReflectionPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format.
* RegistryPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format. Added tests
for new Fx 2.0 properties.
* SecurityPermissionAttributeTest.cs: Removed unrequired line.
* SiteIdentityPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format.
* StrongNameIdentityPermissionAttributeTest.cs: Removed unrequired line.
* UIPermissionAttributeTest.cs: Removed unrequired line.
* UrlIdentityPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format.
* ZoneIdentityPermissionAttributeTest.cs: Removed unrequired line.
2003-08-19 Sebastien Pouliot <sebastien@ximian.com>
* SecurityPermissionAttributeTest.cs: Added unit tests for invalid
SecurityAction, Flags effects and custom attributes. Converted
existing tests to NUnit 2.2 format.
* SecurityPermissionTest.cs: New. Unit tests for SecurityPermission.
2003-08-18 Sebastien Pouliot <sebastien@ximian.com>
* IsolatedStorageFilePermissionAttributeTest.cs: Added tests to check
class's attributes. Converted existing tests to NUnit 2.2 format.
* IsolatedStorageFilePermissionTest.cs: New. Unit tests for
IsolatedStorageFilePermission.
* GacIdentityPermissionAttributeTest.cs: New unit tests for
GacIdentityPermissionAttribute (NET_2_0).
* GacIdentityPermissionTest.cs: New unit tests for
GacIdentityPermission (NET_2_0).
* StrongNameIdentityPermissionAttributeTest.cs: Added tests to
check class's attributes.
* UIPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format.
* ZoneIdentityPermissionAttributeTest.cs: Added tests to check class's
attributes. Converted existing tests to NUnit 2.2 format.
2003-08-17 Sebastien Pouliot <sebastien@ximian.com>
* IBuiltInPermissionTest.cs: New. Unit tests to check the result of
the "somewhat undocumented" IBuiltInPermission.GetTokenIndex on all
permissions inside corlib.
* StrongNameIdentityPermissionTest.cs: New. Unit tests for
StrongNameIdentityPermission.
* StrongNameIdentityPermissionAttributeTest.cs: Added unit test to
check the behavior of using an invalid SecurityAction. Added tests
for CreatePermission. Converted existing tests to NUnit 2.2 format.
* UIPermissionTest.cs: New. Unit tests for UIPermission.
* UIPermissionAttributeTest.cs: Added unit tests to check the behavior
of using invalid enums for properties (no checks).
* ZoneIdentityPermissionAttributeTest.cs: Added unit tests to check
the behavior of using invliad enums for properties (no checks).
* ZoneIdentityPermissionTest.cs: Added new unit tests for XML decoding.
2003-08-04 Sebastien Pouliot <sebastien@ximian.com>
* ZoneIdentityPermissionTest.cs: Added tests to check that NoZone is a
subset of every SecurityZone.
2003-08-03 Sebastien Pouliot <sebastien@ximian.com>
* ZoneIdentityPermissionTest.cs: New. NUnit 2.2 format.
2003-05-20 Sebastien Pouliot <sebastien@ximian.com>
* PublisherIdentityPermissionTest.cs: SetUp is now public (required
for new nunit).
2004-01-27 Sebastien Pouliot <spouliot@videotron.ca>
* FileIOPermissionTest.cs: Converted to NUnit2. Added a test to show a
strange behaviour (short/long path) - ignored for now.
* FileIOPermissionAttributeTest.cs: Removed GetTempPath from the tests
as the introduced failures weren't related to the class (test moved to
FileIOPermissionTest.cs).
2003-12-29 Sebastien Pouliot <spouliot@videotron.ca>
* EnvironmentPermissionAttributeTest.cs: Updated to test default
properties, Actions, get for All (1.1) and Unrestricted.
* FileDialogPermissionAttributeTest.cs: Updated to test default
properties, Actions and Unrestricted.
* FileIOPermissionAttributeTest.cs: Updated to test default
properties, Actions, get for All (1.1) and Unrestricted.
* IsolatedStorageFilePermissionAttributeTest.cs: New.
* PermissionSetAttributeTest.cs: New.
* PrincipalPermissionAttributeTest.cs: Updated to test default
properties, Actions and Unrestricted.
* PublisherIdentityPermissionAttributeTest.cs: Updated to test default
properties, Actions and Unrestricted.
* ReflectionPermissionAttributeTest.cs: Updated to test default
properties, Actions and Unrestricted.
* RegistryPermissionAttributeTest.cs: New.
* SecurityPermissionAttributeTest.cs: New.
* SiteIdentityPermissionAttributeTest.cs: New.
* StrongNameIdentityPermissionAttributeTest.cs: New.
* StrongNamePublicKeyBlobTest.cs: Converted to NUnit2 format.
* UIPermissionAttributeTest.cs: New.
* UrlIdentityPermissionAttributeTest.cs: New.
* ZoneIdentityPermissionAttributeTest.cs: New.
2003-10-21 Nick Drochak <ndrochak@gol.com>
* FileIOPermissionAttributeTest.cs: Handle Short File Name vs. Long
File Name messiness. This probably needs to be worked on for the
tests to work on Linux, etc.
2003-07-01 Sebastien Pouliot <spouliot@videotron.ca>
* PrincipalPermissionAttributeTest.cs: New.
* PrincipalPermissionTest.cs: New.
2003-06-29 Sebastien Pouliot <spouliot@videotron.ca>
* ReflectionPermissionAttributeTest.cs: New.
* ReflectionPermissionTest.cs: New.
2003-06-29 Nick Drochak <ndrochak@gol.com>
* FileIOPermissionAttributeTest.cs: Don't use windows path name.
2003-06-28 Sebastien Pouliot <spouliot@videotron.ca>
* EnvironmentPermissionAttributeTest.cs: New.
* EnvironmentPermissionTest.cs: New.
* FileDialogPermissionAttributeTest.cs: New.
* FileDialogPermissionTest.cs: New.
* FileIOPermissionAttributeTest.cs: New.
* PublisherIdentityPermissionAttributeTest.cs: New.
* PublisherIdentityPermissionTest.cs: New.
2002-12-21 Nick Drochak <ndrochak@gol.com>
* all: make tests build and run under nunit2
2002-12-16 Sebastien Pouliot <spouliot@videotron.ca>
AllTests.cs: Added StrongNamePublicKeyBlobTest suite.
StrongNamePublicKeyBlobTest.cs: New. Test suite for
StrongNamePublicKeyBlob.
2002-06-18 Nick Drochak <ndrochak@gol.com>
* FileIOPermissionTest.cs: Use Unix paths if it looks like we are not
running the tests on Windows. Need to expand this when we run the
tests on Mac OS's (and others I suppose). Also consolidated some
redundant code.
2002-02-09 Nick Drochak <ndrochak@gol.com>
* FileIOPermissionTest.cs: Remove intersect test where it was trying
to intersect a permission with itself. This throws an exception
with mscorlib.
2002-01-14 Nick Drochak <ndrochak@gol.com>
* FileIOPermissionTest.cs: New File.
* AllTests.cs: New File.

View File

@@ -0,0 +1,114 @@
//
// CodeAccessSecurityAttributeTest.cs -
// NUnit Test Cases for CodeAccessSecurityAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
// note: CodeAccessSecurityAttribute is abstract so we define our own to test
// no [Serialize] or [AttributeUsage] here to test their inheritance
public class NonAbstractCodeAccessSecurityAttribute : CodeAccessSecurityAttribute {
public NonAbstractCodeAccessSecurityAttribute (SecurityAction action)
: base (action)
{
}
public override IPermission CreatePermission ()
{
return null;
}
}
[TestFixture]
public class CodeAccessSecurityAttributeTest {
[Test]
public void Action ()
{
NonAbstractCodeAccessSecurityAttribute a = new NonAbstractCodeAccessSecurityAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
NonAbstractCodeAccessSecurityAttribute a = new NonAbstractCodeAccessSecurityAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void Unrestricted ()
{
NonAbstractCodeAccessSecurityAttribute a = new NonAbstractCodeAccessSecurityAttribute (SecurityAction.Assert);
Assert.IsFalse (a.Unrestricted, "Unrestricted (default)");
a.Unrestricted = true;
Assert.IsTrue (a.Unrestricted, "Unrestricted (true)");
a.Unrestricted = false;
Assert.IsFalse (a.Unrestricted, "Unrestricted (false)");
}
[Test]
public void Attributes ()
{
Type t = typeof (NonAbstractCodeAccessSecurityAttribute);
Assert.IsFalse (t.IsSerializable, "IsSerializable");
object[] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (0, attrs.Length, "AttributeUsage-false");
attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), true);
Assert.AreEqual (1, attrs.Length, "AttributeUsage-true");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,175 @@
//
// EnvironmentPermissionAttributeTest.cs -
// NUnit Test Cases for EnvironmentPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
#if MOBILE
[Ignore]
#endif
public class EnvironmentPermissionAttributeTest {
private static string envar = "TMP";
[Test]
public void Default ()
{
EnvironmentPermissionAttribute a = new EnvironmentPermissionAttribute (SecurityAction.Assert);
Assert.IsNull (a.Read, "Read");
Assert.IsNull (a.Write, "Write");
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
EnvironmentPermission p = (EnvironmentPermission) a.CreatePermission ();
#if NET_2_0
Assert.AreEqual (String.Empty, p.GetPathList (EnvironmentPermissionAccess.Read), "GetPathList(Read)");
Assert.AreEqual (String.Empty, p.GetPathList (EnvironmentPermissionAccess.Write), "GetPathList(Write)");
#else
Assert.IsNull (p.GetPathList (EnvironmentPermissionAccess.Read), "GetPathList(Read)");
Assert.IsNull (p.GetPathList (EnvironmentPermissionAccess.Write), "GetPathList(Write)");
#endif
Assert.IsFalse (p.IsUnrestricted (), "CreatePermission-IsUnrestricted");
}
[Test]
public void Action ()
{
EnvironmentPermissionAttribute a = new EnvironmentPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
EnvironmentPermissionAttribute a = new EnvironmentPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void All ()
{
EnvironmentPermissionAttribute attr = new EnvironmentPermissionAttribute (SecurityAction.Assert);
attr.All = envar;
Assert.AreEqual (envar, attr.Read, "All=Read");
Assert.AreEqual (envar, attr.Write, "All=Write");
EnvironmentPermission p = (EnvironmentPermission) attr.CreatePermission ();
Assert.AreEqual (envar, p.GetPathList (EnvironmentPermissionAccess.Read), "All=EnvironmentPermission-Read");
Assert.AreEqual (envar, p.GetPathList (EnvironmentPermissionAccess.Write), "All=EnvironmentPermission-Write");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void All_Get ()
{
EnvironmentPermissionAttribute attr = new EnvironmentPermissionAttribute (SecurityAction.Assert);
string s = attr.All;
}
[Test]
public void Read ()
{
EnvironmentPermissionAttribute attr = new EnvironmentPermissionAttribute (SecurityAction.Assert);
attr.Read = envar;
Assert.AreEqual (envar, attr.Read, "Read=Read");
Assert.IsNull (attr.Write, "Write=null");
EnvironmentPermission p = (EnvironmentPermission) attr.CreatePermission ();
Assert.AreEqual (envar, p.GetPathList (EnvironmentPermissionAccess.Read), "Read=EnvironmentPermission-Read");
#if NET_2_0
Assert.AreEqual (String.Empty, p.GetPathList (EnvironmentPermissionAccess.Write), "Read=EnvironmentPermission-Write");
#else
Assert.IsNull (p.GetPathList (EnvironmentPermissionAccess.Write), "Read=EnvironmentPermission-Write");
#endif
}
[Test]
public void Write ()
{
EnvironmentPermissionAttribute attr = new EnvironmentPermissionAttribute (SecurityAction.Assert);
attr.Write = envar;
Assert.IsNull (attr.Read, "Read=null");
Assert.AreEqual (envar, attr.Write, "Write=Write");
EnvironmentPermission p = (EnvironmentPermission) attr.CreatePermission ();
#if NET_2_0
Assert.AreEqual (String.Empty, p.GetPathList (EnvironmentPermissionAccess.Read), "Write=EnvironmentPermission-Read");
#else
Assert.IsNull (p.GetPathList (EnvironmentPermissionAccess.Read), "Write=EnvironmentPermission-Read");
#endif
Assert.AreEqual (envar, p.GetPathList (EnvironmentPermissionAccess.Write), "Write=EnvironmentPermission-Write");
}
[Test]
public void Unrestricted ()
{
EnvironmentPermissionAttribute a = new EnvironmentPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
EnvironmentPermission perm = (EnvironmentPermission) a.CreatePermission ();
Assert.IsTrue (perm.IsUnrestricted (), "CreatePermission.IsUnrestricted");
Assert.AreEqual (String.Empty, perm.GetPathList (EnvironmentPermissionAccess.Read), "GetPathList(Read)");
Assert.AreEqual (String.Empty, perm.GetPathList (EnvironmentPermissionAccess.Write), "GetPathList(Write)");
}
[Test]
public void Attributes ()
{
EnvironmentPermissionAttribute a = new EnvironmentPermissionAttribute (SecurityAction.Assert);
Type t = typeof (EnvironmentPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,361 @@
//
// EnvironmentPermissionTest.cs - NUnit Test Cases for EnvironmentPermission
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
#if MOBILE
[Ignore]
#endif
public class EnvironmentPermissionTest {
private static string className = "System.Security.Permissions.EnvironmentPermission, ";
private static string envVariables = "TMP;TEMP";
[Test]
public void PermissionStateNone ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.None)");
Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted");
EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
SecurityElement se = ep.ToXml ();
Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class");
Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version");
}
[Test]
public void PermissionStateUnrestricted ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted);
Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.Unrestricted)");
Assert.IsTrue (ep.IsUnrestricted (), "IsUnrestricted");
EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
SecurityElement se = ep.ToXml ();
Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void NullPathList ()
{
EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.AllAccess, null);
}
[Test]
public void AllAccess ()
{
EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.AllAccess, envVariables);
Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void NoAccess ()
{
EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.NoAccess, envVariables);
Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void ReadAccess ()
{
EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void WriteAccess ()
{
EnvironmentPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.Write, envVariables);
Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void AddPathList ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
ep.AddPathList (EnvironmentPermissionAccess.AllAccess, envVariables);
// LAMESPEC NoAccess do not remove the TMP from AllAccess
ep.AddPathList (EnvironmentPermissionAccess.NoAccess, "TMP");
ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
SecurityElement se = ep.ToXml ();
// Note: Debugger can mess results (try to run without stepping)
Assert.AreEqual ("TMP;TEMP;UID", (se.Attributes ["Read"] as string), "AddPathList-ToXml-Read");
Assert.AreEqual ("TMP;TEMP;PROMPT", (se.Attributes ["Write"] as string), "AddPathList-ToXml-Write");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetPathListAllAccess ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
Assert.AreEqual ("", ep.GetPathList (EnvironmentPermissionAccess.AllAccess), "GetPathList-AllAccess");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetPathListNoAccess ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
Assert.AreEqual ("", ep.GetPathList (EnvironmentPermissionAccess.NoAccess), "GetPathList-NoAccess");
}
[Test]
public void GetPathList ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
#if NET_2_0
Assert.AreEqual (String.Empty, ep.GetPathList (EnvironmentPermissionAccess.Read), "GetPathList-Read-Empty");
Assert.AreEqual (String.Empty, ep.GetPathList (EnvironmentPermissionAccess.Write), "GetPathList-Write-Empty");
#else
Assert.IsNull (ep.GetPathList (EnvironmentPermissionAccess.Read), "GetPathList-Read-Empty");
Assert.IsNull (ep.GetPathList (EnvironmentPermissionAccess.Write), "GetPathList-Write-Empty");
#endif
ep.AddPathList (EnvironmentPermissionAccess.Read, "UID");
ep.AddPathList (EnvironmentPermissionAccess.Write, "PROMPT");
Assert.AreEqual ("UID", ep.GetPathList (EnvironmentPermissionAccess.Read), "GetPathList-Read");
Assert.AreEqual ("PROMPT", ep.GetPathList (EnvironmentPermissionAccess.Write), "GetPathList-Write");
}
[Test]
public void SetPathList ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
ep.SetPathList (EnvironmentPermissionAccess.AllAccess, envVariables);
// LAMESPEC NoAccess do not remove the TMP from AllAccess
ep.SetPathList (EnvironmentPermissionAccess.NoAccess, "SYSTEMROOT");
ep.SetPathList (EnvironmentPermissionAccess.Read, "UID");
ep.SetPathList (EnvironmentPermissionAccess.Write, "PROMPT");
SecurityElement se = ep.ToXml ();
Assert.AreEqual ("UID", (se.Attributes ["Read"] as string), "SetPathList-ToXml-Read");
Assert.AreEqual ("PROMPT", (se.Attributes ["Write"] as string), "SetPathList-ToXml-Write");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXmlNull ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
ep.FromXml (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXmlInvalidPermission ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
SecurityElement se = ep.ToXml ();
// can't modify - so we create our own
SecurityElement se2 = new SecurityElement ("IInvalidPermission", se.Text);
se2.AddAttribute ("class", se.Attribute ("class"));
se2.AddAttribute ("version", se.Attribute ("version"));
ep.FromXml (se2);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXmlWrongVersion ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
SecurityElement se = ep.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");
ep.FromXml (se2);
}
#if NET_2_0
[Category ("NotWorking")]
#endif
[Test]
public void FromXml ()
{
EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
SecurityElement se = ep.ToXml ();
Assert.IsNotNull (se, "ToXml()");
ep.FromXml (se);
se.AddAttribute ("Read", envVariables);
ep.FromXml (se);
Assert.AreEqual (envVariables, ep.GetPathList (EnvironmentPermissionAccess.Read), "FromXml-Read");
se.AddAttribute ("Write", envVariables);
ep.FromXml (se);
Assert.AreEqual (envVariables, ep.GetPathList (EnvironmentPermissionAccess.Read), "FromXml-Read");
Assert.AreEqual (envVariables, ep.GetPathList (EnvironmentPermissionAccess.Write), "FromXml-Write");
}
[Test]
public void UnionWithNull ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
EnvironmentPermission ep2 = null;
EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Union (ep2);
Assert.AreEqual (ep1.ToXml ().ToString (), ep3.ToXml ().ToString (), "EP1 U null == EP1");
}
[Test]
public void UnionWithUnrestricted ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (PermissionState.Unrestricted);
EnvironmentPermission ep2 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Union (ep2);
Assert.IsTrue (ep3.IsUnrestricted (), "Unrestricted U EP2 == Unrestricted");
ep3 = (EnvironmentPermission) ep2.Union (ep1);
Assert.IsTrue (ep3.IsUnrestricted (), "EP2 U Unrestricted == Unrestricted");
}
#if NET_2_0
[Category ("NotWorking")]
#endif
[Test]
public void Union ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
EnvironmentPermission ep2 = new EnvironmentPermission (EnvironmentPermissionAccess.Write, envVariables);
EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Union (ep2);
EnvironmentPermission ep4 = new EnvironmentPermission (EnvironmentPermissionAccess.AllAccess, envVariables);
Assert.AreEqual (ep3.ToXml ().ToString (), ep4.ToXml ().ToString (), "EP1 U EP2 == EP1+2");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void UnionWithBadPermission ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted);
EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Union (fdp2);
}
[Test]
public void IntersectWithNull ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
EnvironmentPermission ep2 = null;
EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Intersect (ep2);
Assert.IsNull (ep3, "EP1 N null == null");
}
[Test]
public void IntersectWithUnrestricted ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (PermissionState.Unrestricted);
EnvironmentPermission ep2 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Intersect (ep2);
Assert.IsTrue (!ep3.IsUnrestricted (), "Unrestricted N EP2 == EP2");
Assert.AreEqual (ep2.ToXml ().ToString (), ep3.ToXml ().ToString (), "Unrestricted N EP2 == EP2");
ep3 = (EnvironmentPermission) ep2.Intersect (ep1);
Assert.IsTrue (!ep3.IsUnrestricted (), "EP2 N Unrestricted == EP2");
Assert.AreEqual (ep2.ToXml ().ToString (), ep3.ToXml ().ToString (), "EP2 N Unrestricted == EP2");
}
[Test]
public void Intersect ()
{
// no intersection
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Write, envVariables);
EnvironmentPermission ep2 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Intersect (ep2);
Assert.IsNull (ep3, "EP1 N EP2 == null");
// intersection in read
EnvironmentPermission ep4 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, "TMP");
ep3 = (EnvironmentPermission) ep4.Intersect (ep2);
Assert.AreEqual ("TMP", ep3.GetPathList (EnvironmentPermissionAccess.Read), "Intersect-Read");
// intersection in write
EnvironmentPermission ep5 = new EnvironmentPermission (EnvironmentPermissionAccess.Write, "TEMP");
ep3 = (EnvironmentPermission) ep5.Intersect (ep1);
Assert.AreEqual ("TEMP", ep3.GetPathList (EnvironmentPermissionAccess.Write), "Intersect-Read");
// intersection in read and write
EnvironmentPermission ep6 = new EnvironmentPermission (EnvironmentPermissionAccess.AllAccess, "TEMP");
EnvironmentPermission ep7 = new EnvironmentPermission (EnvironmentPermissionAccess.AllAccess, envVariables);
ep3 = (EnvironmentPermission) ep6.Intersect (ep7);
Assert.AreEqual ("TEMP", ep3.GetPathList (EnvironmentPermissionAccess.Read), "Intersect-AllAccess-Read");
Assert.AreEqual ("TEMP", ep3.GetPathList (EnvironmentPermissionAccess.Write), "Intersect-AllAccess-Write");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IntersectWithBadPermission ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted);
EnvironmentPermission ep3 = (EnvironmentPermission) ep1.Intersect (fdp2);
}
[Test]
public void IsSubsetOfNull ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
Assert.IsTrue (!ep1.IsSubsetOf (null), "IsSubsetOf(null)");
}
[Test]
public void IsSubsetOfUnrestricted ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (PermissionState.Unrestricted);
EnvironmentPermission ep2 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
EnvironmentPermission ep3 = new EnvironmentPermission (PermissionState.Unrestricted);
Assert.IsTrue (!ep1.IsSubsetOf (ep2), "Unrestricted.IsSubsetOf()");
Assert.IsTrue (ep2.IsSubsetOf (ep1), "IsSubsetOf(Unrestricted)");
Assert.IsTrue (ep1.IsSubsetOf (ep3), "Unrestricted.IsSubsetOf(Unrestricted)");
}
[Test]
public void IsSubsetOf ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Write, envVariables);
EnvironmentPermission ep2 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
Assert.IsTrue (!ep1.IsSubsetOf (ep2), "IsSubsetOf(nosubset1)");
Assert.IsTrue (!ep2.IsSubsetOf (ep1), "IsSubsetOf(nosubset2)");
EnvironmentPermission ep3 = new EnvironmentPermission (EnvironmentPermissionAccess.Write, "TMP");
Assert.IsTrue (!ep1.IsSubsetOf (ep3), "IsSubsetOf(TMP)");
Assert.IsTrue (ep3.IsSubsetOf (ep1), "TMP.IsSubsetOf()");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsSubsetOfBadPermission ()
{
EnvironmentPermission ep1 = new EnvironmentPermission (EnvironmentPermissionAccess.Read, envVariables);
FileDialogPermission fdp2 = new FileDialogPermission (PermissionState.Unrestricted);
Assert.IsTrue (ep1.IsSubsetOf (fdp2), "IsSubsetOf(FileDialogPermission)");
}
}
}

View File

@@ -0,0 +1,161 @@
//
// FileDialogPermissionAttribute.cs -
// NUnit Test Cases for FileDialogPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
#if MOBILE
[Ignore]
#endif
public class FileDialogPermissionAttributeTest {
[Test]
public void Default ()
{
FileDialogPermissionAttribute a = new FileDialogPermissionAttribute (SecurityAction.Assert);
Assert.IsFalse (a.Open, "Open");
Assert.IsFalse (a.Save, "Save");
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
FileDialogPermission perm = (FileDialogPermission) a.CreatePermission ();
Assert.IsFalse (perm.IsUnrestricted (), "CreatePermission-IsUnrestricted");
}
[Test]
public void Action ()
{
FileDialogPermissionAttribute a = new FileDialogPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
FileDialogPermissionAttribute a = new FileDialogPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void None ()
{
FileDialogPermissionAttribute attr = new FileDialogPermissionAttribute (SecurityAction.Assert);
attr.Open = false;
attr.Save = false;
Assert.IsFalse (attr.Open, "None=Open");
Assert.IsFalse (attr.Save, "None=Save");
FileDialogPermission p = (FileDialogPermission) attr.CreatePermission ();
Assert.AreEqual (FileDialogPermissionAccess.None, p.Access, "None=FileDialogPermission");
}
[Test]
public void Open ()
{
FileDialogPermissionAttribute attr = new FileDialogPermissionAttribute (SecurityAction.Assert);
attr.Open = true;
attr.Save = false;
Assert.IsTrue (attr.Open, "Open=Open");
Assert.IsFalse (attr.Save, "Open=Save");
FileDialogPermission p = (FileDialogPermission) attr.CreatePermission ();
Assert.AreEqual (FileDialogPermissionAccess.Open, p.Access, "Open=FileDialogPermission");
}
[Test]
public void Save ()
{
FileDialogPermissionAttribute attr = new FileDialogPermissionAttribute (SecurityAction.Assert);
attr.Open = false;
attr.Save = true;
Assert.IsFalse (attr.Open, "Save=Open");
Assert.IsTrue (attr.Save, "Save=Save");
FileDialogPermission p = (FileDialogPermission) attr.CreatePermission ();
Assert.AreEqual (FileDialogPermissionAccess.Save, p.Access, "Save=FileDialogPermission");
}
[Test]
public void OpenSave ()
{
FileDialogPermissionAttribute attr = new FileDialogPermissionAttribute (SecurityAction.Assert);
attr.Open = true;
attr.Save = true;
Assert.IsTrue (attr.Open, "OpenSave=Open");
Assert.IsTrue (attr.Save, "OpenSave=Save");
FileDialogPermission p = (FileDialogPermission) attr.CreatePermission ();
Assert.AreEqual (FileDialogPermissionAccess.OpenSave, p.Access, "OpenSave=FileDialogPermission");
Assert.IsTrue (p.IsUnrestricted (), "OpenSave=Unrestricted");
}
[Test]
public void Unrestricted ()
{
FileDialogPermissionAttribute a = new FileDialogPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
FileDialogPermission perm = (FileDialogPermission) a.CreatePermission ();
Assert.IsTrue (perm.IsUnrestricted (), "CreatePermission.IsUnrestricted");
}
[Test]
public void Attributes ()
{
Type t = typeof (FileDialogPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object[] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,301 @@
//
// FileDialogPermissionTest.cs - NUnit Test Cases for FileDialogPermission
//
// Author:
// Sebastien Pouliot (spouliot@motus.com)
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class FileDialogPermissionTest {
private static string className = "System.Security.Permissions.FileDialogPermission, ";
[Test]
public void PermissionStateNone ()
{
FileDialogPermission p = new FileDialogPermission (PermissionState.None);
Assert.IsNotNull (p, "FileDialogPermission(PermissionState.None)");
Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
FileDialogPermission copy = (FileDialogPermission) p.Copy ();
Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
SecurityElement se = p.ToXml ();
Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class");
Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version");
}
[Test]
public void PermissionStateUnrestricted ()
{
FileDialogPermission p = new FileDialogPermission (PermissionState.Unrestricted);
Assert.IsNotNull (p, "FileDialogPermission(PermissionState.Unrestricted)");
Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
FileDialogPermission copy = (FileDialogPermission) p.Copy ();
Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
SecurityElement se = p.ToXml ();
Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
}
[Test]
public void Derestricted ()
{
FileDialogPermission p = new FileDialogPermission (PermissionState.Unrestricted);
Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
p.Access = FileDialogPermissionAccess.None;
Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
}
[Test]
public void None ()
{
FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.None);
Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = p.ToXml ();
Assert.IsNull ((se.Attributes ["Access"] as string), "ToXml-Access=None");
}
[Test]
public void Open ()
{
FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.Open);
Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = p.ToXml ();
Assert.AreEqual ("Open", (se.Attributes ["Access"] as string), "ToXml-Access=Open");
}
[Test]
public void Save ()
{
FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.Save);
Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = p.ToXml ();
Assert.AreEqual ("Save", (se.Attributes ["Access"] as string), "ToXml-Access=Save");
}
[Test]
public void OpenSave ()
{
FileDialogPermission p = new FileDialogPermission (FileDialogPermissionAccess.OpenSave);
Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
SecurityElement se = p.ToXml ();
Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
}
[Test]
public void Access ()
{
FileDialogPermission p = new FileDialogPermission (PermissionState.None);
Assert.IsTrue (!p.IsUnrestricted (), "Access(default).IsUnrestricted");
p.Access = FileDialogPermissionAccess.None;
Assert.IsTrue (!p.IsUnrestricted (), "Access(None).IsUnrestricted");
p.Access = FileDialogPermissionAccess.Open;
Assert.IsTrue (!p.IsUnrestricted (), "Access(Open).IsUnrestricted");
p.Access = FileDialogPermissionAccess.Save;
Assert.IsTrue (!p.IsUnrestricted (), "Access(Save).IsUnrestricted");
p.Access = FileDialogPermissionAccess.OpenSave;
Assert.IsTrue (p.IsUnrestricted (), "Access(OpenSave).IsUnrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXmlNull ()
{
FileDialogPermission p = new FileDialogPermission (PermissionState.None);
p.FromXml (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXmlInvalidPermission ()
{
FileDialogPermission p = new FileDialogPermission (PermissionState.None);
SecurityElement se = p.ToXml ();
// can't modify - so we create our own
SecurityElement se2 = new SecurityElement ("IInvalidPermission", se.Text);
se2.AddAttribute ("class", se.Attribute ("class"));
se2.AddAttribute ("version", se.Attribute ("version"));
p.FromXml (se2);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXmlWrongVersion ()
{
FileDialogPermission p = new FileDialogPermission (PermissionState.None);
SecurityElement se = p.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");
p.FromXml (se2);
}
[Test]
public void FromXml ()
{
FileDialogPermission p = new FileDialogPermission (PermissionState.None);
SecurityElement se = p.ToXml ();
Assert.IsNotNull (se, "ToXml()");
FileDialogPermission p2 = (FileDialogPermission) p.Copy ();
p2.FromXml (se);
Assert.AreEqual (FileDialogPermissionAccess.None, p2.Access, "FromXml-None");
se.AddAttribute ("Access", "Open");
p2.FromXml (se);
Assert.AreEqual (FileDialogPermissionAccess.Open, p2.Access, "FromXml-Open");
se = p.ToXml ();
se.AddAttribute ("Access", "Save");
p2.FromXml (se);
Assert.AreEqual (FileDialogPermissionAccess.Save, p2.Access, "FromXml-Save");
se = p.ToXml ();
se.AddAttribute ("Unrestricted", "true");
p2.FromXml (se);
Assert.IsTrue (p2.IsUnrestricted (), "FromXml-Unrestricted");
}
[Test]
public void UnionWithNull ()
{
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
FileDialogPermission p2 = null;
FileDialogPermission p3 = (FileDialogPermission) p1.Union (p2);
Assert.AreEqual (p1.ToXml ().ToString (), p3.ToXml ().ToString (), "P1 U null == P1");
}
[Test]
public void UnionWithUnrestricted ()
{
FileDialogPermission p1 = new FileDialogPermission (PermissionState.Unrestricted);
FileDialogPermission p2 = new FileDialogPermission (FileDialogPermissionAccess.Open);
FileDialogPermission p3 = (FileDialogPermission) p1.Union (p2);
Assert.IsTrue (p3.IsUnrestricted (), "Unrestricted U P2 == Unrestricted");
p3 = (FileDialogPermission) p2.Union (p1);
Assert.IsTrue (p3.IsUnrestricted (), "P2 U Unrestricted == Unrestricted");
}
[Test]
public void Union ()
{
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
FileDialogPermission p2 = new FileDialogPermission (FileDialogPermissionAccess.Save);
FileDialogPermission p3 = (FileDialogPermission) p1.Union (p2);
FileDialogPermission p4 = new FileDialogPermission (FileDialogPermissionAccess.OpenSave);
Assert.AreEqual (p3.ToXml ().ToString (), p4.ToXml ().ToString (), "P1 U P2 == P1+2");
Assert.IsTrue (p3.IsUnrestricted (), "P1+2==Unrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void UnionWithBadPermission ()
{
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted);
FileDialogPermission p3 = (FileDialogPermission) p1.Union (ep2);
}
[Test]
public void IntersectWithNull ()
{
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
FileDialogPermission p2 = null;
FileDialogPermission p3 = (FileDialogPermission) p1.Intersect (p2);
Assert.IsNull (p3, "P1 N null == null");
}
[Test]
public void IntersectWithUnrestricted ()
{
FileDialogPermission p1 = new FileDialogPermission (PermissionState.Unrestricted);
FileDialogPermission p2 = new FileDialogPermission (FileDialogPermissionAccess.Open);
FileDialogPermission p3 = (FileDialogPermission) p1.Intersect (p2);
Assert.IsTrue (!p3.IsUnrestricted (), "Unrestricted N P2 == P2");
Assert.AreEqual (p2.ToXml ().ToString (), p3.ToXml ().ToString (), "Unrestricted N EP2 == EP2");
p3 = (FileDialogPermission) p2.Intersect (p1);
Assert.IsTrue (!p3.IsUnrestricted (), "P2 N Unrestricted == P2");
Assert.AreEqual (p2.ToXml ().ToString (), p3.ToXml ().ToString (), "P2 N Unrestricted == P2");
}
[Test]
public void Intersect ()
{
// no intersection
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
FileDialogPermission p2 = new FileDialogPermission (FileDialogPermissionAccess.Save);
FileDialogPermission p3 = (FileDialogPermission) p1.Intersect (p2);
Assert.IsNull (p3, "EP1 N EP2 == null");
// intersection in open
FileDialogPermission p4 = new FileDialogPermission (FileDialogPermissionAccess.Open);
p3 = (FileDialogPermission) p4.Intersect (p1);
Assert.AreEqual (FileDialogPermissionAccess.Open, p3.Access, "Intersect-Open");
// intersection in save
FileDialogPermission p5 = new FileDialogPermission (FileDialogPermissionAccess.Save);
p3 = (FileDialogPermission) p5.Intersect (p2);
Assert.AreEqual (FileDialogPermissionAccess.Save, p3.Access, "Intersect-Save");
// intersection in open and save
FileDialogPermission p6 = new FileDialogPermission (FileDialogPermissionAccess.OpenSave);
FileDialogPermission p7 = new FileDialogPermission (FileDialogPermissionAccess.OpenSave);
p3 = (FileDialogPermission) p6.Intersect (p7);
Assert.AreEqual (FileDialogPermissionAccess.OpenSave, p3.Access, "Intersect-AllAccess-OpenSave");
Assert.IsTrue (p3.IsUnrestricted (), "Intersect-OpenSave-Unrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IntersectWithBadPermission ()
{
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted);
FileDialogPermission p3 = (FileDialogPermission) p1.Intersect (ep2);
}
[Test]
public void IsSubsetOfNull ()
{
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
Assert.IsTrue (!p1.IsSubsetOf (null), "IsSubsetOf(null)");
}
[Test]
public void IsSubsetOfUnrestricted ()
{
FileDialogPermission p1 = new FileDialogPermission (PermissionState.Unrestricted);
FileDialogPermission p2 = new FileDialogPermission (FileDialogPermissionAccess.Open);
FileDialogPermission p3 = new FileDialogPermission (PermissionState.Unrestricted);
Assert.IsTrue (!p1.IsSubsetOf (p2), "Unrestricted.IsSubsetOf()");
Assert.IsTrue (p2.IsSubsetOf (p1), "IsSubsetOf(Unrestricted)");
Assert.IsTrue (p1.IsSubsetOf (p3), "Unrestricted.IsSubsetOf(Unrestricted)");
}
[Test]
public void IsSubsetOf ()
{
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
FileDialogPermission p2 = new FileDialogPermission (FileDialogPermissionAccess.Save);
Assert.IsTrue (!p1.IsSubsetOf (p2), "IsSubsetOf(nosubset1)");
Assert.IsTrue (!p2.IsSubsetOf (p1), "IsSubsetOf(nosubset2)");
FileDialogPermission p3 = new FileDialogPermission (FileDialogPermissionAccess.OpenSave);
Assert.IsTrue (p1.IsSubsetOf (p3), "IsSubsetOf(OpenSave)");
Assert.IsTrue (!p3.IsSubsetOf (p1), "OpenSave.IsSubsetOf()");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsSubsetOfBadPermission ()
{
FileDialogPermission p1 = new FileDialogPermission (FileDialogPermissionAccess.Open);
EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted);
Assert.IsTrue (p1.IsSubsetOf (ep2), "IsSubsetOf(EnvironmentPermission)");
}
}
}

View File

@@ -0,0 +1,347 @@
//
// FileIOPermissionAttributeTest.cs -
// NUnit Test Cases for FileIOPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
#if MOBILE
[Ignore]
#endif
public class FileIOPermissionAttributeTest {
[Test]
public void Default ()
{
FileIOPermissionAttribute a = new FileIOPermissionAttribute (SecurityAction.Assert);
Assert.IsNull (a.Append, "Append");
Assert.IsNull (a.PathDiscovery, "PathDiscovery");
Assert.IsNull (a.Read, "Read");
Assert.IsNull (a.Write, "Write");
#if NET_2_0
Assert.IsNotNull (a.AllFiles, "AllFiles");
Assert.IsNotNull (a.AllLocalFiles, "AllLocalFiles");
Assert.IsNull (a.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (a.ViewAccessControl, "ViewAccessControl");
#endif
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
FileIOPermission perm = (FileIOPermission) a.CreatePermission ();
Assert.AreEqual (FileIOPermissionAccess.NoAccess, perm.AllFiles, "CreatePermission-AllFiles");
Assert.AreEqual (FileIOPermissionAccess.NoAccess, perm.AllLocalFiles, "CreatePermission-AllLocalFiles");
Assert.IsFalse (perm.IsUnrestricted (), "perm-Unrestricted");
}
[Test]
public void Action ()
{
FileIOPermissionAttribute a = new FileIOPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
FileDialogPermissionAttribute a = new FileDialogPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void All ()
{
string filename = Assembly.GetCallingAssembly ().Location;
FileIOPermissionAttribute attr = new FileIOPermissionAttribute (SecurityAction.Assert);
attr.All = filename;
Assert.AreEqual (filename, attr.Append, "All=Append");
Assert.AreEqual (filename, attr.PathDiscovery, "All=PathDiscovery");
Assert.AreEqual (filename, attr.Read, "All=Read");
Assert.AreEqual (filename, attr.Write, "All=Write");
#if NET_2_0
Assert.IsNotNull (attr.AllFiles, "AllFiles");
Assert.IsNotNull (attr.AllLocalFiles, "AllLocalFiles");
Assert.IsNull (attr.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (attr.ViewAccessControl, "ViewAccessControl");
#endif
FileIOPermission p = (FileIOPermission)attr.CreatePermission ();
filename = Path.GetFullPath (filename);
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Append) [0], "All=FileIOPermissionAttribute-Append");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.PathDiscovery) [0], "All=FileIOPermissionAttribute-PathDiscovery");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Read) [0], "All=FileIOPermissionAttribute-Read");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Write) [0], "All=FileIOPermissionAttribute-Write");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void All_Get ()
{
FileIOPermissionAttribute attr = new FileIOPermissionAttribute (SecurityAction.Assert);
string s = attr.All;
}
[Test]
public void Append ()
{
string filename = Assembly.GetCallingAssembly ().Location;
FileIOPermissionAttribute attr = new FileIOPermissionAttribute (SecurityAction.Assert);
attr.Append = filename;
Assert.AreEqual (filename, attr.Append, "Append=Append");
Assert.IsNull (attr.PathDiscovery, "PathDiscovery=null");
Assert.IsNull (attr.Read, "Read=null");
Assert.IsNull (attr.Write, "Write=null");
#if NET_2_0
Assert.IsNotNull (attr.AllFiles, "AllFiles");
Assert.IsNotNull (attr.AllLocalFiles, "AllLocalFiles");
Assert.IsNull (attr.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (attr.ViewAccessControl, "ViewAccessControl");
#endif
FileIOPermission p = (FileIOPermission)attr.CreatePermission ();
filename = Path.GetFullPath (filename);
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Append) [0], "Append=FileIOPermissionAttribute-Append");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.PathDiscovery), "Append=FileIOPermissionAttribute-PathDiscovery");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Read), "Append=FileIOPermissionAttribute-Read");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Write), "Append=FileIOPermissionAttribute-Write");
}
[Test]
public void PathDiscovery ()
{
string filename = Assembly.GetCallingAssembly ().Location;
FileIOPermissionAttribute attr = new FileIOPermissionAttribute (SecurityAction.Assert);
attr.PathDiscovery = filename;
Assert.IsNull (attr.Append, "Append=null");
Assert.AreEqual (filename, attr.PathDiscovery, "PathDiscovery=PathDiscovery");
Assert.IsNull (attr.Read, "Read=null");
Assert.IsNull (attr.Write, "Write=null");
#if NET_2_0
Assert.IsNotNull (attr.AllFiles, "AllFiles");
Assert.IsNotNull (attr.AllLocalFiles, "AllLocalFiles");
Assert.IsNull (attr.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (attr.ViewAccessControl, "ViewAccessControl");
#endif
FileIOPermission p = (FileIOPermission)attr.CreatePermission ();
filename = Path.GetFullPath (filename);
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Append), "PathDiscovery=FileIOPermissionAttribute-Append");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.PathDiscovery) [0], "PathDiscovery=FileIOPermissionAttribute-PathDiscovery");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Read), "PathDiscovery=FileIOPermissionAttribute-Read");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Write), "PathDiscovery=FileIOPermissionAttribute-Write");
}
[Test]
public void Read ()
{
string filename = Assembly.GetCallingAssembly ().Location;
FileIOPermissionAttribute attr = new FileIOPermissionAttribute (SecurityAction.Assert);
attr.Read = filename;
Assert.IsNull (attr.Append, "Append=null");
Assert.IsNull (attr.PathDiscovery, "PathDiscovery=null");
Assert.AreEqual (filename, attr.Read, "Read=Read");
Assert.IsNull (attr.Write, "Write=null");
#if NET_2_0
Assert.IsNotNull (attr.AllFiles, "AllFiles");
Assert.IsNotNull (attr.AllLocalFiles, "AllLocalFiles");
Assert.IsNull (attr.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (attr.ViewAccessControl, "ViewAccessControl");
#endif
FileIOPermission p = (FileIOPermission)attr.CreatePermission ();
filename = Path.GetFullPath (filename);
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Append), "PathDiscovery=FileIOPermissionAttribute-Append");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.PathDiscovery), "PathDiscovery=FileIOPermissionAttribute-PathDiscovery");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Read) [0], "PathDiscovery=FileIOPermissionAttribute-Read");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Write), "PathDiscovery=FileIOPermissionAttribute-Write");
}
#if NET_2_0
[Test]
public void ChangeAccessControl ()
{
FileIOPermissionAttribute a = new FileIOPermissionAttribute (SecurityAction.Assert);
a.ChangeAccessControl = "mono";
Assert.IsNull (a.Append, "Append");
Assert.AreEqual ("mono", a.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (a.PathDiscovery, "PathDiscovery");
Assert.IsNull (a.Read, "Read");
Assert.IsNull (a.ViewAccessControl, "ViewAccessControl");
Assert.IsNull (a.Write, "Write");
a.ChangeAccessControl = null;
Assert.IsNull (a.Append, "Append");
Assert.IsNull (a.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (a.PathDiscovery, "PathDiscovery");
Assert.IsNull (a.Read, "Read");
Assert.IsNull (a.ViewAccessControl, "ViewAccessControl");
Assert.IsNull (a.Write, "Write");
}
[Test]
public void ViewAccessControl ()
{
FileIOPermissionAttribute a = new FileIOPermissionAttribute (SecurityAction.Assert);
a.ViewAccessControl = "mono";
Assert.IsNull (a.Append, "Append");
Assert.IsNull (a.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (a.PathDiscovery, "PathDiscovery");
Assert.IsNull (a.Read, "Read");
Assert.AreEqual ("mono", a.ViewAccessControl, "ViewAccessControl");
Assert.IsNull (a.Write, "Write");
a.ViewAccessControl = null;
Assert.IsNull (a.Append, "Append");
Assert.IsNull (a.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (a.PathDiscovery, "PathDiscovery");
Assert.IsNull (a.Read, "Read");
Assert.IsNull (a.ViewAccessControl, "ViewAccessControl");
Assert.IsNull (a.Write, "Write");
}
[Test]
public void ViewAndModify_Set ()
{
FileIOPermissionAttribute a = new FileIOPermissionAttribute (SecurityAction.Assert);
a.ViewAndModify = "mono";
Assert.AreEqual ("mono", a.Append, "Append");
Assert.IsNull (a.ChangeAccessControl, "ChangeAccessControl");
Assert.AreEqual ("mono", a.PathDiscovery, "PathDiscovery");
Assert.AreEqual ("mono", a.Read, "Read");
Assert.IsNull (a.ViewAccessControl, "ViewAccessControl");
Assert.AreEqual ("mono", a.Write, "Write");
a.ViewAndModify = null;
Assert.IsNull (a.Append, "Append");
Assert.IsNull (a.ChangeAccessControl, "ChangeAccessControl");
Assert.IsNull (a.PathDiscovery, "PathDiscovery");
Assert.IsNull (a.Read, "Read");
Assert.IsNull (a.ViewAccessControl, "ViewAccessControl");
Assert.IsNull (a.Write, "Write");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ViewAndModify_Get ()
{
FileIOPermissionAttribute a = new FileIOPermissionAttribute (SecurityAction.Assert);
a.ViewAndModify = "mono";
Assert.AreEqual ("ViewAndModify", "mono", a.ViewAndModify);
}
#endif
[Test]
public void Write ()
{
string filename = Assembly.GetCallingAssembly ().Location;
FileIOPermissionAttribute attr = new FileIOPermissionAttribute (SecurityAction.Assert);
attr.Write = filename;
Assert.IsNull (attr.Append, "Append=null");
Assert.IsNull (attr.PathDiscovery, "PathDiscovery=null");
Assert.IsNull (attr.Read, "Read=null");
Assert.AreEqual (filename, attr.Write, "Write=Write");
FileIOPermission p = (FileIOPermission) attr.CreatePermission ();
filename = Path.GetFullPath (filename);
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Append), "PathDiscovery=FileIOPermissionAttribute-Append");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.PathDiscovery), "PathDiscovery=FileIOPermissionAttribute-PathDiscovery");
Assert.IsNull (p.GetPathList (FileIOPermissionAccess.Read), "PathDiscovery=FileIOPermissionAttribute-Read");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Write) [0], "PathDiscovery=FileIOPermissionAttribute-Write");
}
[Test]
public void Unrestricted ()
{
FileIOPermissionAttribute a = new FileIOPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
FileIOPermission perm = (FileIOPermission) a.CreatePermission ();
Assert.IsTrue (perm.IsUnrestricted (), "CreatePermission.IsUnrestricted");
Assert.AreEqual (FileIOPermissionAccess.AllAccess, perm.AllFiles, "CreatePermission.AllFiles");
Assert.AreEqual (FileIOPermissionAccess.AllAccess, perm.AllLocalFiles, "CreatePermission.AllLocalFiles");
}
[Test]
public void Attributes ()
{
Type t = typeof (FileDialogPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
[Test]
[Category("NotDotNet")]
public void NonC14NPath ()
{
string filename = Path.Combine (Path.GetTempPath (), "test");
filename = Path.Combine (filename, "..");
filename = Path.Combine (filename, "here");
FileIOPermissionAttribute attr = new FileIOPermissionAttribute (SecurityAction.Assert);
// attribute class will keep the .. in the path
attr.All = filename;
Assert.AreEqual (filename, attr.Append, "All=Append");
Assert.AreEqual (filename, attr.PathDiscovery, "All=PathDiscovery");
Assert.AreEqual (filename, attr.Read, "All=Read");
Assert.AreEqual (filename, attr.Write, "All=Write");
// but the permission class will c14n it
filename = Path.GetFullPath (filename);
FileIOPermission p = (FileIOPermission)attr.CreatePermission ();
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Append) [0], "All=FileIOPermissionAttribute-Append");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.PathDiscovery) [0], "All=FileIOPermissionAttribute-PathDiscovery");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Read) [0], "All=FileIOPermissionAttribute-Read");
Assert.AreEqual (filename, p.GetPathList (FileIOPermissionAccess.Write) [0], "All=FileIOPermissionAttribute-Write");
}
}
}

View File

@@ -0,0 +1,456 @@
//
// MonoTests.System.Security.Permissions.FileIOPermissionTest.cs
//
// Author:
// Nick Drochak (ndrochak@gol.com)
//
// (C) 2001-2002 Nick Drochak II
//
// Note: Only Unix and Windows file paths are tested. To run the tests on Mac OS's
// search for the "FIXME" notes below and adjust accordingly.
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.Security.Permissions {
#if !TARGET_JVM
public class FilePathUtil {
[DllImport("kernel32.dll")]
private static extern uint GetLongPathName (string shortPath,
StringBuilder buffer, uint bufLength);
static public string GetLongPathName (string somePath)
{
StringBuilder buffer = new StringBuilder(260);
if (0 != GetLongPathName (somePath, buffer, (uint) buffer.Capacity))
return buffer.ToString ();
else
return null;
}
[DllImport("kernel32.dll", SetLastError=true)]
private static extern uint GetShortPathName ( string longPath,
StringBuilder buffer, uint bufLength);
static public string GetShortPathName (string somePath)
{
StringBuilder buffer = new StringBuilder(260);
if (0 != GetShortPathName (somePath, buffer, (uint) buffer.Capacity))
return buffer.ToString ();
else
return null;
}
}
#endif
[TestFixture]
public class FileIOPermissionTest {
string[] pathArrayGood;
string[] pathArrayBad;
FileIOPermission p;
FileIOPermission p2;
string[] pathsInPermission;
string[] pathArrayGood2;
FileIOPermission unrestricted;
private string filename;
private bool unix;
[SetUp]
public void SetUp ()
{
Environment.CurrentDirectory = Path.GetTempPath();
filename = Path.GetTempFileName ();
int os = (int) Environment.OSVersion.Platform;
unix = ((os == 4) || (os == 128) || (os == 6));
p = null;
pathsInPermission = null;
pathArrayGood = new string[2];
pathArrayBad = new string[2];
pathArrayGood2 = new string[3];
// FIXME: Adjust to run on Mac OS's
if (Path.VolumeSeparatorChar == ':') {
pathArrayGood[0] = "c:\\temp1";
pathArrayGood[1] = "d:\\temp2";
pathArrayBad[0] = "c:\\temp1";
pathArrayBad[1] = "d:\\temp*";
pathArrayGood2[0] = "c:\\temp1";
pathArrayGood2[1] = "d:\\temp2";
pathArrayGood2[2] = "z:\\something";
}
else {
pathArrayGood[0] = "/temp1";
pathArrayGood[1] = "/usr/temp2";
pathArrayBad[0] = "/temp1";
pathArrayBad[1] = "/usr/temp*"; // not really bad under Unix...
pathArrayGood2[0] = "/temp1";
pathArrayGood2[1] = "/usr/temp2";
pathArrayGood2[2] = "/usr/bin/something";
}
}
[TearDown]
public void TearDown ()
{
if (File.Exists (filename))
File.Delete (filename);
}
[Test]
public void ConstructorPermissionState ()
{
p = new FileIOPermission(PermissionState.None);
Assert.AreEqual(false, p.IsUnrestricted(), "Should be Restricted");
p = new FileIOPermission(PermissionState.Unrestricted);
Assert.AreEqual(true, p.IsUnrestricted(), "Should be Unrestricted");
try{
p = new FileIOPermission((PermissionState)77);
Assert.Fail("Should have thrown an exception on invalid PermissionState");
}
catch{
// we should be here if things are working. nothing to do
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorString_Null ()
{
p = new FileIOPermission(FileIOPermissionAccess.Append, (string)null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorString_NotRooted ()
{
p = new FileIOPermission(FileIOPermissionAccess.Append, "this path is not rooted");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorString_InvalidPath ()
{
p = new FileIOPermission(FileIOPermissionAccess.Append, "<this is not a valid path>");
}
[Test]
public void ConstructorString_Wildcard ()
{
try {
// note: this is a valid path on UNIX so we must be able to protect it
p = new FileIOPermission(FileIOPermissionAccess.Append, pathArrayBad [1]);
}
catch (ArgumentException) {
if (unix)
Assert.Fail ("Wildcard * is valid in filenames");
// else it's normal for Windows to throw ArgumentException
}
catch (Exception e) {
Assert.Fail ("Bad or wrong exception: " + e.ToString ());
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorString_InvalidAccess ()
{
p = new FileIOPermission((FileIOPermissionAccess)77, "c:\\temp");
}
[Test]
public void ConstructorString ()
{
string pathToAdd;
// FIXME: Adjust to run on Mac OS's
if (Path.VolumeSeparatorChar == ':')
pathToAdd = "c:\\temp";
else
pathToAdd = "/temp";
p = new FileIOPermission(FileIOPermissionAccess.Read, pathToAdd);
pathsInPermission = p.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue (pathsInPermission.Length == 1, "Does not contain correct number of paths. Expected 1 but got: "+pathsInPermission.Length);
Assert.IsTrue(pathsInPermission[0] == pathToAdd, "Does not contain expected path from constructor: "+pathToAdd);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorStringArray_Null ()
{
p = new FileIOPermission(FileIOPermissionAccess.Append, (string[])null);
}
[Test]
public void ConstructorStringArray_Wildcard ()
{
try {
// note: this is a valid path on UNIX so we must be able to protect it
p = new FileIOPermission(FileIOPermissionAccess.Append, pathArrayBad);
}
catch (ArgumentException) {
if (unix)
Assert.Fail ("Wildcard * is valid in filenames");
// else it's normal for Windows to throw ArgumentException
}
catch (Exception e) {
Assert.Fail ("Bad or wrong exception: " + e.ToString ());
}
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorStringArray_InvalidAccess ()
{
p = new FileIOPermission((FileIOPermissionAccess)77, pathArrayGood);
}
[Test]
public void ConstructorStringArray ()
{
p = new FileIOPermission(FileIOPermissionAccess.Read, pathArrayGood);
pathsInPermission = p.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue (pathsInPermission.Length == 2, "Does not contain correct number of paths. Expected 2 but got: "+pathsInPermission.Length);
foreach (string s in pathsInPermission){
Assert.IsTrue (Array.IndexOf(pathsInPermission, s) >=0, "Unexpected path in the Permission: " + s);
}
}
[Test]
public void AddPathListStringArray ()
{
p = new FileIOPermission(FileIOPermissionAccess.Read, pathArrayGood);
pathsInPermission = p.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue (pathsInPermission.Length == 2, "Does not contain correct number of paths. Expected 2 but got: "+pathsInPermission.Length);
foreach (string s in pathsInPermission){
Assert.IsTrue (Array.IndexOf(pathsInPermission, s) >=0, "Unexpected path in the Permission: " + s);
}
p.AddPathList(FileIOPermissionAccess.Append, pathArrayGood);
pathsInPermission = p.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue (pathsInPermission.Length == 2, "Should still contain correct number Read paths. Expected 2 but got: "+pathsInPermission.Length);
foreach (string s in pathsInPermission){
Assert.IsTrue (Array.IndexOf(pathsInPermission, s) >=0, "Unexpected path in the Permission: " + s);
}
pathsInPermission = p.GetPathList(FileIOPermissionAccess.Append);
Assert.IsTrue (pathsInPermission.Length == 2, "Should contain correct number of Append paths. Expected 2 but got: "+pathsInPermission.Length);
foreach (string s in pathsInPermission){
Assert.IsTrue (Array.IndexOf(pathsInPermission, s) >=0, "Unexpected path in the Permission: " + s);
}
}
[Test]
public void Intersect ()
{
p = new FileIOPermission(FileIOPermissionAccess.Read, pathArrayGood);
p.AllFiles = FileIOPermissionAccess.Append;
p.AllLocalFiles = FileIOPermissionAccess.Write;
unrestricted = new FileIOPermission(PermissionState.Unrestricted);
FileIOPermission intersection = (FileIOPermission)p.Intersect(unrestricted);
pathsInPermission = intersection.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue (pathsInPermission.Length == 2, "Should contain correct number of Read paths. Expected 2 but got: "+pathsInPermission.Length);
Assert.IsTrue((intersection.AllFiles & FileIOPermissionAccess.Append) != 0, "Should have Append bit in AllFiles.");
Assert.IsTrue((intersection.AllLocalFiles & FileIOPermissionAccess.Write) != 0, "Should have Write bit in AllLocalFiles.");
intersection = (FileIOPermission)unrestricted.Intersect(p);
pathsInPermission = intersection.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue (pathsInPermission.Length == 2, "Should contain correct number of Read paths. Expected 2 but got: "+pathsInPermission.Length);
Assert.IsTrue((intersection.AllFiles & FileIOPermissionAccess.Append) != 0, "Should have Append bit in AllFiles.");
Assert.IsTrue((intersection.AllLocalFiles & FileIOPermissionAccess.Write) != 0, "Should have Write bit in AllLocalFiles.");
p2 = new FileIOPermission(FileIOPermissionAccess.Append | FileIOPermissionAccess.Read, pathArrayGood2);
p2.AllFiles = FileIOPermissionAccess.Append | FileIOPermissionAccess.Write;
p2.AllLocalFiles = FileIOPermissionAccess.Write | FileIOPermissionAccess.Read;
intersection = (FileIOPermission)p.Intersect(p2);
pathsInPermission = intersection.GetPathList(FileIOPermissionAccess.Read);
Assert.IsNotNull (pathsInPermission, "Should have some paths");
Assert.AreEqual (2, pathsInPermission.Length, "Should contain correct number of Read paths");
Assert.AreEqual ( FileIOPermissionAccess.Append, intersection.AllFiles, "Should have only Append bit in AllFiles.");
Assert.AreEqual ( FileIOPermissionAccess.Write, intersection.AllLocalFiles, "Should have only Write bit in AllLocalFiles.");
intersection = (FileIOPermission)p2.Intersect(p);
pathsInPermission = intersection.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue (pathsInPermission.Length == 2, "Should contain correct number of Read paths. Expected 2 but got: "+pathsInPermission.Length);
Assert.IsTrue(intersection.AllFiles == FileIOPermissionAccess.Append, "Should have only Append bit in AllFiles.");
Assert.IsTrue(intersection.AllLocalFiles == FileIOPermissionAccess.Write, "Should have only Write bit in AllLocalFiles.");
}
[Test]
public void IsSubsetOf ()
{
unrestricted = new FileIOPermission(PermissionState.Unrestricted);
Assert.IsTrue(unrestricted.IsSubsetOf(unrestricted), "IsSubsetOf reflective test failed");
p = new FileIOPermission(FileIOPermissionAccess.Read, pathArrayGood);
p.AllFiles = FileIOPermissionAccess.Append;
p.AllLocalFiles = FileIOPermissionAccess.Write;
Assert.IsTrue(p.IsSubsetOf(p), "#1 IsSubsetOf reflective test failed");
Assert.IsTrue(!unrestricted.IsSubsetOf(p), "#1 IsSubsetOf false test failed");
Assert.IsTrue(p.IsSubsetOf(unrestricted), "#1 IsSubsetOf true test failed");
p2 = new FileIOPermission(FileIOPermissionAccess.Append | FileIOPermissionAccess.Read, pathArrayGood2);
p2.AllFiles = FileIOPermissionAccess.Append | FileIOPermissionAccess.Write;
p2.AllLocalFiles = FileIOPermissionAccess.Write | FileIOPermissionAccess.Read;
Assert.IsTrue(p2.IsSubsetOf(p2), "#2 IsSubsetOf reflective test failed");
Assert.IsTrue(p.IsSubsetOf(p2), "#2 IsSubsetOf true test failed");
Assert.IsTrue(!p2.IsSubsetOf(p), "#2 IsSubsetOf false test failed");
}
[Test]
public void Union ()
{
unrestricted = new FileIOPermission(PermissionState.Unrestricted);
p = new FileIOPermission(FileIOPermissionAccess.Read, pathArrayGood);
FileIOPermission union = (FileIOPermission)unrestricted.Union(p);
pathsInPermission = union.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue(union.IsUnrestricted(), "Should get an unrestricted permission");
Assert.IsTrue(pathsInPermission == null, "Path list should be empty");
union = (FileIOPermission)p.Union(unrestricted);
pathsInPermission = union.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue(union.IsUnrestricted(), "Should get an unrestricted permission");
Assert.IsTrue(pathsInPermission == null, "Path list should be empty");
p2 = new FileIOPermission(FileIOPermissionAccess.Append, pathArrayGood2);
union = (FileIOPermission)p.Union(p2);
pathsInPermission = union.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue(pathsInPermission.Length == pathArrayGood.Length, "Path list should have 2 for Read");
pathsInPermission = union.GetPathList(FileIOPermissionAccess.Append);
Assert.IsTrue(pathsInPermission.Length == pathArrayGood2.Length, "Path list should have 3 for Append");
union = (FileIOPermission)p2.Union(p);
pathsInPermission = union.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue(pathsInPermission.Length == pathArrayGood.Length, "Path list should have 2 for Read");
pathsInPermission = union.GetPathList(FileIOPermissionAccess.Append);
Assert.IsTrue(pathsInPermission.Length == pathArrayGood2.Length, "Path list should have 3 for Append");
}
[Test]
public void Union_Bug79118 ()
{
string[] f1 = unix ? new string[] { "/tmp/one", "/tmp/two" } : new string[] { "c:\\temp\\one", "c:\\temp\\two" };
string[] f2 = unix ? new string[] { "/tmp/two" } : new string[] { "c:\\temp\\two" };
p = new FileIOPermission (FileIOPermissionAccess.Read, f1);
p2 = new FileIOPermission (FileIOPermissionAccess.Read, f2);
FileIOPermission union = (FileIOPermission) p.Union (p2);
string[] paths = union.GetPathList(FileIOPermissionAccess.Read);
Assert.AreEqual (2, paths.Length, "Length");
Assert.AreEqual (f1[0], paths[0], "0");
Assert.AreEqual (f1[1], paths[1], "1");
}
private void Partial (string msg, string[] path1, string[] path2, int expected)
{
p = new FileIOPermission (FileIOPermissionAccess.Read, path1);
p2 = new FileIOPermission (FileIOPermissionAccess.Read, path2);
FileIOPermission union = (FileIOPermission) p.Union (p2);
string[] paths = union.GetPathList(FileIOPermissionAccess.Read);
Assert.AreEqual (expected, paths.Length, msg + ".Length");
Assert.AreEqual (path1[0], paths[0], msg + "[0]");
if (expected > 1)
Assert.AreEqual (path2[0], paths[1], msg + "[1]");
}
[Test]
public void Union_Partial ()
{
string[] f1 = unix ? new string[] { "/dir/part" } : new string[] { "c:\\dir\\part" };
string[] f2 = unix ? new string[] { "/dir/partial" } : new string[] { "c:\\dir\\partial" };
Partial ("1", f1, f2, 2);
Partial ("2", f2, f1, 2);
f1 = unix ? new string[] { "/dir/part/" } : new string[] { "c:\\dir\\part\\" };
f2 = unix ? new string[] { "/dir/partial/" } : new string[] { "c:\\dir\\partial\\" };
Partial ("3", f1, f2, 2);
Partial ("4", f2, f1, 2);
f1 = unix ? new string[] { "/dir/part/ial" } : new string[] { "c:\\dir\\part\\ial" };
f2 = unix ? new string[] { "/dir/part/ial" } : new string[] { "c:\\dir\\part\\ial" };
Partial ("5", f1, f2, 1);
Partial ("6", f2, f1, 1);
}
[Test]
public void FromXML ()
{
p = new FileIOPermission(PermissionState.None);
SecurityElement esd = new SecurityElement("IPermission");
esd.AddAttribute("class", "FileIOPermission");
esd.AddAttribute("version", "1");
esd.AddAttribute("Unrestricted", "true");
p.FromXml(esd);
Assert.IsTrue(p.IsUnrestricted(), "Should get an unrestricted permission");
esd = new SecurityElement("IPermission");
esd.AddAttribute("class", "FileIOPermission");
esd.AddAttribute("version", "1");
// FIXME: Adjust to run on Mac OS's
if (Path.VolumeSeparatorChar == ':') {
esd.AddAttribute("Read", "c:\\temp;d:\\temp2");
esd.AddAttribute("Write", "c:\\temp;d:\\temp2;z:\\temp3");
}
else {
esd.AddAttribute("Read", "/temp;/usr/temp2");
esd.AddAttribute("Write", "/temp;/usr/temp2;/usr/bin/temp3");
}
p = new FileIOPermission(PermissionState.None);
p.FromXml(esd);
pathsInPermission = p.GetPathList(FileIOPermissionAccess.Read);
Assert.IsTrue(pathsInPermission.Length == 2, "Path list should have 2 for Read");
pathsInPermission = p.GetPathList(FileIOPermissionAccess.Write);
Assert.IsTrue(pathsInPermission.Length == 3, "Path list should have 2 for Write");
}
[Test]
public void ToXML ()
{
p = new FileIOPermission(FileIOPermissionAccess.Read, pathArrayGood);
SecurityElement esd = p.ToXml();
Assert.IsTrue(esd.Tag == "IPermission", "Esd tag incorrect");
Assert.IsTrue((String)esd.Attributes["version"] == "1", "Esd version incorrect");
string read = (String)esd.Attributes["Read"];
pathsInPermission = read.Split(';');
Assert.IsTrue(pathsInPermission.Length == 2, "Path list should have 2 for Read");
}
#if !TARGET_JVM
[Test]
[Ignore("should compatibility go that far ?")]
public void ShortToLong ()
{
// on windows this returns a "short" (8.3) path and filename
string filename = Path.GetTempFileName ();
p = new FileIOPermission(FileIOPermissionAccess.Read, filename);
string[] files = p.GetPathList (FileIOPermissionAccess.Read);
Assert.AreEqual (1, files.Length, "GetPathList.Count");
// FIXME: here GetTempFileName != GetPathList[0] for MS but == for Mono
Assert.AreEqual (Path.GetFileName (filename), Path.GetFileName (files [0]), "Path.GetFileName(GetTempFileName)==Path.GetFileName(GetPathList[0])");
// note: this will fail on Linux as kernel32.dll isn't available
Assert.AreEqual (FilePathUtil.GetLongPathName (filename), files [0], "GetLongPathName(GetTempFileName)==GetPathList[0]");
}
#endif
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FileUrl ()
{
// file://... isn't accepted
string filename = Assembly.GetExecutingAssembly ().CodeBase;
p = new FileIOPermission (FileIOPermissionAccess.Read, filename);
}
}
}

View File

@@ -0,0 +1,110 @@
//
// GacIdentityPermissionAttributeTest.cs - NUnit Test Cases for GacIdentityPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class GacIdentityPermissionAttributeTest {
[Test]
public void Default ()
{
GacIdentityPermissionAttribute a = new GacIdentityPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
IPermission p = a.CreatePermission ();
Assert.IsNotNull (p, "CreatePermission");
Assert.IsTrue ((p is GacIdentityPermission), "GacIdentityPermission");
}
[Test]
public void Action ()
{
GacIdentityPermissionAttribute a = new GacIdentityPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
GacIdentityPermissionAttribute a = new GacIdentityPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
// MS BUG [ExpectedException (typeof (ArgumentException))]
public void Unrestricted ()
{
GacIdentityPermissionAttribute a = new GacIdentityPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
IPermission perm = a.CreatePermission ();
}
[Test]
public void Attributes ()
{
GacIdentityPermissionAttribute a = new GacIdentityPermissionAttribute (SecurityAction.Assert);
Type t = typeof (GacIdentityPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object[] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute) attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}
#endif

View File

@@ -0,0 +1,241 @@
//
// GacIdentityPermissionTest.cs - NUnit Test Cases for GacIdentityPermission
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class GacIdentityPermissionTest {
[Test]
public void PermissionStateNone ()
{
GacIdentityPermission gip = new GacIdentityPermission (PermissionState.None);
SecurityElement se = gip.ToXml ();
// only class and version are present
Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes");
Assert.IsNull (se.Children, "Xml-Children");
GacIdentityPermission copy = (GacIdentityPermission)gip.Copy ();
Assert.IsFalse (Object.ReferenceEquals (gip, copy), "ReferenceEquals");
}
[Category ("NotWorking")]
[Test]
public void PermissionStateUnrestricted ()
{
GacIdentityPermission gip = new GacIdentityPermission (PermissionState.Unrestricted);
// FX 2.0 now supports Unrestricted for Identity Permissions
// However the XML doesn't show the Unrestricted status...
SecurityElement se = gip.ToXml ();
// only class and version are present
Assert.AreEqual (2, se.Attributes.Count, "Xml-Attributes");
Assert.IsNull (se.Children, "Xml-Children");
GacIdentityPermission copy = (GacIdentityPermission)gip.Copy ();
Assert.IsFalse (Object.ReferenceEquals (gip, copy), "ReferenceEquals");
// ... and because it doesn't implement IUnrestrictedPermission
// there is not way to know if it's unrestricted so...
Assert.IsTrue (gip.Equals (new GacIdentityPermission (PermissionState.None)), "Unrestricted==None");
// there is not much difference after all ;-)
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void PermissionStateInvalid ()
{
GacIdentityPermission gip = new GacIdentityPermission ((PermissionState)2);
}
[Test]
public void GacIdentityPermission_Empty ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
Assert.IsNotNull (gip);
}
[Test]
public void Intersect ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
GacIdentityPermission intersect = (GacIdentityPermission)gip.Intersect (null);
Assert.IsNull (intersect, "gip N null");
GacIdentityPermission empty = new GacIdentityPermission (PermissionState.None);
intersect = (GacIdentityPermission)gip.Intersect (empty);
Assert.IsNotNull (intersect, "gip N null");
intersect = (GacIdentityPermission)gip.Intersect (gip);
Assert.IsNotNull (intersect, "gip N gip");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Intersect_DifferentPermissions ()
{
GacIdentityPermission a = new GacIdentityPermission (PermissionState.None);
SecurityPermission b = new SecurityPermission (PermissionState.None);
a.Intersect (b);
}
[Test]
public void IsSubsetOf ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
Assert.IsFalse (gip.IsSubsetOf (null), "gip.IsSubsetOf (null)");
GacIdentityPermission empty = new GacIdentityPermission (PermissionState.None);
Assert.IsFalse (empty.IsSubsetOf (null), "empty.IsSubsetOf (null)");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsSubsetOf_DifferentPermissions ()
{
GacIdentityPermission a = new GacIdentityPermission (PermissionState.None);
SecurityPermission b = new SecurityPermission (PermissionState.None);
a.IsSubsetOf (b);
}
[Test]
public void Union ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
GacIdentityPermission union = (GacIdentityPermission)gip.Union (null);
Assert.IsNotNull (union, "gip U null");
GacIdentityPermission empty = new GacIdentityPermission (PermissionState.None);
union = (GacIdentityPermission)gip.Union (empty);
Assert.IsNotNull (union, "gip U empty");
union = (GacIdentityPermission)gip.Union (gip);
Assert.IsNotNull (union, "gip U gip");
// note: can't be tested with PermissionState.Unrestricted
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Union_DifferentPermissions ()
{
GacIdentityPermission a = new GacIdentityPermission (PermissionState.None);
SecurityPermission b = new SecurityPermission (PermissionState.None);
a.Union (b);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
gip.FromXml (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongTag ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
SecurityElement se = gip.ToXml ();
se.Tag = "IMono";
gip.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongTagCase ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
SecurityElement se = gip.ToXml ();
se.Tag = "IPERMISSION"; // instead of IPermission
gip.FromXml (se);
}
[Test]
public void FromXml_WrongClass ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
SecurityElement se = gip.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
w.AddAttribute ("version", se.Attribute ("version"));
gip.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 ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
SecurityElement se = gip.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
gip.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongVersion ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
SecurityElement se = gip.ToXml ();
se.Attributes.Remove ("version");
se.Attributes.Add ("version", "2");
gip.FromXml (se);
}
[Test]
public void FromXml_NoVersion ()
{
GacIdentityPermission gip = new GacIdentityPermission ();
SecurityElement se = gip.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
gip.FromXml (w);
}
}
}
#endif

View File

@@ -0,0 +1,363 @@
//
// HostProtectionAttributeTest.cs - NUnit Test Cases for HostProtectionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
#if MOBILE
[Ignore]
#endif
public class HostProtectionAttributeTest {
private void DefaultTests (HostProtectionAttribute hpa)
{
Assert.AreEqual (SecurityAction.LinkDemand, hpa.Action, "Action");
Assert.AreEqual (HostProtectionResource.None, hpa.Resources, "Resources");
Assert.IsFalse (hpa.ExternalProcessMgmt, "ExternalProcessMgmt");
Assert.IsFalse (hpa.ExternalThreading, "ExternalThreading");
Assert.IsFalse (hpa.MayLeakOnAbort, "MayLeakOnAbort");
Assert.IsFalse (hpa.SecurityInfrastructure, "SecurityInfrastructure");
Assert.IsFalse (hpa.SelfAffectingProcessMgmt, "SelfAffectingProcessMgmt");
Assert.IsFalse (hpa.SelfAffectingThreading, "SelfAffectingThreading");
Assert.IsFalse (hpa.SharedState, "SharedState");
Assert.IsFalse (hpa.Synchronization, "Synchronization");
Assert.IsFalse (hpa.UI, "UI");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted");
IPermission p = hpa.CreatePermission ();
Assert.AreEqual ("System.Security.Permissions.HostProtectionPermission", p.GetType ().ToString (), "CreatePermission");
Assert.IsTrue ((p is IUnrestrictedPermission), "IUnrestrictedPermission");
}
[Test]
#if MOBILE
[Ignore]
#endif
public void HostProtectionAttribute_Empty ()
{
// note: normally security attributes don't have an empty constructor
HostProtectionAttribute hpa = new HostProtectionAttribute ();
DefaultTests (hpa);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void HostProtectionAttribute_Assert ()
{
new HostProtectionAttribute (SecurityAction.Assert);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void HostProtectionAttribute_Demand ()
{
new HostProtectionAttribute (SecurityAction.Demand);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void HostProtectionAttribute_Deny ()
{
new HostProtectionAttribute (SecurityAction.Deny);
}
[Test]
#if MOBILE
[Ignore]
#endif
[ExpectedException (typeof (ArgumentException))]
public void HostProtectionAttribute_InheritanceDemand ()
{
new HostProtectionAttribute (SecurityAction.InheritanceDemand);
}
[Test]
public void HostProtectionAttribute_LinkDemand ()
{
HostProtectionAttribute hpa = new HostProtectionAttribute (SecurityAction.LinkDemand);
DefaultTests (hpa);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void HostProtectionAttribute_PermitOnly ()
{
new HostProtectionAttribute (SecurityAction.PermitOnly);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void HostProtectionAttribute_RequestMinimum ()
{
new HostProtectionAttribute (SecurityAction.RequestMinimum);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void HostProtectionAttribute_RequestOptional ()
{
new HostProtectionAttribute (SecurityAction.RequestOptional);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void HostProtectionAttribute_RequestRefuse ()
{
new HostProtectionAttribute (SecurityAction.RequestRefuse);
}
private HostProtectionAttribute Empty ()
{
HostProtectionAttribute a = new HostProtectionAttribute ();
a.Synchronization = false;
a.SharedState = false;
a.ExternalProcessMgmt = false;
a.SelfAffectingProcessMgmt = false;
a.ExternalThreading = false;
a.SelfAffectingThreading = false;
a.SecurityInfrastructure = false;
a.UI = false;
a.MayLeakOnAbort = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
return a;
}
[Test]
public void Synchronization ()
{
HostProtectionAttribute a = Empty ();
a.Synchronization = true;
Assert.AreEqual (HostProtectionResource.Synchronization, a.Resources, "Resources=Synchronization");
a.Synchronization = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void SharedState ()
{
HostProtectionAttribute a = Empty ();
a.SharedState = true;
Assert.AreEqual (HostProtectionResource.SharedState, a.Resources, "Resources=SharedState");
a.SharedState = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void ExternalProcessMgmt ()
{
HostProtectionAttribute a = Empty ();
a.ExternalProcessMgmt = true;
Assert.AreEqual (HostProtectionResource.ExternalProcessMgmt, a.Resources, "Resources=ExternalProcessMgmt");
a.ExternalProcessMgmt = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void SelfAffectingProcessMgmt ()
{
HostProtectionAttribute a = Empty ();
a.SelfAffectingProcessMgmt = true;
Assert.AreEqual (HostProtectionResource.SelfAffectingProcessMgmt, a.Resources, "Resources=SelfAffectingProcessMgmt");
a.SelfAffectingProcessMgmt = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void ExternalThreading ()
{
HostProtectionAttribute a = Empty ();
a.ExternalThreading = true;
Assert.AreEqual (HostProtectionResource.ExternalThreading, a.Resources, "Resources=ExternalThreading");
a.ExternalThreading = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void SelfAffectingThreading ()
{
HostProtectionAttribute a = Empty ();
a.SelfAffectingThreading = true;
Assert.AreEqual (HostProtectionResource.SelfAffectingThreading, a.Resources, "Resources=SelfAffectingThreading");
a.SelfAffectingThreading = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void SecurityInfrastructure ()
{
HostProtectionAttribute a = Empty ();
a.SecurityInfrastructure = true;
Assert.AreEqual (HostProtectionResource.SecurityInfrastructure, a.Resources, "Resources=SecurityInfrastructure");
a.SecurityInfrastructure = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void UI ()
{
HostProtectionAttribute a = Empty ();
a.UI = true;
Assert.AreEqual (HostProtectionResource.UI, a.Resources, "Resources=UI");
a.UI = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void MayLeakOnAbort ()
{
HostProtectionAttribute a = Empty ();
a.MayLeakOnAbort = true;
Assert.AreEqual (HostProtectionResource.MayLeakOnAbort, a.Resources, "Resources=MayLeakOnAbort");
a.MayLeakOnAbort = false;
Assert.AreEqual (HostProtectionResource.None, a.Resources, "Resources=None");
}
[Test]
public void Properties ()
{
HostProtectionAttribute hpa = new HostProtectionAttribute (SecurityAction.LinkDemand);
HostProtectionResource expected = HostProtectionResource.None;
Assert.AreEqual (expected, hpa.Resources, "None");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-1");
hpa.ExternalProcessMgmt = true;
expected |= HostProtectionResource.ExternalProcessMgmt;
Assert.AreEqual (expected, hpa.Resources, "+ExternalProcessMgmt");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-2");
hpa.ExternalThreading = true;
expected |= HostProtectionResource.ExternalThreading;
Assert.AreEqual (expected, hpa.Resources, "+ExternalThreading");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-3");
hpa.MayLeakOnAbort = true;
expected |= HostProtectionResource.MayLeakOnAbort;
Assert.AreEqual (expected, hpa.Resources, "+MayLeakOnAbort");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-4");
hpa.SecurityInfrastructure = true;
expected |= HostProtectionResource.SecurityInfrastructure;
Assert.AreEqual (expected, hpa.Resources, "+SecurityInfrastructure");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-5");
hpa.SelfAffectingProcessMgmt = true;
expected |= HostProtectionResource.SelfAffectingProcessMgmt;
Assert.AreEqual (expected, hpa.Resources, "+SelfAffectingProcessMgmt");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-6");
hpa.SelfAffectingThreading = true;
expected |= HostProtectionResource.SelfAffectingThreading;
Assert.AreEqual (expected, hpa.Resources, "+SelfAffectingThreading");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-7");
hpa.SharedState = true;
expected |= HostProtectionResource.SharedState;
Assert.AreEqual (expected, hpa.Resources, "+SharedState");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-8");
hpa.Synchronization = true;
expected |= HostProtectionResource.Synchronization;
Assert.AreEqual (expected, hpa.Resources, "+Synchronization");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-9");
hpa.UI = true;
expected |= HostProtectionResource.UI;
Assert.AreEqual (expected, hpa.Resources, "+UI");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted");
hpa.ExternalProcessMgmt = false;
expected &= ~HostProtectionResource.ExternalProcessMgmt;
Assert.AreEqual (expected, hpa.Resources, "-ExternalProcessMgmt");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-10");
hpa.ExternalThreading = false;
expected &= ~HostProtectionResource.ExternalThreading;
Assert.AreEqual (expected, hpa.Resources, "+ExternalThreading");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-11");
hpa.MayLeakOnAbort = false;
expected &= ~HostProtectionResource.MayLeakOnAbort;
Assert.AreEqual (expected, hpa.Resources, "+MayLeakOnAbort");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-12");
hpa.SecurityInfrastructure = false;
expected &= ~HostProtectionResource.SecurityInfrastructure;
Assert.AreEqual (expected, hpa.Resources, "+SecurityInfrastructure");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-13");
hpa.SelfAffectingProcessMgmt = false;
expected &= ~HostProtectionResource.SelfAffectingProcessMgmt;
Assert.AreEqual (expected, hpa.Resources, "+SelfAffectingProcessMgmt");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-14");
hpa.SelfAffectingThreading = false;
expected &= ~HostProtectionResource.SelfAffectingThreading;
Assert.AreEqual (expected, hpa.Resources, "+SelfAffectingThreading");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-15");
hpa.SharedState = false;
expected &= ~HostProtectionResource.SharedState;
Assert.AreEqual (expected, hpa.Resources, "+SharedState");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-16");
hpa.Synchronization = false;
expected &= ~HostProtectionResource.Synchronization;
Assert.AreEqual (expected, hpa.Resources, "+Synchronization");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-17");
hpa.UI = false;
expected &= ~HostProtectionResource.UI;
Assert.AreEqual (expected, hpa.Resources, "+UI");
Assert.IsFalse (hpa.Unrestricted, "Unrestricted-18");
}
[Test]
public void Attributes ()
{
Type t = typeof (HostProtectionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Delegate);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}
#endif

View File

@@ -0,0 +1,197 @@
//
// IBuiltInPermissionTest.cs - NUnit Test Cases for IBuiltInPermission
//
// Author:
// Sebastien Pouliot <sebastien@ximian.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.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class IBuiltInPermissionTest {
// IBuiltInPermission is internal but we can test it's values
// using reflection.
private int GetTokenIndex (IPermission p)
{
Type t = p.GetType ();
int result = (int) t.InvokeMember ("System.Security.Permissions.IBuiltInPermission.GetTokenIndex",
BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
null, p, null);
return result;
}
[Test]
public void Environment ()
{
IPermission p = (IPermission) new EnvironmentPermission (PermissionState.None);
Assert.AreEqual (0, GetTokenIndex (p));
}
[Test]
public void FileDialog ()
{
IPermission p = (IPermission) new FileDialogPermission (PermissionState.None);
Assert.AreEqual (1, GetTokenIndex (p));
}
[Test]
public void FileIO ()
{
IPermission p = (IPermission) new FileIOPermission (PermissionState.None);
Assert.AreEqual (2, GetTokenIndex (p));
}
[Test]
public void IsolatedStorageFile ()
{
IPermission p = (IPermission) new IsolatedStorageFilePermission (PermissionState.None);
Assert.AreEqual (3, GetTokenIndex (p));
}
[Test]
public void Reflection ()
{
IPermission p = (IPermission) new ReflectionPermission (PermissionState.None);
Assert.AreEqual (4, GetTokenIndex (p));
}
[Test]
public void Registry ()
{
IPermission p = (IPermission) new RegistryPermission (PermissionState.None);
Assert.AreEqual (5, GetTokenIndex (p));
}
[Test]
public void Security ()
{
IPermission p = (IPermission) new SecurityPermission (PermissionState.None);
Assert.AreEqual (6, GetTokenIndex (p));
}
[Test]
public void UI ()
{
IPermission p = (IPermission) new UIPermission (PermissionState.None);
Assert.AreEqual (7, GetTokenIndex (p));
}
[Test]
public void Principal ()
{
IPermission p = (IPermission) new PrincipalPermission (PermissionState.None);
Assert.AreEqual (8, GetTokenIndex (p));
}
[Test]
#if MOBILE
[Ignore]
#endif
public void HostProtection ()
{
HostProtectionAttribute hpa = new HostProtectionAttribute ();
// internal permission
IPermission p = hpa.CreatePermission ();
Assert.AreEqual (9, GetTokenIndex (p));
}
[Test]
public void PublisherIdentity ()
{
IPermission p = (IPermission) new PublisherIdentityPermission (PermissionState.None);
#if NET_2_0
Assert.AreEqual (10, GetTokenIndex (p));
#else
Assert.AreEqual (9, GetTokenIndex (p));
#endif
}
[Test]
public void SiteIdentity ()
{
IPermission p = (IPermission) new SiteIdentityPermission (PermissionState.None);
#if NET_2_0
Assert.AreEqual (11, GetTokenIndex (p));
#else
Assert.AreEqual (10, GetTokenIndex (p));
#endif
}
[Test]
public void StrongNameIdentity ()
{
IPermission p = (IPermission) new StrongNameIdentityPermission (PermissionState.None);
#if NET_2_0
Assert.AreEqual (12, GetTokenIndex (p));
#else
Assert.AreEqual (11, GetTokenIndex (p));
#endif
}
[Test]
public void UrlIdentity ()
{
IPermission p = (IPermission) new UrlIdentityPermission (PermissionState.None);
#if NET_2_0
Assert.AreEqual (13, GetTokenIndex (p));
#else
Assert.AreEqual (12, GetTokenIndex (p));
#endif
}
[Test]
public void ZoneIdentity ()
{
IPermission p = (IPermission) new ZoneIdentityPermission (PermissionState.None);
#if NET_2_0
Assert.AreEqual (14, GetTokenIndex (p));
#else
Assert.AreEqual (13, GetTokenIndex (p));
#endif
}
#if NET_2_0
[Test]
public void GacIdentity ()
{
IPermission p = (IPermission) new GacIdentityPermission (PermissionState.None);
Assert.AreEqual (15, GetTokenIndex (p));
}
[Test]
public void KeyContainer ()
{
IPermission p = (IPermission)new KeyContainerPermission (PermissionState.None);
Assert.AreEqual (16, GetTokenIndex (p));
}
#endif
}
}

View File

@@ -0,0 +1,150 @@
//
// IsolatedStorageFilePermissionAttributeTest.cs - NUnit Test Cases for IsolatedStorageFilePermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class IsolatedStorageFilePermissionAttributeTest {
[Test]
public void Default ()
{
IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (IsolatedStorageContainment.None, a.UsageAllowed, "UsageAllowed");
Assert.AreEqual (0, a.UserQuota, "UserQuota");
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
IsolatedStorageFilePermission perm = (IsolatedStorageFilePermission) a.CreatePermission ();
Assert.AreEqual (IsolatedStorageContainment.None, perm.UsageAllowed, "CreatePermission-UsageAllowed");
Assert.AreEqual (0, perm.UserQuota, "CreatePermission-UserQuota");
}
[Test]
public void Action ()
{
IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void UsageAllowed ()
{
IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (IsolatedStorageContainment.None, a.UsageAllowed, "UsageAllowed=None");
a.UsageAllowed = IsolatedStorageContainment.AdministerIsolatedStorageByUser;
Assert.AreEqual (IsolatedStorageContainment.AdministerIsolatedStorageByUser, a.UsageAllowed, "UsageAllowed=AdministerIsolatedStorageByUser");
a.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByRoamingUser;
Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByRoamingUser, a.UsageAllowed, "UsageAllowed=AssemblyIsolationByRoamingUser");
a.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser;
Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByUser, a.UsageAllowed, "UsageAllowed=AssemblyIsolationByUser");
a.UsageAllowed = IsolatedStorageContainment.DomainIsolationByRoamingUser;
Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByRoamingUser, a.UsageAllowed, "UsageAllowed=DomainIsolationByRoamingUser");
a.UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser;
Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByUser, a.UsageAllowed, "UsageAllowed=DomainIsolationByUser");
a.UsageAllowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
Assert.AreEqual (IsolatedStorageContainment.UnrestrictedIsolatedStorage, a.UsageAllowed, "UsageAllowed=UnrestrictedIsolatedStorage");
}
[Test]
public void UsageAllowed_Invalid ()
{
IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
a.UsageAllowed = (IsolatedStorageContainment)Int32.MinValue;
// no validation in attribute
}
[Test]
public void UserQuota ()
{
IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (0, a.UserQuota, "UserQuota=default");
a.UserQuota = Int64.MinValue;
Assert.AreEqual (Int64.MinValue, a.UserQuota, "UserQuota=MinValue");
a.UserQuota = Int64.MaxValue;
Assert.AreEqual (Int64.MaxValue, a.UserQuota, "UserQuota=MaxValue");
}
[Test]
public void Unrestricted ()
{
IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
IsolatedStorageFilePermission perm = (IsolatedStorageFilePermission) a.CreatePermission ();
Assert.IsTrue (perm.IsUnrestricted (), "CreatePermission.IsUnrestricted");
Assert.AreEqual (IsolatedStorageContainment.UnrestrictedIsolatedStorage, perm.UsageAllowed, "CreatePermission.UsageAllowed");
Assert.AreEqual (Int64.MaxValue, perm.UserQuota, "CreatePermission.UserQuota");
}
[Test]
public void Attributes ()
{
IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
Type t = typeof (IsolatedStorageFilePermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,400 @@
//
// IsolatedStorageFilePermissionTest.cs - NUnit Test Cases for IsolatedStorageFilePermission
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class IsolatedStorageFilePermissionTest {
[Test]
public void PermissionStateNone ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
Assert.AreEqual (IsolatedStorageContainment.None, isfp.UsageAllowed, "UsageAllowed");
Assert.AreEqual (0, isfp.UserQuota, "UserQuota");
SecurityElement se = isfp.ToXml ();
// only class and version are present
Assert.AreEqual ("None", se.Attribute ("Allowed"), "Xml-Allowed");
Assert.IsNull (se.Children, "Xml-Children");
IsolatedStorageFilePermission copy = (IsolatedStorageFilePermission)isfp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (isfp, copy), "ReferenceEquals");
Assert.AreEqual (isfp.UsageAllowed, copy.UsageAllowed, "UsageAllowed");
Assert.AreEqual (isfp.UserQuota, copy.UserQuota, "UserQuota");
}
[Test]
public void PermissionStateUnrestricted ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.Unrestricted);
Assert.AreEqual (IsolatedStorageContainment.UnrestrictedIsolatedStorage, isfp.UsageAllowed, "UsageAllowed");
Assert.AreEqual (Int64.MaxValue, isfp.UserQuota, "UserQuota");
SecurityElement se = isfp.ToXml ();
// only class and version are present
Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "Xml-Unrestricted");
Assert.IsNull (se.Children, "Xml-Children");
IsolatedStorageFilePermission copy = (IsolatedStorageFilePermission)isfp.Copy ();
Assert.IsFalse (Object.ReferenceEquals (isfp, copy), "ReferenceEquals");
Assert.AreEqual (isfp.UsageAllowed, copy.UsageAllowed, "UsageAllowed");
Assert.AreEqual (isfp.UserQuota, copy.UserQuota, "UserQuota");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void PermissionStateInvalid ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission ((PermissionState)2);
}
[Test]
public void Intersect ()
{
IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None);
IsolatedStorageFilePermission intersect = (IsolatedStorageFilePermission)empty.Intersect (null);
Assert.IsNull (intersect, "empty N null");
intersect = (IsolatedStorageFilePermission)empty.Intersect (empty);
Assert.IsNull (intersect, "empty N empty");
IsolatedStorageFilePermission unrestricted = new IsolatedStorageFilePermission (PermissionState.Unrestricted);
intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (null);
Assert.IsNull (intersect, "unrestricted N null");
intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (empty);
Assert.IsNotNull (intersect, "unrestricted N empty");
intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (unrestricted);
Assert.IsNotNull (intersect, "unrestricted N unrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Intersect_DifferentPermissions ()
{
IsolatedStorageFilePermission a = new IsolatedStorageFilePermission (PermissionState.None);
SecurityPermission b = new SecurityPermission (PermissionState.None);
a.Intersect (b);
}
[Test]
public void IsSubsetOf ()
{
IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None);
Assert.IsTrue (empty.IsSubsetOf (null), "empty.IsSubsetOf (null)");
IsolatedStorageFilePermission unrestricted = new IsolatedStorageFilePermission (PermissionState.Unrestricted);
Assert.IsFalse (unrestricted.IsSubsetOf (null), "unrestricted.IsSubsetOf (null)");
Assert.IsFalse (unrestricted.IsSubsetOf (empty), "unrestricted.IsSubsetOf (empty)");
Assert.IsTrue (empty.IsSubsetOf (unrestricted), "empty.IsSubsetOf (unrestricted)");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsSubsetOf_DifferentPermissions ()
{
IsolatedStorageFilePermission a = new IsolatedStorageFilePermission (PermissionState.None);
SecurityPermission b = new SecurityPermission (PermissionState.None);
a.IsSubsetOf (b);
}
[Test]
public void Union ()
{
IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None);
IsolatedStorageFilePermission union = (IsolatedStorageFilePermission)empty.Union (null);
Assert.IsNotNull (union, "empty U null");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-1");
Assert.IsFalse (Object.ReferenceEquals (empty, union), "ReferenceEquals-1");
union = (IsolatedStorageFilePermission)empty.Union (empty);
Assert.IsNotNull (union, "empty U empty");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-2");
Assert.IsFalse (Object.ReferenceEquals (empty, union), "ReferenceEquals-2");
IsolatedStorageFilePermission unrestricted = new IsolatedStorageFilePermission (PermissionState.Unrestricted);
union = (IsolatedStorageFilePermission)unrestricted.Union (null);
Assert.IsNotNull (union, "unrestricted U null");
Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-3");
Assert.IsFalse (Object.ReferenceEquals (unrestricted, union), "ReferenceEquals-3");
union = (IsolatedStorageFilePermission)unrestricted.Union (empty);
Assert.IsNotNull (union, "unrestricted U empty");
Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-4");
Assert.IsFalse (Object.ReferenceEquals (unrestricted, union), "ReferenceEquals-4");
union = (IsolatedStorageFilePermission)unrestricted.Union (unrestricted);
Assert.IsNotNull (union, "unrestricted U unrestricted");
Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-5");
Assert.IsFalse (Object.ReferenceEquals (unrestricted, union), "ReferenceEquals-5");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Union_DifferentPermissions ()
{
IsolatedStorageFilePermission a = new IsolatedStorageFilePermission (PermissionState.None);
SecurityPermission b = new SecurityPermission (PermissionState.None);
a.Union (b);
}
[Test]
public void UsageAllowedQuota ()
{
IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None);
IsolatedStorageFilePermission small = new IsolatedStorageFilePermission (PermissionState.None);
small.UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser;
small.UserQuota = 1;
IsolatedStorageFilePermission union = (IsolatedStorageFilePermission)empty.Union (small);
Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByUser, union.UsageAllowed, "DomainIsolationByUser");
Assert.AreEqual (1, union.UserQuota, "1");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-1");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-1a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-1b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-1c");
IsolatedStorageFilePermission intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-1");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-1");
small.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser;
small.UserQuota = 2;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByUser, union.UsageAllowed, "AssemblyIsolationByUser");
Assert.AreEqual (2, union.UserQuota, "2");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-2");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-2a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-2b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-2c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-2");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-2");
#if NET_2_0
small.UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByUser;
small.UserQuota = 3;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByUser, union.UsageAllowed, "ApplicationIsolationByUser");
Assert.AreEqual (3, union.UserQuota, "3");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-3");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-3a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-3b");
Assert.IsFalse (union.IsSubsetOf (small), "IsSubset-3c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-3");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-3");
small.UsageAllowed = IsolatedStorageContainment.DomainIsolationByMachine;
small.UserQuota = 4;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByMachine, union.UsageAllowed, "DomainIsolationByMachine");
Assert.AreEqual (4, union.UserQuota, "4");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-4");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-4a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-4b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-4c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-4");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-4");
small.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByMachine;
small.UserQuota = 5;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByMachine, union.UsageAllowed, "AssemblyIsolationByMachine");
Assert.AreEqual (5, union.UserQuota, "5");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-5");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-5a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-5b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-5c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-5");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-5");
small.UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByMachine;
small.UserQuota = 6;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.ApplicationIsolationByMachine, union.UsageAllowed, "ApplicationIsolationByMachine");
Assert.AreEqual (6, union.UserQuota, "6");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-6");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-6a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-6b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-6c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-6");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-6");
#endif
small.UsageAllowed = IsolatedStorageContainment.DomainIsolationByRoamingUser;
small.UserQuota = 7;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByRoamingUser, union.UsageAllowed, "DomainIsolationByRoamingUser");
Assert.AreEqual (7, union.UserQuota, "7a");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-7a");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-7a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-7b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-7c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-7");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-7");
// can't go back ;-)
small.UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser;
small.UserQuota = 1;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByRoamingUser, union.UsageAllowed, "DomainIsolationByRoamingUser");
Assert.AreEqual (7, union.UserQuota, "7b");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-7b");
small.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByRoamingUser;
small.UserQuota = 7; // no change
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByRoamingUser, union.UsageAllowed, "AssemblyIsolationByRoamingUser");
Assert.AreEqual (7, union.UserQuota, "7c");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-7c");
#if NET_2_0
small.UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByRoamingUser;
small.UserQuota = 8;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.ApplicationIsolationByRoamingUser, union.UsageAllowed, "ApplicationIsolationByRoamingUser");
Assert.AreEqual (8, union.UserQuota, "8");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-8");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-8a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-8b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-8c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-8");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-8");
#endif
small.UsageAllowed = IsolatedStorageContainment.AdministerIsolatedStorageByUser;
small.UserQuota = 9;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.AdministerIsolatedStorageByUser, union.UsageAllowed, "AdministerIsolatedStorageByUser");
Assert.AreEqual (9, union.UserQuota, "9");
Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-9");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-9a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-9b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-9c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-9");
Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-9");
small.UsageAllowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
small.UserQuota = 10;
union = (IsolatedStorageFilePermission)union.Union (small);
Assert.AreEqual (IsolatedStorageContainment.UnrestrictedIsolatedStorage, union.UsageAllowed, "UnrestrictedIsolatedStorage");
Assert.AreEqual (Int64.MaxValue, union.UserQuota, "10");
Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-10");
Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-10a");
Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-10b");
Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-10c");
intersect = (IsolatedStorageFilePermission)union.Intersect (small);
Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-10");
Assert.IsFalse ((small.UserQuota == intersect.UserQuota), "Intersect-UserQuota-10");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXml_Null ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
isfp.FromXml (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongTag ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
SecurityElement se = isfp.ToXml ();
se.Tag = "IMono";
isfp.FromXml (se);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongTagCase ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
SecurityElement se = isfp.ToXml ();
se.Tag = "IPERMISSION"; // instead of IPermission
isfp.FromXml (se);
}
[Test]
public void FromXml_WrongClass ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
SecurityElement se = isfp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
w.AddAttribute ("version", se.Attribute ("version"));
isfp.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 ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
SecurityElement se = isfp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("version", se.Attribute ("version"));
isfp.FromXml (w);
// doesn't even care of the class attribute presence
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXml_WrongVersion ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
SecurityElement se = isfp.ToXml ();
se.Attributes.Remove ("version");
se.Attributes.Add ("version", "2");
isfp.FromXml (se);
}
[Test]
public void FromXml_NoVersion ()
{
IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None);
SecurityElement se = isfp.ToXml ();
SecurityElement w = new SecurityElement (se.Tag);
w.AddAttribute ("class", se.Attribute ("class"));
isfp.FromXml (w);
}
}
}

View File

@@ -0,0 +1,114 @@
//
// IsolatedStoragePermissionAttributeTest.cs -
// NUnit Test Cases for IsolateStoragePermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
// note: IsolateStoragePermissionAttribute is abstract so we define our own to test
// no [Serialize] or [AttributeUsage] here to test their inheritance
public class NonAbstractIsolatedStoragePermissionAttribute : IsolatedStoragePermissionAttribute {
public NonAbstractIsolatedStoragePermissionAttribute (SecurityAction action)
: base (action)
{
}
public override IPermission CreatePermission ()
{
return null;
}
}
[TestFixture]
public class IsolatedStoragePermissionAttributeTest {
[Test]
public void Action ()
{
NonAbstractIsolatedStoragePermissionAttribute a = new NonAbstractIsolatedStoragePermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
NonAbstractIsolatedStoragePermissionAttribute a = new NonAbstractIsolatedStoragePermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void Unrestricted ()
{
NonAbstractIsolatedStoragePermissionAttribute a = new NonAbstractIsolatedStoragePermissionAttribute (SecurityAction.Assert);
Assert.IsFalse (a.Unrestricted, "Unrestricted (default)");
a.Unrestricted = true;
Assert.IsTrue (a.Unrestricted, "Unrestricted (true)");
a.Unrestricted = false;
Assert.IsFalse (a.Unrestricted, "Unrestricted (false)");
}
[Test]
public void Attributes ()
{
Type t = typeof (NonAbstractIsolatedStoragePermissionAttribute);
Assert.IsFalse (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (0, attrs.Length, "AttributeUsage-false");
attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), true);
Assert.AreEqual (1, attrs.Length, "AttributeUsage-true");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,207 @@
//
// KeyContainerPermissionAttributeTest.cs -
// NUnit Test Cases for KeyContainerPermissionAttributeTest
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class KeyContainerPermissionAttributeTest {
[Test]
[Category ("NotWorking")]
public void Default ()
{
KeyContainerPermissionAttribute a = new KeyContainerPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (KeyContainerPermissionFlags.NoFlags, a.Flags, "Flags");
Assert.IsNull (a.KeyContainerName, "KeyContainerName");
Assert.AreEqual (-1, a.KeySpec, "KeySpec");
Assert.IsNull (a.KeyStore, "KeyStore");
Assert.IsNull (a.ProviderName, "ProviderName");
Assert.AreEqual (-1, a.ProviderType, "ProviderType");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
KeyContainerPermission perm = (KeyContainerPermission)a.CreatePermission ();
Assert.AreEqual (KeyContainerPermissionFlags.NoFlags, perm.Flags, "perm.Flags");
Assert.IsFalse (perm.IsUnrestricted (), "perm.Unrestricted");
}
[Test]
public void Action ()
{
KeyContainerPermissionAttribute a = new KeyContainerPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
KeyContainerPermissionAttribute a = new KeyContainerPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
private KeyContainerPermissionAttribute Empty ()
{
return new KeyContainerPermissionAttribute (SecurityAction.Assert);
}
[Test]
public void KeyContainerName ()
{
KeyContainerPermissionAttribute a = Empty ();
a.KeyContainerName = "mono";
Assert.AreEqual ("mono", a.KeyContainerName, "KeyContainerName-1");
a.KeyContainerName = null;
Assert.IsNull (a.KeyContainerName, "KeyContainerName-2");
a.KeyContainerName = String.Empty;
Assert.AreEqual (String.Empty, a.KeyContainerName, "KeyContainerName-3");
Assert.AreEqual (KeyContainerPermissionFlags.NoFlags, a.Flags, "Flags");
}
[Test]
public void KeySpec ()
{
KeyContainerPermissionAttribute a = Empty ();
a.KeySpec = Int32.MinValue;
Assert.AreEqual (Int32.MinValue, a.KeySpec, "KeySpec-1");
a.KeySpec = 0;
Assert.AreEqual (0, a.KeySpec, "KeySpec-2");
a.KeySpec = Int32.MaxValue;
Assert.AreEqual (Int32.MaxValue, a.KeySpec, "KeySpec-3");
Assert.AreEqual (KeyContainerPermissionFlags.NoFlags, a.Flags, "Flags");
}
[Test]
public void KeyStore ()
{
KeyContainerPermissionAttribute a = Empty ();
a.KeyStore = "mono";
Assert.AreEqual ("mono", a.KeyStore, "KeyStore-1");
a.KeyStore = null;
Assert.IsNull (a.KeyStore, "KeyStore-2");
a.KeyStore = String.Empty;
Assert.AreEqual (String.Empty, a.KeyStore, "KeyStore-3");
Assert.AreEqual (KeyContainerPermissionFlags.NoFlags, a.Flags, "Flags");
}
[Test]
public void ProviderName ()
{
KeyContainerPermissionAttribute a = Empty ();
a.ProviderName = "mono";
Assert.AreEqual ("mono", a.ProviderName, "ProviderName-1");
a.ProviderName = null;
Assert.IsNull (a.ProviderName, "ProviderName-2");
a.ProviderName = String.Empty;
Assert.AreEqual (String.Empty, a.ProviderName, "ProviderName-3");
Assert.AreEqual (KeyContainerPermissionFlags.NoFlags, a.Flags, "Flags");
}
[Test]
public void ProviderType ()
{
KeyContainerPermissionAttribute a = Empty ();
a.ProviderType = Int32.MinValue;
Assert.AreEqual (Int32.MinValue, a.ProviderType, "ProviderType-1");
a.ProviderType = 0;
Assert.AreEqual (0, a.ProviderType, "ProviderType-2");
a.ProviderType = Int32.MaxValue;
Assert.AreEqual (Int32.MaxValue, a.ProviderType, "ProviderType-3");
Assert.AreEqual (KeyContainerPermissionFlags.NoFlags, a.Flags, "Flags");
}
[Test]
public void Unrestricted ()
{
KeyContainerPermissionAttribute a = Empty ();
a.Unrestricted = true;
Assert.AreEqual (KeyContainerPermissionFlags.NoFlags, a.Flags, "Flags");
KeyContainerPermission perm = (KeyContainerPermission)a.CreatePermission ();
Assert.AreEqual (KeyContainerPermissionFlags.AllFlags, perm.Flags, "CreatePermission.Flags");
}
[Test]
public void Flags ()
{
KeyContainerPermissionAttribute a = Empty ();
a.Flags = KeyContainerPermissionFlags.AllFlags;
Assert.IsFalse (a.Unrestricted, "Unrestricted");
Assert.AreEqual (KeyContainerPermissionFlags.AllFlags, a.Flags, "Flags");
}
[Test]
public void Flags_Invalid ()
{
KeyContainerPermissionAttribute a = Empty ();
a.Flags = ((KeyContainerPermissionFlags)Int32.MinValue);
// no validations for flags
}
[Test]
public void Attributes ()
{
Type t = typeof (KeyContainerPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}
#endif

View File

@@ -0,0 +1,262 @@
//
// PermissionSetAttributeTest.cs - NUnit Test Cases for PermissionSetAttribute
//
// 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.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
#if MOBILE
[Ignore]
#endif
public class PermissionSetAttributeTest {
[Test]
public void Default ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
Assert.IsNull (a.File, "File");
#if NET_2_0
Assert.IsNull (a.Hex, "Hex");
#endif
Assert.IsNull (a.Name, "Name");
Assert.IsNull (a.XML, "XML");
Assert.IsFalse (a.UnicodeEncoded, "UnicodeEncoded");
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
IPermission perm = a.CreatePermission ();
Assert.IsNull (perm, "CreatePermission");
PermissionSet ps = a.CreatePermissionSet ();
Assert.AreEqual (0, ps.Count, "CreatePermissionSet");
}
[Test]
public void Action ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
PermissionSetAttribute a = new PermissionSetAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void File ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.File = "mono";
Assert.AreEqual ("mono", a.File, "File");
#if NET_2_0
Assert.IsNull (a.Hex, "Hex");
#endif
Assert.IsNull (a.Name, "Name");
Assert.IsNull (a.XML, "XML");
a.File = null;
Assert.IsNull (a.File, "File");
#if NET_2_0
Assert.IsNull (a.Hex, "Hex");
#endif
Assert.IsNull (a.Name, "Name");
Assert.IsNull (a.XML, "XML");
}
#if NET_2_0
[Test]
public void Hex ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
Assert.IsNull (a.Hex, "Hex-1");
a.Hex = String.Empty;
Assert.AreEqual (String.Empty, a.Hex, "Hex-2");
a.Hex = null;
Assert.IsNull (a.Hex, "Hex-3");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Hex_Bad ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.Hex = "g";
Assert.AreEqual ("g", a.Hex, "Bad Hex");
a.CreatePermissionSet ();
}
[Test]
public void Hex_ASCII_Permission ()
{
SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Assertion);
PermissionSet ps = new PermissionSet (PermissionState.None);
ps.AddPermission (sp);
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.Hex = "3C5065726D697373696F6E53657420636C6173733D2253797374656D2E53656375726974792E5065726D697373696F6E536574220D0A76657273696F6E3D2231223E0D0A3C495065726D697373696F6E20636C6173733D2253797374656D2E53656375726974792E5065726D697373696F6E732E53656375726974795065726D697373696F6E2C206D73636F726C69622C2056657273696F6E3D322E302E333630302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D62373761356335363139333465303839220D0A76657273696F6E3D2231220D0A466C6167733D22417373657274696F6E222F3E0D0A3C2F5065726D697373696F6E5365743E0D0A";
PermissionSet psa = a.CreatePermissionSet ();
Assert.IsTrue (ps.Equals (psa), "HEX-ASCII");
}
[Test]
[ExpectedException (typeof (XmlSyntaxException))]
public void Hex_Unicode_Permission ()
{
SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Assertion);
PermissionSet ps = new PermissionSet (PermissionState.None);
ps.AddPermission (sp);
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.UnicodeEncoded = true;
a.Hex = "3C005000650072006D0069007300730069006F006E00530065007400200063006C006100730073003D002200530079007300740065006D002E00530065006300750072006900740079002E005000650072006D0069007300730069006F006E0053006500740022000D000A00760065007200730069006F006E003D002200310022003E000D000A003C0049005000650072006D0069007300730069006F006E00200063006C006100730073003D002200530079007300740065006D002E00530065006300750072006900740079002E005000650072006D0069007300730069006F006E0073002E00530065006300750072006900740079005000650072006D0069007300730069006F006E002C0020006D00730063006F0072006C00690062002C002000560065007200730069006F006E003D0032002E0030002E0033003600300030002E0030002C002000430075006C0074007500720065003D006E00650075007400720061006C002C0020005000750062006C00690063004B006500790054006F006B0065006E003D00620037003700610035006300350036003100390033003400650030003800390022000D000A00760065007200730069006F006E003D002200310022000D000A0046006C006100670073003D00220041007300730065007200740069006F006E0022002F003E000D000A003C002F005000650072006D0069007300730069006F006E005300650074003E000D000A00";
PermissionSet psu = a.CreatePermissionSet();
Assert.IsTrue(ps.Equals(psu), "HEX-UNICODE");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void Hex_BigEndianUnicode_Permission ()
{
SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Assertion);
PermissionSet ps = new PermissionSet (PermissionState.None);
ps.AddPermission (sp);
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.UnicodeEncoded = true;
a.Hex = "003C005000650072006D0069007300730069006F006E00530065007400200063006C006100730073003D002200530079007300740065006D002E00530065006300750072006900740079002E005000650072006D0069007300730069006F006E0053006500740022000D000A00760065007200730069006F006E003D002200310022003E000D000A003C0049005000650072006D0069007300730069006F006E00200063006C006100730073003D002200530079007300740065006D002E00530065006300750072006900740079002E005000650072006D0069007300730069006F006E0073002E00530065006300750072006900740079005000650072006D0069007300730069006F006E002C0020006D00730063006F0072006C00690062002C002000560065007200730069006F006E003D0032002E0030002E0033003600300030002E0030002C002000430075006C0074007500720065003D006E00650075007400720061006C002C0020005000750062006C00690063004B006500790054006F006B0065006E003D00620037003700610035006300350036003100390033003400650030003800390022000D000A00760065007200730069006F006E003D002200310022000D000A0046006C006100670073003D00220041007300730065007200740069006F006E0022002F003E000D000A003C002F005000650072006D0069007300730069006F006E005300650074003E000D000";
PermissionSet psbeu = a.CreatePermissionSet ();
Assert.IsTrue (ps.Equals (psbeu), "HEX-BIGENDIAN-UNICODE");
}
#endif
[Test]
public void Name ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.Name = "mono";
Assert.IsNull (a.File, "File");
#if NET_2_0
Assert.IsNull (a.Hex, "Hex");
#endif
Assert.AreEqual ("mono", a.Name, "Name");
Assert.IsNull (a.XML, "XML");
a.Name = null;
Assert.IsNull (a.File, "File");
#if NET_2_0
Assert.IsNull (a.Hex, "Hex");
#endif
Assert.IsNull (a.Name, "Name");
Assert.IsNull (a.XML, "XML");
}
[Test]
public void XML ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.XML = "mono";
Assert.IsNull (a.File, "File");
#if NET_2_0
Assert.IsNull (a.Hex, "Hex");
#endif
Assert.IsNull (a.Name, "Name");
Assert.AreEqual ("mono", a.XML, "XML");
a.XML = null;
Assert.IsNull (a.File, "File");
#if NET_2_0
Assert.IsNull (a.Hex, "Hex");
#endif
Assert.IsNull (a.Name, "Name");
Assert.IsNull (a.XML, "XML");
}
[Test]
public void UnicodeEncoded ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.UnicodeEncoded = true;
Assert.IsTrue (a.UnicodeEncoded, "UnicodeEncoded-true");
a.UnicodeEncoded = false;
Assert.IsFalse (a.UnicodeEncoded, "UnicodeEncoded-false");
}
[Test]
public void Unrestricted ()
{
PermissionSetAttribute a = new PermissionSetAttribute (SecurityAction.Assert);
a.Unrestricted = true;
Assert.IsNull (a.File, "File");
#if NET_2_0
Assert.IsNull (a.Hex, "Hex");
#endif
Assert.IsNull (a.Name, "Name");
Assert.IsNull (a.XML, "XML");
PermissionSet ps = a.CreatePermissionSet ();
Assert.IsTrue (ps.IsUnrestricted (), "CreatePermissionSet.IsUnrestricted");
}
[Test]
public void Attributes ()
{
Type t = typeof (PermissionSetAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,224 @@
//
// PrincipalPermissionAttributeTest.cs - NUnit Test Cases for PrincipalPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class PrincipalPermissionAttributeTest {
private static string user = "user";
private static string role = "role";
[Test]
public void Default ()
{
PrincipalPermissionAttribute a = new PrincipalPermissionAttribute (SecurityAction.Assert);
Assert.IsNull (a.Name, "Name");
Assert.IsNull (a.Role, "Role");
Assert.IsTrue (a.Authenticated, "Authenticated");
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
PrincipalPermission perm = (PrincipalPermission) a.CreatePermission ();
Assert.IsNotNull (perm, "CreatePermission");
}
[Test]
public void Action ()
{
PrincipalPermissionAttribute a = new PrincipalPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
PrincipalPermissionAttribute a = new PrincipalPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void NameNullRoleNullAuthenticated ()
{
PrincipalPermissionAttribute attr = new PrincipalPermissionAttribute (SecurityAction.Assert);
attr.Name = null;
attr.Role = null;
attr.Authenticated = true;
Assert.IsNull (attr.Name, "NameNullRoleNullAuthenticated.Name");
Assert.IsNull (attr.Role, "NameNullRoleNullAuthenticated.Role");
Assert.IsTrue (attr.Authenticated, "NameNullRoleNullAuthenticated.Authenticated");
PrincipalPermission p = (PrincipalPermission) attr.CreatePermission ();
Assert.IsTrue (p.IsUnrestricted (), "NameNullRoleNullAuthenticated.IsUnrestricted");
}
[Test]
public void NameNullRoleNullNonAuthenticated ()
{
PrincipalPermissionAttribute attr = new PrincipalPermissionAttribute (SecurityAction.Assert);
attr.Name = null;
attr.Role = null;
attr.Authenticated = false;
Assert.IsNull (attr.Name, "NameNullRoleNullNonAuthenticated.Name");
Assert.IsNull (attr.Role, "NameNullRoleNullNonAuthenticated.Role");
Assert.IsFalse (attr.Authenticated, "NameNullRoleNullNonAuthenticated.Authenticated");
PrincipalPermission p = (PrincipalPermission) attr.CreatePermission ();
Assert.IsFalse (p.IsUnrestricted (), "NameNullRoleNullNonAuthenticated.IsUnrestricted");
}
[Test]
public void NameRoleNullAuthenticated ()
{
PrincipalPermissionAttribute attr = new PrincipalPermissionAttribute (SecurityAction.Assert);
attr.Name = user;
attr.Role = null;
attr.Authenticated = true;
Assert.AreEqual (user, attr.Name, "NameRoleNullAuthenticated.Name");
Assert.IsNull (attr.Role, "NameRoleNullAuthenticated.Role");
Assert.IsTrue (attr.Authenticated, "NameRoleNullAuthenticated.Authenticated");
PrincipalPermission p = (PrincipalPermission) attr.CreatePermission ();
Assert.IsFalse (p.IsUnrestricted (), "NameRoleNullAuthenticated.IsUnrestricted");
}
[Test]
public void NameRoleNullNonAuthenticated ()
{
PrincipalPermissionAttribute attr = new PrincipalPermissionAttribute (SecurityAction.Assert);
attr.Name = user;
attr.Role = null;
attr.Authenticated = false;
Assert.AreEqual (user, attr.Name, "NameRoleNullNonAuthenticated.Name");
Assert.IsNull (attr.Role, "NameRoleNullNonAuthenticated.Role");
Assert.IsFalse (attr.Authenticated, "NameRoleNullNonAuthenticated.Authenticated");
PrincipalPermission p = (PrincipalPermission) attr.CreatePermission ();
Assert.IsFalse (p.IsUnrestricted (), "NameRoleNullNonAuthenticated.IsUnrestricted");
}
[Test]
public void NameNullRoleAuthenticated ()
{
PrincipalPermissionAttribute attr = new PrincipalPermissionAttribute (SecurityAction.Assert);
attr.Name = null;
attr.Role = role;
attr.Authenticated = true;
Assert.IsNull (attr.Name, "NameNullRoleAuthenticated.Name");
Assert.AreEqual (role, attr.Role, "NameNullRoleAuthenticated.Role");
Assert.IsTrue (attr.Authenticated, "NameNullRoleAuthenticated.Authenticated");
PrincipalPermission p = (PrincipalPermission) attr.CreatePermission ();
Assert.IsFalse (p.IsUnrestricted (), "NameNullRoleAuthenticated.IsUnrestricted");
}
[Test]
public void NameNullRoleNonAuthenticated ()
{
PrincipalPermissionAttribute attr = new PrincipalPermissionAttribute (SecurityAction.Assert);
attr.Name = null;
attr.Role = role;
attr.Authenticated = false;
Assert.IsNull (attr.Name, "NameNullRoleNonAuthenticated.Name");
Assert.AreEqual (role, attr.Role, "NameNullRoleNonAuthenticated.Role");
Assert.IsFalse (attr.Authenticated, "NameNullRoleNonAuthenticated.Authenticated");
PrincipalPermission p = (PrincipalPermission) attr.CreatePermission ();
Assert.IsFalse (p.IsUnrestricted (), "NameNullRoleNonAuthenticated.IsUnrestricted");
}
[Test]
public void NameRoleAuthenticated ()
{
PrincipalPermissionAttribute attr = new PrincipalPermissionAttribute (SecurityAction.Assert);
attr.Name = user;
attr.Role = role;
attr.Authenticated = true;
Assert.AreEqual (user, attr.Name, "NameRoleAuthenticated.Name");
Assert.AreEqual (role, attr.Role, "NameRoleAuthenticated.Role");
Assert.IsTrue (attr.Authenticated, "NameRoleAuthenticated.Authenticated");
PrincipalPermission p = (PrincipalPermission) attr.CreatePermission ();
Assert.IsFalse (p.IsUnrestricted (), "NameRoleAuthenticated.IsUnrestricted");
}
[Test]
public void NameRoleNonAuthenticated ()
{
PrincipalPermissionAttribute attr = new PrincipalPermissionAttribute (SecurityAction.Assert);
attr.Name = user;
attr.Role = role;
attr.Authenticated = false;
Assert.AreEqual (user, attr.Name, "NameRoleNonAuthenticated.Name");
Assert.AreEqual (role, attr.Role, "NameRoleNonAuthenticated.Role");
Assert.IsFalse (attr.Authenticated, "NameRoleNonAuthenticated.Authenticated");
PrincipalPermission p = (PrincipalPermission) attr.CreatePermission ();
Assert.IsFalse (p.IsUnrestricted (), "NameRoleNonAuthenticated.IsUnrestricted");
}
[Test]
public void Unrestricted ()
{
PrincipalPermissionAttribute a = new PrincipalPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
PrincipalPermission perm = (PrincipalPermission) a.CreatePermission ();
Assert.IsTrue (perm.IsUnrestricted (), "CreatePermission.IsUnrestricted");
}
[Test]
public void Attributes ()
{
Type t = typeof (PrincipalPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object[] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Class | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

View File

@@ -0,0 +1,329 @@
//
// PrincipalPermissionTest.cs - NUnit Test Cases for PrincipalPermission
//
// Author:
// Sebastien Pouliot (spouliot@motus.com)
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class PrincipalPermissionTest {
private static string className = "System.Security.Permissions.PrincipalPermission, ";
[Test]
public void PermissionStateNone ()
{
PrincipalPermission p = new PrincipalPermission (PermissionState.None);
Assert.IsNotNull (p, "PrincipalPermission(PermissionState.None)");
Assert.IsTrue (!p.IsUnrestricted (), "IsUnrestricted");
PrincipalPermission copy = (PrincipalPermission) p.Copy ();
Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
SecurityElement se = p.ToXml ();
Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class");
Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version");
}
[Test]
public void PermissionStateUnrestricted ()
{
PrincipalPermission p = new PrincipalPermission (PermissionState.Unrestricted);
Assert.IsNotNull (p, "PrincipalPermission(PermissionState.Unrestricted)");
Assert.IsTrue (p.IsUnrestricted (), "IsUnrestricted");
PrincipalPermission copy = (PrincipalPermission) p.Copy ();
Assert.AreEqual (p.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
// Note: Unrestricted isn't shown in XML
}
[Test]
public void Name ()
{
PrincipalPermission p = new PrincipalPermission ("user", null);
Assert.IsTrue(!p.IsUnrestricted (), "Name.IsUnrestricted");
}
[Test]
public void UnauthenticatedName ()
{
PrincipalPermission p = new PrincipalPermission ("user", null, false);
Assert.IsTrue(!p.IsUnrestricted (), "UnauthenticatedName.IsUnrestricted");
}
[Test]
public void Role ()
{
PrincipalPermission p = new PrincipalPermission (null, "users");
Assert.IsTrue(!p.IsUnrestricted (), "Role.IsUnrestricted");
}
[Test]
public void UnauthenticatedRole ()
{
PrincipalPermission p = new PrincipalPermission (null, "users", false);
Assert.IsTrue(!p.IsUnrestricted (), "UnauthenticatedRole.IsUnrestricted");
}
[Test]
public void NameRole ()
{
PrincipalPermission p = new PrincipalPermission ("user", "users", true);
Assert.IsTrue(!p.IsUnrestricted (), "NameRole.IsUnrestricted");
}
[Test]
public void UnauthenticatedNameRole ()
{
PrincipalPermission p = new PrincipalPermission ("user", "users", false);
Assert.IsTrue(!p.IsUnrestricted (), "UnauthenticatedNameRole.IsUnrestricted");
}
[Test]
public void AuthenticatedNullNull ()
{
PrincipalPermission p = new PrincipalPermission (null, null, true);
Assert.IsTrue(p.IsUnrestricted (), "UnauthenticatedNameRole.IsUnrestricted");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void FromXmlNull ()
{
PrincipalPermission p = new PrincipalPermission (PermissionState.None);
p.FromXml (null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXmlInvalidPermission ()
{
PrincipalPermission p = new PrincipalPermission (PermissionState.None);
SecurityElement se = p.ToXml ();
// can't modify - so we create our own
SecurityElement se2 = new SecurityElement ("IInvalidPermission", se.Text);
se2.AddAttribute ("class", se.Attribute ("class"));
se2.AddAttribute ("version", se.Attribute ("version"));
p.FromXml (se2);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void FromXmlWrongVersion ()
{
PrincipalPermission p = new PrincipalPermission (PermissionState.None);
SecurityElement se = p.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");
p.FromXml (se2);
}
[Test]
public void FromXml ()
{
PrincipalPermission p = new PrincipalPermission (PermissionState.None);
SecurityElement se = p.ToXml ();
Assert.IsNotNull (se, "ToXml()");
PrincipalPermission p2 = (PrincipalPermission) p.Copy ();
p2.FromXml (se);
Assert.AreEqual (p.ToString (), p2.ToString (), "FromXml-Copy");
string className = (string) se.Attributes ["class"];
string version = (string) se.Attributes ["version"];
SecurityElement se2 = new SecurityElement (se.Tag);
se2.AddAttribute ("class", className);
se2.AddAttribute ("version", version);
p2.FromXml (se2);
SecurityElement sec = new SecurityElement ("Identity");
sec.AddAttribute ("Authenticated", "true");
se2.AddChild (sec);
p2.FromXml (se2);
Assert.IsTrue (p2.IsUnrestricted (), "FromXml-Unrestricted");
}
[Test]
public void UnionWithNull ()
{
PrincipalPermission p1 = new PrincipalPermission ("user", null);
PrincipalPermission p2 = null;
PrincipalPermission p3 = (PrincipalPermission) p1.Union (p2);
Assert.AreEqual (p1.ToXml ().ToString (), p3.ToXml ().ToString (), "P1 U null == P1");
}
[Test]
public void UnionWithUnrestricted ()
{
PrincipalPermission p1 = new PrincipalPermission (PermissionState.Unrestricted);
PrincipalPermission p2 = new PrincipalPermission ("user", "role");
PrincipalPermission p3 = (PrincipalPermission) p1.Union (p2);
Assert.IsTrue (p3.IsUnrestricted (), "Unrestricted U P2 == Unrestricted");
p3 = (PrincipalPermission) p2.Union (p1);
Assert.IsTrue (p3.IsUnrestricted (), "P2 U Unrestricted == Unrestricted");
}
[Test]
public void Union ()
{
PrincipalPermission p1 = new PrincipalPermission ("user A", "role A");
PrincipalPermission p2 = new PrincipalPermission ("user B", "role B", false);
PrincipalPermission p3 = (PrincipalPermission) p1.Union (p2);
Assert.IsTrue (p3.ToString ().IndexOf ("user A") >= 0, "Union.UserA");
Assert.IsTrue (p3.ToString ().IndexOf ("user B") >= 0, "Union.UserB");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void UnionWithBadPermission ()
{
PrincipalPermission p1 = new PrincipalPermission ("user", null);
EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted);
PrincipalPermission p3 = (PrincipalPermission) p1.Union (ep2);
}
[Test]
public void IntersectWithNull ()
{
PrincipalPermission p1 = new PrincipalPermission ("user", "role");
PrincipalPermission p2 = null;
PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (p2);
Assert.IsNull (p3, "P1 N null == null");
}
[Test]
public void IntersectWithUnrestricted ()
{
PrincipalPermission p1 = new PrincipalPermission (PermissionState.Unrestricted);
PrincipalPermission p2 = new PrincipalPermission ("user", "role");
PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (p2);
Assert.IsTrue (!p3.IsUnrestricted (), "Unrestricted N P2 == P2");
Assert.AreEqual (p2.ToXml ().ToString (), p3.ToXml ().ToString (), "Unrestricted N EP2 == EP2");
p3 = (PrincipalPermission) p2.Intersect (p1);
Assert.IsTrue (!p3.IsUnrestricted (), "P2 N Unrestricted == P2");
Assert.AreEqual (p2.ToXml ().ToString (), p3.ToXml ().ToString (), "P2 N Unrestricted == P2");
}
[Test]
public void Intersect ()
{
// no intersection
PrincipalPermission p1 = new PrincipalPermission ("user A", "role 1");
PrincipalPermission p2 = new PrincipalPermission ("user B", "role 2");
PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (p2);
Assert.IsNull (p3, "EP1 N EP2 == null");
// intersection in role
PrincipalPermission p4 = new PrincipalPermission ("user C", "role 1");
p3 = (PrincipalPermission) p4.Intersect (p1);
Assert.IsTrue (p3.ToString ().IndexOf ("user A") < 0, "Intersect (!user A)");
Assert.IsTrue (p3.ToString ().IndexOf ("user C") < 0, "Intersect (!user C)");
Assert.IsTrue (p3.ToString ().IndexOf ("role 1") >= 0, "Intersect (role 1)");
// intersection in role without authentication
PrincipalPermission p5 = new PrincipalPermission ("user C", "role 1", false);
p3 = (PrincipalPermission) p5.Intersect (p1);
Assert.IsNull (p3, "EP5 N EP1 == null");
}
[Test]
public void IntersectNullName ()
{
PrincipalPermission p1 = new PrincipalPermission ("user", "role");
PrincipalPermission p2 = new PrincipalPermission (null, "role");
PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (p2);
Assert.AreEqual (p1.ToString (), p3.ToString (), "p1 N p2 == p1");
p3 = (PrincipalPermission) p2.Intersect (p1);
Assert.AreEqual (p1.ToString (), p3.ToString (), "p2 N p1 == p1");
}
[Test]
public void IntersectNullRole ()
{
PrincipalPermission p1 = new PrincipalPermission ("user", "role");
PrincipalPermission p2 = new PrincipalPermission ("user", null);
PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (p2);
Assert.AreEqual (p1.ToString (), p3.ToString (), "p1 N p2 == p1");
p3 = (PrincipalPermission) p2.Intersect (p1);
Assert.AreEqual (p1.ToString (), p3.ToString (), "p2 N p1 == p1");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IntersectWithBadPermission ()
{
PrincipalPermission p1 = new PrincipalPermission ("user", null);
EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted);
PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (ep2);
}
[Test]
public void IsSubsetOfNull ()
{
PrincipalPermission p = new PrincipalPermission ("user", null);
Assert.IsTrue (!p.IsSubsetOf (null), "User.IsSubsetOf(null)");
p = new PrincipalPermission (PermissionState.None);
Assert.IsTrue (p.IsSubsetOf (null), "None.IsSubsetOf(null)");
p = new PrincipalPermission (PermissionState.Unrestricted);
Assert.IsTrue (!p.IsSubsetOf (null), "Unrestricted.IsSubsetOf(null)");
}
[Test]
public void IsSubsetOfNone ()
{
PrincipalPermission none = new PrincipalPermission (PermissionState.None);
PrincipalPermission p = new PrincipalPermission ("user", null);
Assert.IsTrue (!p.IsSubsetOf (none), "User.IsSubsetOf(null)");
p = new PrincipalPermission (PermissionState.None);
Assert.IsTrue (p.IsSubsetOf (none), "None.IsSubsetOf(null)");
p = new PrincipalPermission (PermissionState.Unrestricted);
Assert.IsTrue (!p.IsSubsetOf (none), "Unrestricted.IsSubsetOf(null)");
}
[Test]
public void IsSubsetOfUnrestricted ()
{
PrincipalPermission p1 = new PrincipalPermission (PermissionState.Unrestricted);
PrincipalPermission p2 = new PrincipalPermission ("user", "role", false);
Assert.IsTrue (!p1.IsSubsetOf (p2), "Unrestricted.IsSubsetOf(user)");
Assert.IsTrue (p2.IsSubsetOf (p1), "user.IsSubsetOf(Unrestricted)");
}
[Test]
public void IsSubsetOf ()
{
PrincipalPermission p1 = new PrincipalPermission ("user A", "role 1");
PrincipalPermission p2 = new PrincipalPermission (null, "role 1");
Assert.IsTrue (p1.IsSubsetOf (p2), "UserRole.IsSubsetOf(Role)");
Assert.IsTrue (!p2.IsSubsetOf (p1), "Role.IsSubsetOf(UserRole)");
PrincipalPermission p3 = new PrincipalPermission ("user A", "role 1", false);
Assert.IsTrue (!p3.IsSubsetOf (p1), "UserRoleAuth.IsSubsetOf(UserRoleNA)");
Assert.IsTrue (!p1.IsSubsetOf (p3), "UserRoleNA.IsSubsetOf(UserRoleAuth)");
PrincipalPermission p4 = new PrincipalPermission (null, null, true); // unrestricted
Assert.IsTrue (!p4.IsSubsetOf (p1), "unrestricted.IsSubsetOf(UserRole)");
Assert.IsTrue (p1.IsSubsetOf (p4), "UserRole.IsSubsetOf(unrestricted)");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void IsSubsetOfBadPermission ()
{
PrincipalPermission p1 = new PrincipalPermission ("user", null);
EnvironmentPermission ep2 = new EnvironmentPermission (PermissionState.Unrestricted);
Assert.IsTrue (p1.IsSubsetOf (ep2), "IsSubsetOf(EnvironmentPermission)");
}
}
}

View File

@@ -0,0 +1,238 @@
//
// PublisherIdentityPermissionAttributeTest.cs -
// NUnit Test Cases for PublisherIdentityPermissionAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Security;
using System.Security.Permissions;
using System.Security.Cryptography.X509Certificates;
namespace MonoTests.System.Security.Permissions {
[TestFixture]
public class PublisherIdentityPermissionAttributeTest {
private static byte[] cert1 = { 0x30,0x82,0x05,0x0F,0x30,0x82,0x03,0xF7,0xA0,0x03,0x02,0x01,0x02,0x02,0x0A,0x61,0x07,0x11,0x43,0x00,0x00,0x00,0x00,0x00,0x34,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,0x05,0x00,0x30,0x81,0xA6,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x08,0x13,0x0A,0x57,0x61,0x73,0x68,0x69,0x6E,0x67,0x74,0x6F,0x6E,0x31,0x10,0x30,0x0E,0x06,0x03,0x55,0x04,0x07,0x13,0x07,0x52,0x65,0x64,0x6D,0x6F,0x6E,0x64,0x31,0x1E,0x30,0x1C,0x06,0x03,
0x55,0x04,0x0A,0x13,0x15,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x43,0x6F,0x72,0x70,0x6F,0x72,0x61,0x74,0x69,0x6F,0x6E,0x31,0x2B,0x30,0x29,0x06,0x03,0x55,0x04,0x0B,0x13,0x22,0x43,0x6F,0x70,0x79,0x72,0x69,0x67,0x68,0x74,0x20,0x28,0x63,0x29,0x20,0x32,0x30,0x30,0x30,0x20,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x43,0x6F,0x72,0x70,0x2E,0x31,0x23,0x30,0x21,0x06,0x03,0x55,0x04,0x03,0x13,0x1A,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x43,0x6F,0x64,0x65,0x20,0x53,0x69,0x67,
0x6E,0x69,0x6E,0x67,0x20,0x50,0x43,0x41,0x30,0x1E,0x17,0x0D,0x30,0x32,0x30,0x35,0x32,0x35,0x30,0x30,0x35,0x35,0x34,0x38,0x5A,0x17,0x0D,0x30,0x33,0x31,0x31,0x32,0x35,0x30,0x31,0x30,0x35,0x34,0x38,0x5A,0x30,0x81,0xA1,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x08,0x13,0x0A,0x57,0x61,0x73,0x68,0x69,0x6E,0x67,0x74,0x6F,0x6E,0x31,0x10,0x30,0x0E,0x06,0x03,0x55,0x04,0x07,0x13,0x07,0x52,0x65,0x64,0x6D,0x6F,0x6E,0x64,0x31,0x1E,0x30,0x1C,0x06,
0x03,0x55,0x04,0x0A,0x13,0x15,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x43,0x6F,0x72,0x70,0x6F,0x72,0x61,0x74,0x69,0x6F,0x6E,0x31,0x2B,0x30,0x29,0x06,0x03,0x55,0x04,0x0B,0x13,0x22,0x43,0x6F,0x70,0x79,0x72,0x69,0x67,0x68,0x74,0x20,0x28,0x63,0x29,0x20,0x32,0x30,0x30,0x32,0x20,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x43,0x6F,0x72,0x70,0x2E,0x31,0x1E,0x30,0x1C,0x06,0x03,0x55,0x04,0x03,0x13,0x15,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x43,0x6F,0x72,0x70,0x6F,0x72,0x61,
0x74,0x69,0x6F,0x6E,0x30,0x82,0x01,0x22,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x03,0x82,0x01,0x0F,0x00,0x30,0x82,0x01,0x0A,0x02,0x82,0x01,0x01,0x00,0xAA,0x99,0xBD,0x39,0xA8,0x18,0x27,0xF4,0x2B,0x3D,0x0B,0x4C,0x3F,0x7C,0x77,0x2E,0xA7,0xCB,0xB5,0xD1,0x8C,0x0D,0xC2,0x3A,0x74,0xD7,0x93,0xB5,0xE0,0xA0,0x4B,0x3F,0x59,0x5E,0xCE,0x45,0x4F,0x9A,0x79,0x29,0xF1,0x49,0xCC,0x1A,0x47,0xEE,0x55,0xC2,0x08,0x3E,0x12,0x20,0xF8,0x55,0xF2,0xEE,0x5F,0xD3,0xE0,0xCA,0x96,0xBC,0x30,
0xDE,0xFE,0x58,0xC8,0x27,0x32,0xD0,0x85,0x54,0xE8,0xF0,0x91,0x10,0xBB,0xF3,0x2B,0xBE,0x19,0xE5,0x03,0x9B,0x0B,0x86,0x1D,0xF3,0xB0,0x39,0x8C,0xB8,0xFD,0x0B,0x1D,0x3C,0x73,0x26,0xAC,0x57,0x2B,0xCA,0x29,0xA2,0x15,0x90,0x82,0x15,0xE2,0x77,0xA3,0x40,0x52,0x03,0x8B,0x9D,0xC2,0x70,0xBA,0x1F,0xE9,0x34,0xF6,0xF3,0x35,0x92,0x4E,0x55,0x83,0xF8,0xDA,0x30,0xB6,0x20,0xDE,0x57,0x06,0xB5,0x5A,0x42,0x06,0xDE,0x59,0xCB,0xF2,0xDF,0xA6,0xBD,0x15,0x47,0x71,0x19,0x25,0x23,0xD2,0xCB,0x6F,0x9B,0x19,0x79,0xDF,0x6A,0x5B,
0xF1,0x76,0x05,0x79,0x29,0xFC,0xC3,0x56,0xCA,0x8F,0x44,0x08,0x85,0x55,0x8A,0xCB,0xC8,0x0F,0x46,0x4B,0x55,0xCB,0x8C,0x96,0x77,0x4A,0x87,0xE8,0xA9,0x41,0x06,0xC7,0xFF,0x0D,0xE9,0x68,0x57,0x63,0x72,0xC3,0x69,0x57,0xB4,0x43,0xCF,0x32,0x3A,0x30,0xDC,0x1B,0xE9,0xD5,0x43,0x26,0x2A,0x79,0xFE,0x95,0xDB,0x22,0x67,0x24,0xC9,0x2F,0xD0,0x34,0xE3,0xE6,0xFB,0x51,0x49,0x86,0xB8,0x3C,0xD0,0x25,0x5F,0xD6,0xEC,0x9E,0x03,0x61,0x87,0xA9,0x68,0x40,0xC7,0xF8,0xE2,0x03,0xE6,0xCF,0x05,0x02,0x03,0x01,0x00,0x01,0xA3,0x82,
0x01,0x40,0x30,0x82,0x01,0x3C,0x30,0x0E,0x06,0x03,0x55,0x1D,0x0F,0x01,0x01,0xFF,0x04,0x04,0x03,0x02,0x06,0xC0,0x30,0x13,0x06,0x03,0x55,0x1D,0x25,0x04,0x0C,0x30,0x0A,0x06,0x08,0x2B,0x06,0x01,0x05,0x05,0x07,0x03,0x03,0x30,0x1D,0x06,0x03,0x55,0x1D,0x0E,0x04,0x16,0x04,0x14,0x6B,0xC8,0xC6,0x51,0x20,0xF0,0xB4,0x2F,0xD3,0xA0,0xB6,0xAE,0x7F,0x5E,0x26,0xB2,0xB8,0x87,0x52,0x29,0x30,0x81,0xA9,0x06,0x03,0x55,0x1D,0x23,0x04,0x81,0xA1,0x30,0x81,0x9E,0x80,0x14,0x29,0x5C,0xB9,0x1B,0xB6,0xCD,0x33,0xEE,0xBB,0x9E,
0x59,0x7D,0xF7,0xE5,0xCA,0x2E,0xC4,0x0D,0x34,0x28,0xA1,0x74,0xA4,0x72,0x30,0x70,0x31,0x2B,0x30,0x29,0x06,0x03,0x55,0x04,0x0B,0x13,0x22,0x43,0x6F,0x70,0x79,0x72,0x69,0x67,0x68,0x74,0x20,0x28,0x63,0x29,0x20,0x31,0x39,0x39,0x37,0x20,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x43,0x6F,0x72,0x70,0x2E,0x31,0x1E,0x30,0x1C,0x06,0x03,0x55,0x04,0x0B,0x13,0x15,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x43,0x6F,0x72,0x70,0x6F,0x72,0x61,0x74,0x69,0x6F,0x6E,0x31,0x21,0x30,0x1F,0x06,0x03,0x55,
0x04,0x03,0x13,0x18,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x52,0x6F,0x6F,0x74,0x20,0x41,0x75,0x74,0x68,0x6F,0x72,0x69,0x74,0x79,0x82,0x10,0x6A,0x0B,0x99,0x4F,0xC0,0x00,0xDE,0xAA,0x11,0xD4,0xD8,0x40,0x9A,0xA8,0xBE,0xE6,0x30,0x4A,0x06,0x03,0x55,0x1D,0x1F,0x04,0x43,0x30,0x41,0x30,0x3F,0xA0,0x3D,0xA0,0x3B,0x86,0x39,0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x63,0x72,0x6C,0x2E,0x6D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x2E,0x63,0x6F,0x6D,0x2F,0x70,0x6B,0x69,0x2F,0x63,0x72,0x6C,0x2F,0x70,0x72,
0x6F,0x64,0x75,0x63,0x74,0x73,0x2F,0x43,0x6F,0x64,0x65,0x53,0x69,0x67,0x6E,0x50,0x43,0x41,0x2E,0x63,0x72,0x6C,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,0x05,0x00,0x03,0x82,0x01,0x01,0x00,0x35,0x23,0xFD,0x13,0x54,0xFC,0xE9,0xDC,0xF0,0xDD,0x0C,0x14,0x7A,0xFA,0xA7,0xB3,0xCE,0xFD,0xA7,0x3A,0xC8,0xBA,0xE5,0xE7,0xF6,0x03,0xFB,0x53,0xDB,0xA7,0x99,0xA9,0xA0,0x9B,0x36,0x9C,0x03,0xEB,0x82,0x47,0x1C,0x21,0xBD,0x14,0xCB,0xE7,0x67,0x40,0x09,0xC7,0x16,0x91,0x02,0x55,0xCE,0x43,0x42,0xB4,
0xCD,0x1B,0x5D,0xB0,0xF3,0x32,0x04,0x3D,0x12,0xE5,0x1D,0xA7,0x07,0xA7,0x8F,0xA3,0x7E,0x45,0x55,0x76,0x1B,0x96,0x95,0x91,0x69,0xF0,0xDD,0x38,0xF3,0x48,0x89,0xEF,0x70,0x40,0xB7,0xDB,0xB5,0x55,0x80,0xC0,0x03,0xC4,0x2E,0xB6,0x28,0xDC,0x0A,0x82,0x0E,0xC7,0x43,0xE3,0x7A,0x48,0x5D,0xB8,0x06,0x89,0x92,0x40,0x6C,0x6E,0xC5,0xDC,0xF8,0x9A,0xEF,0x0B,0xBE,0x21,0x0A,0x8C,0x2F,0x3A,0xB5,0xED,0xA7,0xCE,0x71,0x87,0x68,0x23,0xE1,0xB3,0xE4,0x18,0x7D,0xB8,0x47,0x01,0xA5,0x2B,0xC4,0x58,0xCB,0xB2,0x89,0x6C,0x5F,0xFD,
0xD3,0x2C,0xC4,0x6F,0xB8,0x23,0xB2,0x0D,0xFF,0x3C,0xF2,0x11,0x45,0x74,0xF2,0x09,0x06,0x99,0x18,0xDD,0x6F,0xC0,0x86,0x01,0x18,0x12,0x1D,0x2B,0x16,0xAF,0x56,0xEF,0x65,0x33,0xA1,0xEA,0x67,0x4E,0xF4,0x4B,0x82,0xAB,0xE9,0x0F,0xDC,0x01,0xFA,0xDF,0x60,0x7F,0x66,0x47,0x5D,0xCB,0x2C,0x70,0xCC,0x7B,0x4E,0xD9,0x06,0xB8,0x6E,0x8C,0x0C,0xFE,0x62,0x1E,0x42,0xF9,0x93,0x7C,0xA2,0xAB,0x0A,0x9E,0xD0,0x23,0x10,0xAE,0x4D,0x7B,0x27,0x91,0x6F,0x26,0xBE,0x68,0xFA,0xA6,0x3F,0x9F,0x23,0xEB,0xC8,0x9D,0xBB,0x87 };
private static byte[] cert2 = { 0x30,0x82,0x01,0xDF,0x30,0x82,0x01,0x48,0x02,0x01,0x00,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,0x05,0x00,0x30,0x39,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x0D,0x30,0x0B,0x06,0x03,0x55,0x04,0x0A,0x14,0x04,0x41,0x54,0x26,0x54,0x31,0x1B,0x30,0x19,0x06,0x03,0x55,0x04,0x0B,0x14,0x12,0x44,0x69,0x72,0x65,0x63,0x74,0x6F,0x72,0x79,0x20,0x53,0x65,0x72,0x76,0x69,0x63,0x65,0x73,0x30,0x1E,0x17,0x0D,0x39,0x36,0x30,0x31,0x31,0x38,0x32,0x31,0x30,0x33,0x35,0x32,
0x5A,0x17,0x0D,0x30,0x31,0x30,0x31,0x31,0x36,0x32,0x31,0x30,0x33,0x35,0x32,0x5A,0x30,0x39,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,0x13,0x02,0x55,0x53,0x31,0x0D,0x30,0x0B,0x06,0x03,0x55,0x04,0x0A,0x14,0x04,0x41,0x54,0x26,0x54,0x31,0x1B,0x30,0x19,0x06,0x03,0x55,0x04,0x0B,0x14,0x12,0x44,0x69,0x72,0x65,0x63,0x74,0x6F,0x72,0x79,0x20,0x53,0x65,0x72,0x76,0x69,0x63,0x65,0x73,0x30,0x81,0x9D,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,0x05,0x00,0x03,0x81,0x8B,0x00,0x30,0x81,0x87,
0x02,0x81,0x81,0x00,0x87,0x64,0x72,0x89,0x0B,0x20,0x8F,0x87,0x27,0xAC,0xC6,0x22,0xFE,0x00,0x40,0x69,0x48,0xAF,0xC6,0x86,0xCD,0x23,0x33,0xE3,0x11,0xC5,0x31,0x1A,0x1F,0x7E,0x9E,0x92,0x13,0xB6,0xA2,0xAC,0xE3,0xB0,0x1F,0x2A,0x07,0x6C,0xB6,0xD4,0xDE,0x4B,0xFA,0xF1,0xA2,0xA0,0x7D,0xCE,0x4B,0xBE,0xBE,0x26,0x48,0x09,0x8C,0x85,0x11,0xDE,0xCB,0x22,0xE7,0xC2,0xEE,0x44,0x51,0xFE,0x67,0xD5,0x5B,0x5A,0xE0,0x16,0x37,0x54,0x04,0xB8,0x3B,0x32,0x12,0x94,0x83,0x9E,0xB1,0x4D,0x80,0x6C,0xA4,0xA9,0x76,0xAC,0xB8,0xA4,
0x97,0xF7,0xAB,0x0B,0x6C,0xA5,0x43,0xBA,0x6E,0x4F,0xC5,0x4E,0x00,0x30,0x16,0x3C,0x3F,0x99,0x14,0xDA,0xA2,0x20,0x08,0x8B,0xBA,0xED,0x76,0xAC,0x97,0x00,0xD5,0x6D,0x02,0x01,0x0F,0x30,0x0D,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,0x05,0x00,0x03,0x81,0x81,0x00,0x38,0x50,0x1D,0x0A,0xD3,0x1B,0xBB,0xA2,0x9F,0x6C,0x8D,0x10,0xAA,0x42,0x1B,0x05,0x8D,0xE4,0x25,0xAB,0xFB,0x55,0xAE,0x6D,0xBA,0x53,0x67,0x15,0x07,0x9A,0xEC,0x55,0x9F,0x72,0x89,0x5F,0x24,0xB0,0xDB,0xCA,0x64,0xBD,0x64,0xAA,0xC2,0x8C,
0xD9,0x3D,0xA2,0x45,0xB7,0xC6,0x92,0x71,0x51,0xEF,0xED,0xE1,0x51,0x54,0x97,0x56,0x35,0xA1,0xCE,0xE4,0x44,0xC4,0x47,0x66,0xFF,0x91,0xDA,0x88,0x9C,0x23,0xC2,0xB3,0xD4,0x62,0x4A,0xBC,0x94,0x55,0x9C,0x80,0x8E,0xB3,0xDD,0x4F,0x1A,0xED,0x12,0x5A,0xB5,0x2E,0xBC,0xF8,0x4B,0xCE,0xC6,0xD4,0x70,0xB3,0xB3,0x22,0xF8,0x5E,0x5C,0x36,0x7A,0xA6,0xB8,0x39,0x73,0x46,0x43,0x5C,0x9B,0x9A,0xBD,0x1E,0x7E,0xA7,0x04,0xCF,0x25,0x36 };
[TestFixtureSetUp]
public void FixtureSetUp ()
{
using (FileStream fs1 = File.OpenWrite ("cert1.cer")) {
fs1.Write (cert1, 0, cert1.Length);
fs1.Close ();
}
using (FileStream fs2 = File.OpenWrite ("cert2.cer")) {
fs2.Write (cert2, 0, cert2.Length);
fs2.Close ();
}
}
[TestFixtureTearDown]
public void FixtureTearDown ()
{
try {
File.Delete ("cert1.cer");
File.Delete ("cert2.cer");
}
catch {} // don't mess up results over that
}
[Test]
public void Default ()
{
PublisherIdentityPermissionAttribute a = new PublisherIdentityPermissionAttribute (SecurityAction.Assert);
Assert.IsNull (a.CertFile, "CertFile");
Assert.IsNull (a.SignedFile, "SignedFile");
Assert.IsNull (a.X509Certificate, "X509Certificate");
Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
Assert.IsFalse (a.Unrestricted, "Unrestricted");
PublisherIdentityPermission perm = (PublisherIdentityPermission) a.CreatePermission ();
Assert.IsNull (perm.Certificate, "CreatePermission.Certificate");
}
[Test]
public void Action ()
{
PublisherIdentityPermissionAttribute a = new PublisherIdentityPermissionAttribute (SecurityAction.Assert);
Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
a.Action = SecurityAction.Demand;
Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
a.Action = SecurityAction.Deny;
Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
a.Action = SecurityAction.InheritanceDemand;
Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
a.Action = SecurityAction.LinkDemand;
Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
a.Action = SecurityAction.PermitOnly;
Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
a.Action = SecurityAction.RequestMinimum;
Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
a.Action = SecurityAction.RequestOptional;
Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
a.Action = SecurityAction.RequestRefuse;
Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
}
[Test]
public void Action_Invalid ()
{
PublisherIdentityPermissionAttribute a = new PublisherIdentityPermissionAttribute ((SecurityAction)Int32.MinValue);
// no validation in attribute
}
[Test]
public void None ()
{
PublisherIdentityPermissionAttribute attr = new PublisherIdentityPermissionAttribute (SecurityAction.Assert);
Assert.IsNull (attr.CertFile, "None.CertFile");
Assert.IsNull (attr.SignedFile, "None.SignedFile");
Assert.IsNull (attr.X509Certificate, "None.X509Certificate");
PublisherIdentityPermission p = (PublisherIdentityPermission) attr.CreatePermission ();
Assert.IsNull (p.Certificate, "None.CreatePermission");
}
[Test]
public void CertFile ()
{
X509Certificate x509 = new X509Certificate (cert1);
PublisherIdentityPermissionAttribute attr = new PublisherIdentityPermissionAttribute (SecurityAction.Assert);
attr.CertFile = "cert1.cer";
attr.SignedFile = null;
attr.X509Certificate = null;
Assert.AreEqual ("cert1.cer", attr.CertFile, "CertFile");
Assert.IsNull (attr.SignedFile, "SignedFile");
Assert.IsNull (attr.X509Certificate, "X509Certificate");
PublisherIdentityPermission p = (PublisherIdentityPermission) attr.CreatePermission ();
Assert.AreEqual (x509.GetRawCertDataString (), p.Certificate.GetRawCertDataString (), "CertFile.Certificate");
}
[Test]
[Ignore ("CreateFromSignedFile isn't finished yet")]
public void SignedFile ()
{
X509Certificate x509 = new X509Certificate (cert1);
PublisherIdentityPermissionAttribute attr = new PublisherIdentityPermissionAttribute (SecurityAction.Assert);
attr.CertFile = null;
attr.SignedFile = "cert1.cer";
attr.X509Certificate = null;
Assert.IsNull (attr.CertFile, "CertFile");
Assert.AreEqual ("cert1.cer", attr.SignedFile, "SignedFile");
Assert.IsNull (attr.X509Certificate, "X509Certificate");
PublisherIdentityPermission p = (PublisherIdentityPermission) attr.CreatePermission ();
Assert.AreEqual (x509.GetRawCertDataString (), p.Certificate.GetRawCertDataString (), "SignedFile.Certificate");
}
[Test]
public void X509CertificateProperty ()
{
X509Certificate x509 = new X509Certificate (cert2);
PublisherIdentityPermissionAttribute attr = new PublisherIdentityPermissionAttribute (SecurityAction.Assert);
attr.CertFile = null;
attr.SignedFile = null;
attr.X509Certificate = x509.GetRawCertDataString ();
Assert.IsNull (attr.CertFile, "CertFile");
Assert.IsNull (attr.SignedFile, "SignedFile");
Assert.AreEqual (x509.GetRawCertDataString (), attr.X509Certificate, "X509Certificate");
PublisherIdentityPermission p = (PublisherIdentityPermission) attr.CreatePermission ();
Assert.AreEqual (x509.GetRawCertDataString (), p.Certificate.GetRawCertDataString (), "X509CertificateProperty.Certificate");
}
[Test]
public void Priority ()
{
X509Certificate x509 = new X509Certificate (cert1);
PublisherIdentityPermissionAttribute attr = new PublisherIdentityPermissionAttribute (SecurityAction.Assert);
attr.CertFile = "cert1.cer";
attr.SignedFile = "cert2.cer";
attr.X509Certificate = x509.GetRawCertDataString ();
Assert.AreEqual ("cert1.cer", attr.CertFile, "CertFile");
Assert.AreEqual ("cert2.cer", attr.SignedFile, "SignedFile");
Assert.AreEqual (x509.GetRawCertDataString (), attr.X509Certificate, "X509Certificate");
// from documentation X509Certificate has priority over CertFile and SignedFile
PublisherIdentityPermission p = (PublisherIdentityPermission) attr.CreatePermission ();
Assert.AreEqual (x509.GetRawCertDataString (), p.Certificate.GetRawCertDataString (), "p.Certificate");
// but no word about CertFile and SignedFile priority
attr.CertFile = "cert1.cer";
attr.SignedFile = "cert2.cer";
attr.X509Certificate = null;
p = (PublisherIdentityPermission) attr.CreatePermission ();
Assert.AreEqual (x509.GetRawCertDataString (), p.Certificate.GetRawCertDataString (), "p.Certificate");
// CertFile !
}
[Test]
#if !NET_2_0
[ExpectedException (typeof (ArgumentException))]
#else
[Category ("NotWorking")]
#endif
public void Unrestricted ()
{
PublisherIdentityPermissionAttribute a = new PublisherIdentityPermissionAttribute (SecurityAction.Assert);
a.Unrestricted = true;
IPermission perm = a.CreatePermission ();
}
[Test]
public void Attributes ()
{
Type t = typeof (PublisherIdentityPermissionAttribute);
Assert.IsTrue (t.IsSerializable, "IsSerializable");
object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
Assert.AreEqual (1, attrs.Length, "AttributeUsage");
AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
Assert.IsFalse (aua.Inherited, "Inherited");
AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
Assert.AreEqual (at, aua.ValidOn, "ValidOn");
}
}
}

Some files were not shown because too many files have changed in this diff Show More