2 // HttpApplicationCas.cs - CAS unit tests for System.Web.HttpApplication
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.Security;
33 using System.Security.Permissions;
36 namespace MonoCasTests.System.Web {
40 public class HttpApplicationCas : AspNetHostingMinimal {
42 private void Handler (object sender, EventArgs e)
47 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
48 public void Properties_Deny_Unrestricted ()
50 HttpApplication app = new HttpApplication ();
52 if (app.Application == null) {
54 Assert.IsNull (app.Application, "Application");
57 Assert.IsNotNull (app.Application, "Application");
59 Assert.IsNull (app.Context, "Context");
60 Assert.IsNotNull (app.Server, "Server");
61 Assert.IsNull (app.Site, "Site");
65 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
66 public void Events_Deny_Unrestricted ()
68 HttpApplication app = new HttpApplication ();
69 app.Disposed += new EventHandler (Handler);
70 app.Error += new EventHandler (Handler);
71 app.PreSendRequestContent += new EventHandler (Handler);
72 app.PreSendRequestHeaders += new EventHandler (Handler);
73 app.AcquireRequestState += new EventHandler (Handler);
74 app.AuthenticateRequest += new EventHandler (Handler);
75 app.AuthorizeRequest += new EventHandler (Handler);
76 app.BeginRequest += new EventHandler (Handler);
77 app.EndRequest += new EventHandler (Handler);
78 app.PostRequestHandlerExecute += new EventHandler (Handler);
79 app.PreRequestHandlerExecute += new EventHandler (Handler);
80 app.ReleaseRequestState += new EventHandler (Handler);
81 app.ResolveRequestCache += new EventHandler (Handler);
82 app.UpdateRequestCache += new EventHandler (Handler);
84 app.AddOnAcquireRequestStateAsync (null, null);
85 app.AddOnAuthenticateRequestAsync (null, null);
86 app.AddOnAuthorizeRequestAsync (null, null);
87 app.AddOnBeginRequestAsync (null, null);
88 app.AddOnEndRequestAsync (null, null);
89 app.AddOnPostRequestHandlerExecuteAsync (null, null);
90 app.AddOnPreRequestHandlerExecuteAsync (null, null);
91 app.AddOnReleaseRequestStateAsync (null, null);
92 app.AddOnResolveRequestCacheAsync (null, null);
93 app.AddOnUpdateRequestCacheAsync (null, null);
95 app.Disposed -= new EventHandler (Handler);
96 app.Error -= new EventHandler (Handler);
97 app.PreSendRequestContent -= new EventHandler (Handler);
98 app.PreSendRequestHeaders -= new EventHandler (Handler);
99 app.AcquireRequestState -= new EventHandler (Handler);
100 app.AuthenticateRequest -= new EventHandler (Handler);
101 app.AuthorizeRequest -= new EventHandler (Handler);
102 app.BeginRequest -= new EventHandler (Handler);
103 app.EndRequest -= new EventHandler (Handler);
104 app.PostRequestHandlerExecute -= new EventHandler (Handler);
105 app.PreRequestHandlerExecute -= new EventHandler (Handler);
106 app.ReleaseRequestState -= new EventHandler (Handler);
107 app.ResolveRequestCache -= new EventHandler (Handler);
108 app.UpdateRequestCache -= new EventHandler (Handler);
110 app.PostAuthenticateRequest += new EventHandler (Handler);
111 app.PostAuthorizeRequest += new EventHandler (Handler);
112 app.PostResolveRequestCache += new EventHandler (Handler);
113 app.PostMapRequestHandler += new EventHandler (Handler);
114 app.PostAcquireRequestState += new EventHandler (Handler);
115 app.PostReleaseRequestState += new EventHandler (Handler);
116 app.PostUpdateRequestCache += new EventHandler (Handler);
118 app.AddOnPostAuthenticateRequestAsync (null, null);
119 app.AddOnPostAuthenticateRequestAsync (null, null, null);
120 app.AddOnPostAuthorizeRequestAsync (null, null);
121 app.AddOnPostAuthorizeRequestAsync (null, null, null);
122 app.AddOnPostResolveRequestCacheAsync (null, null);
123 app.AddOnPostResolveRequestCacheAsync (null, null, null);
124 app.AddOnPostMapRequestHandlerAsync (null, null);
125 app.AddOnPostMapRequestHandlerAsync (null, null, null);
126 app.AddOnPostAcquireRequestStateAsync (null, null);
127 app.AddOnPostAcquireRequestStateAsync (null, null, null);
128 app.AddOnPostReleaseRequestStateAsync (null, null);
129 app.AddOnPostReleaseRequestStateAsync (null, null, null);
130 app.AddOnPostUpdateRequestCacheAsync (null, null);
131 app.AddOnPostUpdateRequestCacheAsync (null, null, null);
133 app.AddOnAcquireRequestStateAsync (null, null, null);
134 app.AddOnAuthenticateRequestAsync (null, null, null);
135 app.AddOnAuthorizeRequestAsync (null, null, null);
136 app.AddOnBeginRequestAsync (null, null, null);
137 app.AddOnEndRequestAsync (null, null, null);
138 app.AddOnPostRequestHandlerExecuteAsync (null, null, null);
139 app.AddOnPreRequestHandlerExecuteAsync (null, null, null);
140 app.AddOnReleaseRequestStateAsync (null, null, null);
141 app.AddOnResolveRequestCacheAsync (null, null, null);
142 app.AddOnUpdateRequestCacheAsync (null, null, null);
144 app.PostAuthenticateRequest -= new EventHandler (Handler);
145 app.PostAuthorizeRequest -= new EventHandler (Handler);
146 app.PostResolveRequestCache -= new EventHandler (Handler);
147 app.PostMapRequestHandler -= new EventHandler (Handler);
148 app.PostAcquireRequestState -= new EventHandler (Handler);
149 app.PostReleaseRequestState -= new EventHandler (Handler);
150 app.PostUpdateRequestCache -= new EventHandler (Handler);
155 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
156 public void Methods_Deny_Unrestricted ()
158 HttpApplication app = new HttpApplication ();
159 app.CompleteRequest ();
160 app.GetVaryByCustomString (null, String.Empty);
165 [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.High)]
166 [ExpectedException (typeof (SecurityException))]
167 public void Modules_Deny_Unrestricted ()
169 HttpApplication app = new HttpApplication ();
170 Assert.IsNotNull (app.Modules, "Modules");
174 [AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.High)]
175 public void Modules_PermitOnly_High ()
177 HttpApplication app = new HttpApplication ();
178 Assert.IsNotNull (app.Modules, "Modules");
182 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
183 public void Request_Deny_Unrestricted ()
185 HttpApplication app = new HttpApplication ();
187 Assert.IsNotNull (app.Request, "Request");
189 catch (HttpException) {
192 catch (TypeInitializationException) {
198 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
199 public void Response_Deny_Unrestricted ()
201 HttpApplication app = new HttpApplication ();
203 Assert.IsNotNull (app.Response, "Response");
205 catch (HttpException) {
208 catch (TypeInitializationException) {
214 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
215 public void Session_Deny_Unrestricted ()
217 HttpApplication app = new HttpApplication ();
219 Assert.IsNotNull (app.Session, "Session");
221 catch (HttpException) {
224 catch (TypeInitializationException) {
230 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
231 public void User_Deny_Unrestricted ()
233 HttpApplication app = new HttpApplication ();
235 Assert.IsNull (app.User);
237 catch (HttpException) {
240 catch (TypeInitializationException) {
247 public override Type Type {
248 get { return typeof (HttpApplication); }