2 // HostSecurityManagerTest.cs - NUnit Test Cases for HostSecurityManager
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System.Reflection;
34 //using System.Runtime.Hosting;
35 using System.Security;
36 using System.Security.Policy;
38 namespace MonoTests.System.Security {
41 public class HostSecurityManagerTest {
44 public void Defaults ()
46 HostSecurityManager hsm = new HostSecurityManager ();
47 Assert.IsNull (hsm.DomainPolicy, "DomainPolicy");
48 Assert.AreEqual (HostSecurityManagerOptions.AllFlags, hsm.Flags, "Flags");
52 [ExpectedException (typeof (ArgumentNullException))]
53 public void DetermineApplicationTrust_Null_Evidence_TrustManagerContext ()
55 HostSecurityManager hsm = new HostSecurityManager ();
56 hsm.DetermineApplicationTrust (null, new Evidence (), new TrustManagerContext ());
60 [Category ("NotWorking")]
61 [ExpectedException (typeof (ArgumentException))]
62 public void DetermineApplicationTrust_Evidence_Null_TrustManagerContext ()
64 HostSecurityManager hsm = new HostSecurityManager ();
65 Evidence app = new Evidence ();
66 //app.AddHost (new ActivationArgument ());
67 hsm.DetermineApplicationTrust (app, null, new TrustManagerContext ());
71 [Category ("NotWorking")]
72 [ExpectedException (typeof (ArgumentException))]
73 public void DetermineApplicationTrust_Evidence_Evidence_Null ()
75 HostSecurityManager hsm = new HostSecurityManager ();
76 hsm.DetermineApplicationTrust (new Evidence (), new Evidence (), null);
80 public void ProvideAppDomainEvidence ()
82 HostSecurityManager hsm = new HostSecurityManager ();
83 Assert.IsNull (hsm.ProvideAppDomainEvidence (null), "null");
85 Evidence e = new Evidence ();
86 Evidence result = hsm.ProvideAppDomainEvidence (e);
87 Assert.IsNotNull (result, "empty");
88 Assert.AreEqual (0, result.Count, "Count-0");
90 e.AddHost (new Zone (SecurityZone.Untrusted));
91 result = hsm.ProvideAppDomainEvidence (e);
92 Assert.AreEqual (1, result.Count, "Count-1");
96 public void ProvideAssemblyEvidence ()
98 HostSecurityManager hsm = new HostSecurityManager ();
99 Assembly a = Assembly.GetExecutingAssembly ();
101 Evidence result = hsm.ProvideAssemblyEvidence (a, null);
102 Assert.IsNull (result, "null");
104 Evidence e = new Evidence ();
105 result = hsm.ProvideAssemblyEvidence (a, e);
106 Assert.AreEqual (0, result.Count, "Count-empty");
108 e.AddHost (new Zone (SecurityZone.Untrusted));
109 result = hsm.ProvideAssemblyEvidence (a, e);
110 Assert.AreEqual (1, result.Count, "Count-1");
114 public void ProvideAssemblyEvidence_NullAssembly ()
116 HostSecurityManager hsm = new HostSecurityManager ();
118 Evidence result = hsm.ProvideAssemblyEvidence (null, null);
119 Assert.IsNull (result, "null");
121 Evidence e = new Evidence ();
122 result = hsm.ProvideAssemblyEvidence (null, e);
123 Assert.AreEqual (0, result.Count, "Count-empty");
125 e.AddHost (new Zone (SecurityZone.Untrusted));
126 result = hsm.ProvideAssemblyEvidence (null, e);
127 Assert.AreEqual (1, result.Count, "Count-1");
131 [ExpectedException (typeof (NullReferenceException))]
132 public void ResolvePolicy_Null ()
134 HostSecurityManager hsm = new HostSecurityManager ();
135 PermissionSet ps = hsm.ResolvePolicy (null);
139 public void ResolvePolicy_Empty ()
141 HostSecurityManager hsm = new HostSecurityManager ();
142 PermissionSet ps = hsm.ResolvePolicy (new Evidence ());
143 Assert.AreEqual (0, ps.Count, "Count");
144 Assert.IsFalse (ps.IsUnrestricted (), "IsUnrestricted");
148 public void ResolvePolicy_CurrentAssemblyEvidence ()
150 HostSecurityManager hsm = new HostSecurityManager ();
151 Assembly a = Assembly.GetExecutingAssembly ();
152 PermissionSet ps = hsm.ResolvePolicy (a.Evidence);
154 PermissionSet expected = SecurityManager.ResolvePolicy (a.Evidence);
155 Assert.AreEqual (expected.ToString (), ps.ToString (), "PermissionSet");