HttpWorkerRequestCas.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // HttpWorkerRequestCas.cs - CAS unit tests for System.Web.HttpWorkerRequest
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  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:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  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.
  27. //
  28. using NUnit.Framework;
  29. using System;
  30. using System.Collections;
  31. using System.IO;
  32. using System.Reflection;
  33. using System.Security;
  34. using System.Security.Permissions;
  35. using System.Text;
  36. using System.Web;
  37. using System.Web.Caching;
  38. namespace MonoCasTests.System.Web {
  39. class CasHttpWorkerRequest : HttpWorkerRequest {
  40. public override void EndOfRequest ()
  41. {
  42. }
  43. public override void FlushResponse (bool finalFlush)
  44. {
  45. }
  46. public override string GetHttpVerbName ()
  47. {
  48. return null;
  49. }
  50. public override string GetHttpVersion ()
  51. {
  52. return null;
  53. }
  54. public override string GetLocalAddress ()
  55. {
  56. return null;
  57. }
  58. public override int GetLocalPort ()
  59. {
  60. return 0;
  61. }
  62. public override string GetQueryString ()
  63. {
  64. return null;
  65. }
  66. public override string GetRawUrl ()
  67. {
  68. return null;
  69. }
  70. public override string GetRemoteAddress ()
  71. {
  72. return null;
  73. }
  74. public override int GetRemotePort ()
  75. {
  76. return 0;
  77. }
  78. public override string GetUriPath ()
  79. {
  80. return null;
  81. }
  82. public override void SendKnownResponseHeader (int index, string value)
  83. {
  84. }
  85. public override void SendResponseFromFile (IntPtr handle, long offset, long length)
  86. {
  87. }
  88. public override void SendResponseFromFile (string filename, long offset, long length)
  89. {
  90. }
  91. public override void SendResponseFromMemory (byte[] data, int length)
  92. {
  93. }
  94. public override void SendStatus (int statusCode, string statusDescription)
  95. {
  96. }
  97. public override void SendUnknownResponseHeader (string name, string value)
  98. {
  99. }
  100. }
  101. [TestFixture]
  102. [Category ("CAS")]
  103. public class HttpWorkerRequestCas {
  104. [SetUp]
  105. public virtual void SetUp ()
  106. {
  107. if (!SecurityManager.SecurityEnabled)
  108. Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
  109. }
  110. [Test]
  111. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  112. public void Properties_Deny_Unrestricted ()
  113. {
  114. CasHttpWorkerRequest hwr = new CasHttpWorkerRequest ();
  115. Assert.IsNull (hwr.MachineConfigPath, "MachineConfigPath");
  116. Assert.IsNull (hwr.MachineInstallDirectory, "MachineInstallDirectory");
  117. #if NET_2_0
  118. Assert.IsNotNull (hwr.RequestTraceIdentifier, "RequestTraceIdentifier");
  119. Assert.IsNull (hwr.RootWebConfigPath, "RootWebConfigPath");
  120. #endif
  121. }
  122. private void Callback (HttpWorkerRequest wr, object extraData)
  123. {
  124. }
  125. [Test]
  126. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  127. public void Methods_Deny_Unrestricted ()
  128. {
  129. CasHttpWorkerRequest hwr = new CasHttpWorkerRequest ();
  130. hwr.CloseConnection ();
  131. Assert.IsNull (hwr.GetAppPath (), "GetAppPath");
  132. Assert.IsNull (hwr.GetAppPathTranslated (), "GetAppPathTranslated");
  133. Assert.IsNull (hwr.GetAppPoolID (), "GetAppPoolID");
  134. Assert.AreEqual (0, hwr.GetBytesRead (), "GetBytesRead");
  135. Assert.IsNull (hwr.GetFilePath (), "GetFilePath");
  136. Assert.IsNull (hwr.GetFilePathTranslated (), "GetGetFilePathTranslated");
  137. Assert.IsNull (hwr.GetKnownRequestHeader (0), "GetKnownRequestHeader");
  138. Assert.AreEqual (String.Empty, hwr.GetPathInfo (), "GetPathInfo");
  139. Assert.IsNull (hwr.GetPreloadedEntityBody (), "GetPreloadedEntityBody");
  140. Assert.AreEqual ("http", hwr.GetProtocol (), "GetProtocol");
  141. Assert.IsNull (hwr.GetQueryStringRawBytes (), "GetQueryStringRawBytes");
  142. Assert.AreEqual (0, hwr.GetRequestReason (), "GetRequestReason");
  143. Assert.IsNull (hwr.GetServerVariable (null), "GetServerVariable");
  144. Assert.IsNull (hwr.GetUnknownRequestHeader (null), "GetUnknownRequestHeader");
  145. Assert.IsNull (hwr.GetUnknownRequestHeaders (), "GetUnknownRequestHeaders");
  146. Assert.AreEqual (IntPtr.Zero, hwr.GetUserToken (), "GetUserToken");
  147. Assert.IsFalse (hwr.HasEntityBody (), "HasEntityBody");
  148. Assert.IsTrue (hwr.HeadersSent (), "HeadersSent");
  149. Assert.IsTrue (hwr.IsClientConnected (), "IsClientConnected");
  150. Assert.IsFalse (hwr.IsEntireEntityBodyIsPreloaded (), "IsEntireEntityBodyIsPreloaded");
  151. Assert.IsFalse (hwr.IsSecure (), "IsSecure");
  152. Assert.IsNull (hwr.MapPath (null), "MapPath");
  153. try {
  154. Assert.AreEqual (0, hwr.ReadEntityBody (new byte[1], 1), "ReadEntityBody(byte[],int)");
  155. }
  156. catch (NotImplementedException) {
  157. // mono
  158. }
  159. try {
  160. hwr.SendCalculatedContentLength (0);
  161. }
  162. catch (NotImplementedException) {
  163. // mono
  164. }
  165. hwr.SendResponseFromMemory (IntPtr.Zero, 0);
  166. hwr.SetEndOfSendNotification (new HttpWorkerRequest.EndOfSendNotification (Callback), null);
  167. Assert.IsNotNull (hwr.GetClientCertificate (), "GetClientCertificate");
  168. Assert.IsNotNull (hwr.GetClientCertificateBinaryIssuer (), "GetClientCertificateBinaryIssuer");
  169. Assert.AreEqual (0, hwr.GetClientCertificateEncoding (), "GetClientCertificateEncoding");
  170. Assert.IsNotNull (hwr.GetClientCertificatePublicKey (), "GetClientCertificatePublicKey");
  171. DateTime dt = DateTime.Now.AddMinutes (1);
  172. Assert.IsTrue (hwr.GetClientCertificateValidFrom () < dt, "GetClientCertificateValidFrom");
  173. Assert.IsTrue (hwr.GetClientCertificateValidUntil () < dt, "GetClientCertificateValidUntil");
  174. Assert.AreEqual (0, hwr.GetConnectionID (), "GetConnectionID");
  175. Assert.AreEqual (0, hwr.GetUrlContextID (), "GetUrlContextID");
  176. Assert.AreEqual (IntPtr.Zero, hwr.GetVirtualPathToken (), "GetVirtualPathToken");
  177. #if NET_2_0
  178. Assert.AreEqual (0, hwr.GetPreloadedEntityBody (new byte[0], 0), "GetPreloadedEntityBody(byte[],int)");
  179. Assert.AreEqual (0, hwr.GetPreloadedEntityBodyLength (), "GetPreloadedEntityBodyLength");
  180. Assert.AreEqual (0, hwr.GetTotalEntityBodyLength (), "GetTotalEntityBodyLength");
  181. Assert.AreEqual (0, hwr.ReadEntityBody (new byte[1], 0, 1), "ReadEntityBody(byte[],int,int)");
  182. #endif
  183. }
  184. [Test]
  185. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  186. public void StaticMethods_Deny_Unrestricted ()
  187. {
  188. Assert.AreEqual (-1, HttpWorkerRequest.GetKnownRequestHeaderIndex ("mono"), "GetKnownRequestHeaderIndex");
  189. Assert.AreEqual ("Cache-Control", HttpWorkerRequest.GetKnownRequestHeaderName (0), "GetKnownRequestHeaderName");
  190. Assert.AreEqual (-1, HttpWorkerRequest.GetKnownResponseHeaderIndex ("mono"), "GetKnownResponseHeaderIndex");
  191. Assert.AreEqual ("Cache-Control", HttpWorkerRequest.GetKnownResponseHeaderName (0), "GetKnownResponseHeaderName");
  192. Assert.AreEqual ("OK", HttpWorkerRequest.GetStatusDescription (200), "GetStatusDescription");
  193. }
  194. }
  195. }