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.
31 using NUnit.Framework;
33 using System.Collections;
34 using System.Security;
35 using System.Security.Policy;
37 namespace MonoTests.System.Security.Policy {
40 public class ApplicationSecurityManagerTest {
42 private string defaultTrustManagerTypeName;
45 public void FixtureSetUp ()
47 defaultTrustManagerTypeName = ApplicationSecurityManager.ApplicationTrustManager.GetType ().AssemblyQualifiedName;
51 public void ApplicationTrustManager ()
53 Assert.IsNotNull (ApplicationSecurityManager.ApplicationTrustManager);
57 public void UserApplicationTrusts ()
59 Assert.AreEqual (0, ApplicationSecurityManager.UserApplicationTrusts.Count);
62 // FIXME: creating an ActivationContext here seems not easy
65 // [ExpectedException (typeof (ArgumentNullException))]
66 [ExpectedException (typeof (NullReferenceException))]
67 public void DetermineApplicationTrust_Null_Null ()
69 ApplicationSecurityManager.DetermineApplicationTrust (null, null);
73 // [ExpectedException (typeof (ArgumentNullException))]
74 [ExpectedException (typeof (NullReferenceException))]
75 public void DetermineApplicationTrust_Null_TrustManagerContext ()
77 ApplicationSecurityManager.DetermineApplicationTrust (null, new TrustManagerContext ());
80 // testing the default application security manager here
82 // FIXME: creating an ActivationContext here seems not easy
85 [ExpectedException (typeof (ArgumentNullException))]
86 public void DefaultTrustManager_DetermineApplicationTrust_Null_Null ()
88 ApplicationSecurityManager.ApplicationTrustManager.DetermineApplicationTrust (null, null);
92 [ExpectedException (typeof (ArgumentNullException))]
93 public void DefaultTrustManager_DetermineApplicationTrust_Null_TrustManagerContext ()
95 ApplicationSecurityManager.ApplicationTrustManager.DetermineApplicationTrust (null, new TrustManagerContext ());
99 [ExpectedException (typeof (ArgumentNullException))]
100 public void DefaultTrustManager_FromXml_Null ()
102 ApplicationSecurityManager.ApplicationTrustManager.FromXml (null);
106 [ExpectedException (typeof (ArgumentException))]
107 public void DefaultTrustManager_FromXml_BadTag ()
109 SecurityElement se = new SecurityElement (String.Empty);
110 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
113 private void CheckXml (SecurityElement se)
115 Assert.AreEqual (defaultTrustManagerTypeName, se.Attribute ("class"), "class");
116 Assert.AreEqual ("1", se.Attribute ("version"), "version");
117 Assert.AreEqual (2, se.Attributes.Count, "Count");
118 Assert.IsNull (se.Children, "Children");
122 public void DefaultTrustManager_FromXml_NoAttributes ()
124 SecurityElement se = new SecurityElement ("IApplicationTrustManager");
125 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
127 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
131 public void DefaultTrustManager_FromXml_BadClass ()
133 SecurityElement se = new SecurityElement ("IApplicationTrustManager");
134 se.AddAttribute ("class", "System.DoesntExist");
135 se.AddAttribute ("version", "1");
136 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
138 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
142 public void DefaultTrustManager_FromXml_BadVersion ()
144 SecurityElement se = new SecurityElement ("IApplicationTrustManager");
145 se.AddAttribute ("class", defaultTrustManagerTypeName);
146 se.AddAttribute ("version", "42");
147 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
149 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
153 public void DefaultTrustManager_FromXml ()
155 SecurityElement se = new SecurityElement ("IApplicationTrustManager");
156 se.AddAttribute ("class", defaultTrustManagerTypeName);
157 se.AddAttribute ("version", "1");
158 ApplicationSecurityManager.ApplicationTrustManager.FromXml (se);
160 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());
164 public void DefaultTrustManager_ToXml ()
166 CheckXml (ApplicationSecurityManager.ApplicationTrustManager.ToXml ());