2 // IsolatedStorageFilePermissionAttributeTest.cs - NUnit Test Cases for IsolatedStorageFilePermissionAttribute
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
32 using System.Security;
33 using System.Security.Permissions;
35 namespace MonoTests.System.Security.Permissions {
38 public class IsolatedStorageFilePermissionAttributeTest {
41 public void Default ()
43 IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
44 Assert.AreEqual (IsolatedStorageContainment.None, a.UsageAllowed, "UsageAllowed");
45 Assert.AreEqual (0, a.UserQuota, "UserQuota");
46 Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
47 Assert.IsFalse (a.Unrestricted, "Unrestricted");
49 IsolatedStorageFilePermission perm = (IsolatedStorageFilePermission) a.CreatePermission ();
50 Assert.AreEqual (IsolatedStorageContainment.None, perm.UsageAllowed, "CreatePermission-UsageAllowed");
51 Assert.AreEqual (0, perm.UserQuota, "CreatePermission-UserQuota");
57 IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
58 Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
59 a.Action = SecurityAction.Demand;
60 Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
61 a.Action = SecurityAction.Deny;
62 Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
63 a.Action = SecurityAction.InheritanceDemand;
64 Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
65 a.Action = SecurityAction.LinkDemand;
66 Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
67 a.Action = SecurityAction.PermitOnly;
68 Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
69 a.Action = SecurityAction.RequestMinimum;
70 Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
71 a.Action = SecurityAction.RequestOptional;
72 Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
73 a.Action = SecurityAction.RequestRefuse;
74 Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
78 public void Action_Invalid ()
80 IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute ((SecurityAction)Int32.MinValue);
81 // no validation in attribute
85 public void UsageAllowed ()
87 IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
88 Assert.AreEqual (IsolatedStorageContainment.None, a.UsageAllowed, "UsageAllowed=None");
89 a.UsageAllowed = IsolatedStorageContainment.AdministerIsolatedStorageByUser;
90 Assert.AreEqual (IsolatedStorageContainment.AdministerIsolatedStorageByUser, a.UsageAllowed, "UsageAllowed=AdministerIsolatedStorageByUser");
91 a.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByRoamingUser;
92 Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByRoamingUser, a.UsageAllowed, "UsageAllowed=AssemblyIsolationByRoamingUser");
93 a.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser;
94 Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByUser, a.UsageAllowed, "UsageAllowed=AssemblyIsolationByUser");
95 a.UsageAllowed = IsolatedStorageContainment.DomainIsolationByRoamingUser;
96 Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByRoamingUser, a.UsageAllowed, "UsageAllowed=DomainIsolationByRoamingUser");
97 a.UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser;
98 Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByUser, a.UsageAllowed, "UsageAllowed=DomainIsolationByUser");
99 a.UsageAllowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
100 Assert.AreEqual (IsolatedStorageContainment.UnrestrictedIsolatedStorage, a.UsageAllowed, "UsageAllowed=UnrestrictedIsolatedStorage");
104 public void UsageAllowed_Invalid ()
106 IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
107 a.UsageAllowed = (IsolatedStorageContainment)Int32.MinValue;
108 // no validation in attribute
112 public void UserQuota ()
114 IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
115 Assert.AreEqual (0, a.UserQuota, "UserQuota=default");
116 a.UserQuota = Int64.MinValue;
117 Assert.AreEqual (Int64.MinValue, a.UserQuota, "UserQuota=MinValue");
118 a.UserQuota = Int64.MaxValue;
119 Assert.AreEqual (Int64.MaxValue, a.UserQuota, "UserQuota=MaxValue");
123 public void Unrestricted ()
125 IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
126 a.Unrestricted = true;
128 IsolatedStorageFilePermission perm = (IsolatedStorageFilePermission) a.CreatePermission ();
129 Assert.IsTrue (perm.IsUnrestricted (), "CreatePermission.IsUnrestricted");
130 Assert.AreEqual (IsolatedStorageContainment.UnrestrictedIsolatedStorage, perm.UsageAllowed, "CreatePermission.UsageAllowed");
131 Assert.AreEqual (Int64.MaxValue, perm.UserQuota, "CreatePermission.UserQuota");
135 public void Attributes ()
137 IsolatedStorageFilePermissionAttribute a = new IsolatedStorageFilePermissionAttribute (SecurityAction.Assert);
138 Type t = typeof (IsolatedStorageFilePermissionAttribute);
139 Assert.IsTrue (t.IsSerializable, "IsSerializable");
141 object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
142 Assert.AreEqual (1, attrs.Length, "AttributeUsage");
143 AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
144 Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
145 Assert.IsFalse (aua.Inherited, "Inherited");
146 AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
147 Assert.AreEqual (at, aua.ValidOn, "ValidOn");