2 // KeyContainerPermissionAttributeTest.cs -
3 // NUnit Test Cases for KeyContainerPermissionAttributeTest
6 // Sebastien Pouliot <sebastien@ximian.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.
31 using NUnit
.Framework
;
33 using System
.Security
;
34 using System
.Security
.Permissions
;
36 namespace MonoTests
.System
.Security
.Permissions
{
39 public class KeyContainerPermissionAttributeTest
{
42 [Category ("NotWorking")]
43 public void Default ()
45 KeyContainerPermissionAttribute a
= new KeyContainerPermissionAttribute (SecurityAction
.Assert
);
46 Assert
.AreEqual (KeyContainerPermissionFlags
.NoFlags
, a
.Flags
, "Flags");
47 Assert
.IsNull (a
.KeyContainerName
, "KeyContainerName");
48 Assert
.AreEqual (-1, a
.KeySpec
, "KeySpec");
49 Assert
.IsNull (a
.KeyStore
, "KeyStore");
50 Assert
.IsNull (a
.ProviderName
, "ProviderName");
51 Assert
.AreEqual (-1, a
.ProviderType
, "ProviderType");
53 Assert
.IsFalse (a
.Unrestricted
, "Unrestricted");
54 Assert
.AreEqual (a
.ToString (), a
.TypeId
.ToString (), "TypeId");
56 KeyContainerPermission perm
= (KeyContainerPermission
)a
.CreatePermission ();
57 Assert
.AreEqual (KeyContainerPermissionFlags
.NoFlags
, perm
.Flags
, "perm.Flags");
58 Assert
.IsFalse (perm
.IsUnrestricted (), "perm.Unrestricted");
64 KeyContainerPermissionAttribute a
= new KeyContainerPermissionAttribute (SecurityAction
.Assert
);
65 Assert
.AreEqual (SecurityAction
.Assert
, a
.Action
, "Action=Assert");
66 a
.Action
= SecurityAction
.Demand
;
67 Assert
.AreEqual (SecurityAction
.Demand
, a
.Action
, "Action=Demand");
68 a
.Action
= SecurityAction
.Deny
;
69 Assert
.AreEqual (SecurityAction
.Deny
, a
.Action
, "Action=Deny");
70 a
.Action
= SecurityAction
.InheritanceDemand
;
71 Assert
.AreEqual (SecurityAction
.InheritanceDemand
, a
.Action
, "Action=InheritanceDemand");
72 a
.Action
= SecurityAction
.LinkDemand
;
73 Assert
.AreEqual (SecurityAction
.LinkDemand
, a
.Action
, "Action=LinkDemand");
74 a
.Action
= SecurityAction
.PermitOnly
;
75 Assert
.AreEqual (SecurityAction
.PermitOnly
, a
.Action
, "Action=PermitOnly");
76 a
.Action
= SecurityAction
.RequestMinimum
;
77 Assert
.AreEqual (SecurityAction
.RequestMinimum
, a
.Action
, "Action=RequestMinimum");
78 a
.Action
= SecurityAction
.RequestOptional
;
79 Assert
.AreEqual (SecurityAction
.RequestOptional
, a
.Action
, "Action=RequestOptional");
80 a
.Action
= SecurityAction
.RequestRefuse
;
81 Assert
.AreEqual (SecurityAction
.RequestRefuse
, a
.Action
, "Action=RequestRefuse");
85 public void Action_Invalid ()
87 KeyContainerPermissionAttribute a
= new KeyContainerPermissionAttribute ((SecurityAction
)Int32
.MinValue
);
88 // no validation in attribute
91 private KeyContainerPermissionAttribute
Empty ()
93 return new KeyContainerPermissionAttribute (SecurityAction
.Assert
);
97 public void KeyContainerName ()
99 KeyContainerPermissionAttribute a
= Empty ();
100 a
.KeyContainerName
= "mono";
101 Assert
.AreEqual ("mono", a
.KeyContainerName
, "KeyContainerName-1");
102 a
.KeyContainerName
= null;
103 Assert
.IsNull (a
.KeyContainerName
, "KeyContainerName-2");
104 a
.KeyContainerName
= String
.Empty
;
105 Assert
.AreEqual (String
.Empty
, a
.KeyContainerName
, "KeyContainerName-3");
106 Assert
.AreEqual (KeyContainerPermissionFlags
.NoFlags
, a
.Flags
, "Flags");
110 public void KeySpec ()
112 KeyContainerPermissionAttribute a
= Empty ();
113 a
.KeySpec
= Int32
.MinValue
;
114 Assert
.AreEqual (Int32
.MinValue
, a
.KeySpec
, "KeySpec-1");
116 Assert
.AreEqual (0, a
.KeySpec
, "KeySpec-2");
117 a
.KeySpec
= Int32
.MaxValue
;
118 Assert
.AreEqual (Int32
.MaxValue
, a
.KeySpec
, "KeySpec-3");
119 Assert
.AreEqual (KeyContainerPermissionFlags
.NoFlags
, a
.Flags
, "Flags");
123 public void KeyStore ()
125 KeyContainerPermissionAttribute a
= Empty ();
127 Assert
.AreEqual ("mono", a
.KeyStore
, "KeyStore-1");
129 Assert
.IsNull (a
.KeyStore
, "KeyStore-2");
130 a
.KeyStore
= String
.Empty
;
131 Assert
.AreEqual (String
.Empty
, a
.KeyStore
, "KeyStore-3");
132 Assert
.AreEqual (KeyContainerPermissionFlags
.NoFlags
, a
.Flags
, "Flags");
136 public void ProviderName ()
138 KeyContainerPermissionAttribute a
= Empty ();
139 a
.ProviderName
= "mono";
140 Assert
.AreEqual ("mono", a
.ProviderName
, "ProviderName-1");
141 a
.ProviderName
= null;
142 Assert
.IsNull (a
.ProviderName
, "ProviderName-2");
143 a
.ProviderName
= String
.Empty
;
144 Assert
.AreEqual (String
.Empty
, a
.ProviderName
, "ProviderName-3");
145 Assert
.AreEqual (KeyContainerPermissionFlags
.NoFlags
, a
.Flags
, "Flags");
149 public void ProviderType ()
151 KeyContainerPermissionAttribute a
= Empty ();
152 a
.ProviderType
= Int32
.MinValue
;
153 Assert
.AreEqual (Int32
.MinValue
, a
.ProviderType
, "ProviderType-1");
155 Assert
.AreEqual (0, a
.ProviderType
, "ProviderType-2");
156 a
.ProviderType
= Int32
.MaxValue
;
157 Assert
.AreEqual (Int32
.MaxValue
, a
.ProviderType
, "ProviderType-3");
158 Assert
.AreEqual (KeyContainerPermissionFlags
.NoFlags
, a
.Flags
, "Flags");
162 public void Unrestricted ()
164 KeyContainerPermissionAttribute a
= Empty ();
165 a
.Unrestricted
= true;
166 Assert
.AreEqual (KeyContainerPermissionFlags
.NoFlags
, a
.Flags
, "Flags");
168 KeyContainerPermission perm
= (KeyContainerPermission
)a
.CreatePermission ();
169 Assert
.AreEqual (KeyContainerPermissionFlags
.AllFlags
, perm
.Flags
, "CreatePermission.Flags");
175 KeyContainerPermissionAttribute a
= Empty ();
176 a
.Flags
= KeyContainerPermissionFlags
.AllFlags
;
177 Assert
.IsFalse (a
.Unrestricted
, "Unrestricted");
178 Assert
.AreEqual (KeyContainerPermissionFlags
.AllFlags
, a
.Flags
, "Flags");
182 public void Flags_Invalid ()
184 KeyContainerPermissionAttribute a
= Empty ();
185 a
.Flags
= ((KeyContainerPermissionFlags
)Int32
.MinValue
);
186 // no validations for flags
190 public void Attributes ()
192 Type t
= typeof (KeyContainerPermissionAttribute
);
193 Assert
.IsTrue (t
.IsSerializable
, "IsSerializable");
195 object [] attrs
= t
.GetCustomAttributes (typeof (AttributeUsageAttribute
), false);
196 Assert
.AreEqual (1, attrs
.Length
, "AttributeUsage");
197 AttributeUsageAttribute aua
= (AttributeUsageAttribute
)attrs
[0];
198 Assert
.IsTrue (aua
.AllowMultiple
, "AllowMultiple");
199 Assert
.IsFalse (aua
.Inherited
, "Inherited");
200 AttributeTargets at
= (AttributeTargets
.Assembly
| AttributeTargets
.Class
| AttributeTargets
.Struct
| AttributeTargets
.Constructor
| AttributeTargets
.Method
);
201 Assert
.AreEqual (at
, aua
.ValidOn
, "ValidOn");