2 // HttpWorkerRequestCas.cs - CAS unit tests for System.Web.HttpWorkerRequest
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.Collections;
34 using System.Reflection;
35 using System.Security;
36 using System.Security.Permissions;
39 using System.Web.Caching;
41 namespace MonoCasTests.System.Web {
43 class CasHttpWorkerRequest : HttpWorkerRequest {
45 public override void EndOfRequest ()
49 public override void FlushResponse (bool finalFlush)
53 public override string GetHttpVerbName ()
58 public override string GetHttpVersion ()
63 public override string GetLocalAddress ()
68 public override int GetLocalPort ()
73 public override string GetQueryString ()
78 public override string GetRawUrl ()
83 public override string GetRemoteAddress ()
88 public override int GetRemotePort ()
93 public override string GetUriPath ()
98 public override void SendKnownResponseHeader (int index, string value)
102 public override void SendResponseFromFile (IntPtr handle, long offset, long length)
106 public override void SendResponseFromFile (string filename, long offset, long length)
110 public override void SendResponseFromMemory (byte[] data, int length)
114 public override void SendStatus (int statusCode, string statusDescription)
118 public override void SendUnknownResponseHeader (string name, string value)
125 public class HttpWorkerRequestCas {
128 public virtual void SetUp ()
130 if (!SecurityManager.SecurityEnabled)
131 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
135 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
136 public void Properties_Deny_Unrestricted ()
138 CasHttpWorkerRequest hwr = new CasHttpWorkerRequest ();
139 Assert.IsNull (hwr.MachineConfigPath, "MachineConfigPath");
140 Assert.IsNull (hwr.MachineInstallDirectory, "MachineInstallDirectory");
142 Assert.IsNotNull (hwr.RequestTraceIdentifier, "RequestTraceIdentifier");
143 Assert.IsNull (hwr.RootWebConfigPath, "RootWebConfigPath");
147 private void Callback (HttpWorkerRequest wr, object extraData)
152 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
153 public void Methods_Deny_Unrestricted ()
155 CasHttpWorkerRequest hwr = new CasHttpWorkerRequest ();
156 hwr.CloseConnection ();
157 Assert.IsNull (hwr.GetAppPath (), "GetAppPath");
158 Assert.IsNull (hwr.GetAppPathTranslated (), "GetAppPathTranslated");
159 Assert.IsNull (hwr.GetAppPoolID (), "GetAppPoolID");
160 Assert.AreEqual (0, hwr.GetBytesRead (), "GetBytesRead");
161 Assert.IsNull (hwr.GetFilePath (), "GetFilePath");
162 Assert.IsNull (hwr.GetFilePathTranslated (), "GetGetFilePathTranslated");
163 Assert.IsNull (hwr.GetKnownRequestHeader (0), "GetKnownRequestHeader");
164 Assert.AreEqual (String.Empty, hwr.GetPathInfo (), "GetPathInfo");
165 Assert.IsNull (hwr.GetPreloadedEntityBody (), "GetPreloadedEntityBody");
166 Assert.AreEqual ("http", hwr.GetProtocol (), "GetProtocol");
167 Assert.IsNull (hwr.GetQueryStringRawBytes (), "GetQueryStringRawBytes");
168 Assert.AreEqual (0, hwr.GetRequestReason (), "GetRequestReason");
169 Assert.IsNull (hwr.GetServerVariable (null), "GetServerVariable");
170 Assert.IsNull (hwr.GetUnknownRequestHeader (null), "GetUnknownRequestHeader");
171 Assert.IsNull (hwr.GetUnknownRequestHeaders (), "GetUnknownRequestHeaders");
172 Assert.AreEqual (IntPtr.Zero, hwr.GetUserToken (), "GetUserToken");
173 Assert.IsFalse (hwr.HasEntityBody (), "HasEntityBody");
174 Assert.IsTrue (hwr.HeadersSent (), "HeadersSent");
175 Assert.IsTrue (hwr.IsClientConnected (), "IsClientConnected");
176 Assert.IsFalse (hwr.IsEntireEntityBodyIsPreloaded (), "IsEntireEntityBodyIsPreloaded");
177 Assert.IsFalse (hwr.IsSecure (), "IsSecure");
178 Assert.IsNull (hwr.MapPath (null), "MapPath");
181 Assert.AreEqual (0, hwr.ReadEntityBody (new byte[1], 1), "ReadEntityBody(byte[],int)");
183 catch (NotImplementedException) {
188 hwr.SendCalculatedContentLength (0);
190 catch (NotImplementedException) {
194 hwr.SendResponseFromMemory (IntPtr.Zero, 0);
195 hwr.SetEndOfSendNotification (new HttpWorkerRequest.EndOfSendNotification (Callback), null);
197 Assert.IsNotNull (hwr.GetClientCertificate (), "GetClientCertificate");
198 Assert.IsNotNull (hwr.GetClientCertificateBinaryIssuer (), "GetClientCertificateBinaryIssuer");
199 Assert.AreEqual (0, hwr.GetClientCertificateEncoding (), "GetClientCertificateEncoding");
200 Assert.IsNotNull (hwr.GetClientCertificatePublicKey (), "GetClientCertificatePublicKey");
201 DateTime dt = DateTime.Now.AddMinutes (1);
202 Assert.IsTrue (hwr.GetClientCertificateValidFrom () < dt, "GetClientCertificateValidFrom");
203 Assert.IsTrue (hwr.GetClientCertificateValidUntil () < dt, "GetClientCertificateValidUntil");
204 Assert.AreEqual (0, hwr.GetConnectionID (), "GetConnectionID");
205 Assert.AreEqual (0, hwr.GetUrlContextID (), "GetUrlContextID");
206 Assert.AreEqual (IntPtr.Zero, hwr.GetVirtualPathToken (), "GetVirtualPathToken");
208 Assert.AreEqual (0, hwr.GetPreloadedEntityBody (new byte[0], 0), "GetPreloadedEntityBody(byte[],int)");
209 Assert.AreEqual (0, hwr.GetPreloadedEntityBodyLength (), "GetPreloadedEntityBodyLength");
210 Assert.AreEqual (0, hwr.GetTotalEntityBodyLength (), "GetTotalEntityBodyLength");
211 Assert.AreEqual (0, hwr.ReadEntityBody (new byte[1], 0, 1), "ReadEntityBody(byte[],int,int)");
216 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
217 public void StaticMethods_Deny_Unrestricted ()
219 Assert.AreEqual (-1, HttpWorkerRequest.GetKnownRequestHeaderIndex ("mono"), "GetKnownRequestHeaderIndex");
220 Assert.AreEqual ("Cache-Control", HttpWorkerRequest.GetKnownRequestHeaderName (0), "GetKnownRequestHeaderName");
221 Assert.AreEqual (-1, HttpWorkerRequest.GetKnownResponseHeaderIndex ("mono"), "GetKnownResponseHeaderIndex");
222 Assert.AreEqual ("Cache-Control", HttpWorkerRequest.GetKnownResponseHeaderName (0), "GetKnownResponseHeaderName");
223 Assert.AreEqual ("OK", HttpWorkerRequest.GetStatusDescription (200), "GetStatusDescription");