2 // ApplicationSecurityManagerTest.cs -
3 // NUnit Test Cases for ApplicationSecurityManager
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 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.
32 using NUnit.Framework;
34 using System.Collections;
35 using System.Security;
36 using System.Security.Policy;
38 namespace MonoTests.System.Security.Policy {
41 public class ApplicationSecurityManagerTest {
43 private string defaultTrustManagerTypeName;
46 public void FixtureSetUp ()
48 defaultTrustManagerTypeName = ApplicationSecurityManager.ApplicationTrustManager.GetType ().AssemblyQualifiedName;
52 public void ApplicationTrustManager ()
54 Assert.IsNotNull (ApplicationSecurityManager.ApplicationTrustManager);
58 public void UserApplicationTrusts ()
60 Assert.AreEqual (0, ApplicationSecurityManager.UserApplicationTrusts.Count);
63 // FIXME: creating an ActivationContext here seems not easy
66 // [ExpectedException (typeof (ArgumentNullException))]
67 [ExpectedException (typeof (NullReferenceException))]
68 public void DetermineApplicationTrust_Null_Null ()
70 ApplicationSecurityManager.DetermineApplicationTrust (null, null);
74 // [ExpectedException (typeof (ArgumentNullException))]
75 [ExpectedException (typeof (NullReferenceException))]
76 public void DetermineApplicationTrust_Null_TrustManagerContext ()
78 ApplicationSecurityManager.DetermineApplicationTrust (null, new TrustManagerContext ());
81 // testing the default application security manager here
83 // FIXME: creating an ActivationContext here seems not easy
86 [ExpectedException (typeof (ArgumentNullException))]
87 public void DefaultTrustManager_DetermineApplicationTrust_Null_Null ()
89 ApplicationSecurityManager.ApplicationTrustManager.DetermineApplicationTrust (null, null);
93 [ExpectedException (typeof (ArgumentNullException))]
94 public void DefaultTrustManager_DetermineApplicationTrust_Null_TrustManagerContext ()
96 ApplicationSecurityManager.ApplicationTrustManager.DetermineApplicationTrust (null, new TrustManagerContext ());
100 [ExpectedException (typeof (ArgumentNullException))]
101 public void DefaultTrustManager_FromXml_Null ()
103 ApplicationSecurityManager.ApplicationTrustManager.FromXml (null);
107 [ExpectedException (typeof (ArgumentException))]
108 public void DefaultTrustManager_FromXml_BadTag ()
110 SecurityElement se = new SecurityElement (String.Empty);
111 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
114 private void CheckXml (SecurityElement se)
116 Assert.AreEqual (defaultTrustManagerTypeName, se.Attribute ("class"), "class");
117 Assert.AreEqual ("1", se.Attribute ("version"), "version");
118 Assert.AreEqual (2, se.Attributes.Count, "Count");
119 Assert.IsNull (se.Children, "Children");
123 public void DefaultTrustManager_FromXml_NoAttributes ()
125 SecurityElement se = new SecurityElement ("IApplicationTrustManager");
126 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
128 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
132 public void DefaultTrustManager_FromXml_BadClass ()
134 SecurityElement se = new SecurityElement ("IApplicationTrustManager");
135 se.AddAttribute ("class", "System.DoesntExist");
136 se.AddAttribute ("version", "1");
137 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
139 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
143 public void DefaultTrustManager_FromXml_BadVersion ()
145 SecurityElement se = new SecurityElement ("IApplicationTrustManager");
146 se.AddAttribute ("class", defaultTrustManagerTypeName);
147 se.AddAttribute ("version", "42");
148 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
150 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
154 public void DefaultTrustManager_FromXml ()
156 SecurityElement se = new SecurityElement ("IApplicationTrustManager");
157 se.AddAttribute ("class", defaultTrustManagerTypeName);
158 se.AddAttribute ("version", "1");
159 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
161 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
165 public void DefaultTrustManager_ToXml ()
167 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());