2 // HttpRuntimeCas.cs - CAS unit tests for System.Web.HttpRuntime
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.
29 using NUnit.Framework;
32 using System.Reflection;
33 using System.Security;
34 using System.Security.Permissions;
35 using System.Security.Principal;
38 namespace MonoCasTests.System.Web {
42 public class HttpRuntimeCas : AspNetHostingMinimal {
45 public void FixtureSetUp ()
47 // static ctor at fulltrust
53 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
54 public void Constructor_Deny_Unrestricted ()
60 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
61 [ExpectedException (typeof (SecurityException))]
62 public void Constructor_Deny_UnmanagedCode ()
68 [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
69 public void Constructor_PermitOnly_UnmanagedCode ()
76 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
77 public void StaticProperties ()
79 Assert.IsNull (HttpRuntime.AppDomainAppVirtualPath, "AppDomainAppVirtualPath");
80 Assert.IsNotNull (HttpRuntime.Cache, "Cache");
84 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
85 [ExpectedException (typeof (SecurityException))]
86 public void AppDomainAppPath_Deny ()
89 Assert.IsNotNull (HttpRuntime.AppDomainAppPath, "AppDomainAppPath");
91 catch (ArgumentNullException) {
92 Assert.Ignore ("fails before the security check");
97 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
98 [ExpectedException (typeof (SecurityException))]
99 public void BinDirectory_Deny ()
102 Assert.IsNotNull (HttpRuntime.BinDirectory, "BinDirectory");
104 catch (ArgumentException) {
105 Assert.Ignore ("fails before the security check");
110 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
111 [ExpectedException (typeof (SecurityException))]
112 public void CodegenDir_Deny ()
115 Assert.IsNotNull (HttpRuntime.CodegenDir, "CodegenDir");
117 catch (ArgumentNullException) {
118 Assert.Ignore ("fails before the security check");
123 [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.High)]
124 [ExpectedException (typeof (SecurityException))]
125 public void AppDomainAppId_Deny_High ()
127 Assert.IsNull (HttpRuntime.AppDomainAppId, "AppDomainAppId");
131 [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.High)]
132 [ExpectedException (typeof (SecurityException))]
133 public void AppDomainId_Deny_High ()
135 Assert.IsNull (HttpRuntime.AppDomainId, "AppDomainId");
139 [AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.High)]
140 public void PermitOnly_High ()
142 Assert.IsNull (HttpRuntime.AppDomainAppId, "AppDomainAppId");
143 Assert.IsNull (HttpRuntime.AppDomainId, "AppDomainId");
147 [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Low)]
148 [ExpectedException (typeof (SecurityException))]
149 public void IsOnUNCShare_Deny_High ()
151 Assert.IsFalse (HttpRuntime.IsOnUNCShare, "IsOnUNCShare");
155 [AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.High)]
156 public void IsOnUNCShare_PermitOnly_High ()
159 Assert.IsFalse (HttpRuntime.IsOnUNCShare, "IsOnUNCShare");
161 catch (NotImplementedException) {
167 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
168 [ExpectedException (typeof (SecurityException))]
169 public void AspInstallDirectory_Deny_FileIOPermission ()
171 if (HttpRuntime.AspInstallDirectory == null)
172 Assert.Ignore ("null isn't checked for FileIOPermission");
176 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
177 [ExpectedException (typeof (SecurityException))]
178 public void ClrInstallDirectory_Deny_FileIOPermission ()
180 Assert.IsNotNull (HttpRuntime.ClrInstallDirectory, "ClrInstallDirectory");
184 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
185 [ExpectedException (typeof (SecurityException))]
186 public void MachineConfigurationDirectory_Deny_FileIOPermission ()
188 Assert.IsNotNull (HttpRuntime.MachineConfigurationDirectory, "MachineConfigurationDirectory");
192 [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
193 public void PermitOnly_PathDiscovery ()
195 string s = HttpRuntime.AspInstallDirectory; // null in unit tests for mono
196 Assert.IsNotNull (HttpRuntime.ClrInstallDirectory, "ClrInstallDirectory");
197 Assert.IsNotNull (HttpRuntime.MachineConfigurationDirectory, "MachineConfigurationDirectory");
201 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
202 [ExpectedException (typeof (SecurityException))]
203 public void Close_Deny_Unmanaged ()
205 HttpRuntime.Close ();
209 [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
210 public void Close_PermitOnly_Unmanaged ()
212 HttpRuntime.Close ();
216 [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Medium)]
217 [ExpectedException (typeof (SecurityException))]
218 public void ProcessRequest_Deny_Medium ()
220 HttpRuntime.ProcessRequest (null);
224 [AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Medium)]
225 [ExpectedException (typeof (ArgumentNullException))]
226 public void ProcessRequest_PermitOnly_Medium ()
228 HttpRuntime.ProcessRequest (null);
232 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
233 [ExpectedException (typeof (SecurityException))]
234 public void UnloadAppDomain_Deny_Unmanaged ()
236 HttpRuntime.UnloadAppDomain ();
240 [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
241 public void UnloadAppDomain_PermitOnly_Unmanaged ()
243 HttpRuntime.UnloadAppDomain ();
248 // note: the .ctor also has a LinkDemand for UnmanagedCode (which mess up the results)
249 [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
250 public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
252 ConstructorInfo ci = this.Type.GetConstructor (VoidType);
253 Assert.IsNotNull (ci, "default .ctor");
254 return ci.Invoke (null);
257 public override Type Type {
258 get { return typeof (HttpRuntime); }