ISAPIRuntimeCas.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // ISAPIRuntimeCas.cs - CAS unit tests for System.Web.Hosting.ISAPIRuntime
  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.Reflection;
  31. using System.Security;
  32. using System.Security.Permissions;
  33. using System.Web;
  34. using System.Web.Hosting;
  35. namespace MonoCasTests.System.Web.Hosting {
  36. [TestFixture]
  37. [Category ("CAS")]
  38. public class ISAPIRuntimeCas : AspNetHostingMinimal {
  39. private ISAPIRuntime isapi;
  40. [TestFixtureSetUp]
  41. public void FixtureSetUp ()
  42. {
  43. // we're at full trust here
  44. isapi = new ISAPIRuntime ();
  45. }
  46. // test ctor (those tests aren't affected by a LinkDemand)
  47. [Test]
  48. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  49. [ExpectedException (typeof (SecurityException))]
  50. public void Constructor_Deny_UnmanagedCode ()
  51. {
  52. new ISAPIRuntime ();
  53. }
  54. [Test]
  55. [AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Minimal)]
  56. #if NET_2_0
  57. [ExpectedException (typeof (SecurityException))]
  58. #endif
  59. public void Constructor_Deny_AspNetHostingPermission ()
  60. {
  61. new ISAPIRuntime ();
  62. }
  63. [Test]
  64. [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
  65. [AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Minimal)]
  66. public void Constructor_PermitOnly_UnmanagedCode ()
  67. {
  68. new ISAPIRuntime ();
  69. }
  70. // only StopProcessing requires some permissions (UnmanagedCode)
  71. [Test]
  72. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  73. public void Members_Deny_Unrestricted ()
  74. {
  75. try {
  76. isapi.DoGCCollect ();
  77. }
  78. catch (NotImplementedException) {
  79. // mono
  80. }
  81. try {
  82. isapi.ProcessRequest (IntPtr.Zero, 0);
  83. }
  84. #if NET_2_0
  85. catch (AccessViolationException) {
  86. // fx2.0
  87. }
  88. #else
  89. catch (NullReferenceException) {
  90. // fx1.x
  91. }
  92. #endif
  93. catch (NotImplementedException) {
  94. // mono
  95. }
  96. try {
  97. isapi.StartProcessing ();
  98. }
  99. catch (NotImplementedException) {
  100. // mono
  101. }
  102. #if NET_2_0
  103. try {
  104. isapi.InitializeLifetimeService ();
  105. }
  106. catch (NotImplementedException) {
  107. // mono
  108. }
  109. #endif
  110. }
  111. [Test]
  112. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  113. #if NET_2_0
  114. [ExpectedException (typeof (SecurityException))]
  115. #endif
  116. public void StopProcessing_Deny_UnmanagedCode ()
  117. {
  118. try {
  119. isapi.StopProcessing ();
  120. }
  121. #if ONLY_1_1
  122. catch (TypeInitializationException) {
  123. // fx 1.x
  124. }
  125. catch (NotImplementedException) {
  126. // mono
  127. }
  128. #endif
  129. finally {
  130. }
  131. }
  132. [Test]
  133. [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
  134. public void StopProcessing_PermitOnly_UnmanagedCode ()
  135. {
  136. try {
  137. isapi.StopProcessing ();
  138. }
  139. #if ONLY_1_1
  140. catch (TypeInitializationException) {
  141. // fx 1.x
  142. }
  143. #endif
  144. catch (NotImplementedException) {
  145. // mono
  146. }
  147. }
  148. // test for LinkDemand on class
  149. [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
  150. public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
  151. {
  152. // in this case testing the ctor isn't very conveniant
  153. // because it has a Demand similar to the LinkDemand.
  154. try {
  155. return base.CreateControl (action, level);
  156. }
  157. catch (TargetInvocationException tie) {
  158. throw tie.InnerException;
  159. }
  160. }
  161. public override Type Type {
  162. get { return typeof (ISAPIRuntime); }
  163. }
  164. }
  165. }