DesignTimeTemplateParserCas.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // DesignTimeTemplateParserCas.cs
  3. // - CAS unit tests for System.Web.UI.DesignTimeTemplateParser
  4. //
  5. // Author:
  6. // Sebastien Pouliot <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Reflection;
  32. using System.Security;
  33. using System.Security.Permissions;
  34. using System.Web;
  35. using System.Web.UI;
  36. namespace MonoCasTests.System.Web.UI {
  37. [TestFixture]
  38. [Category ("CAS")]
  39. public class DesignTimeTemplateParserCas : AspNetHostingMinimal {
  40. private DesignTimeParseData dtpd;
  41. [TestFixtureSetUp]
  42. public void FixtureSetUp ()
  43. {
  44. dtpd = new DesignTimeParseData (null, "parseText");
  45. }
  46. [Test]
  47. [SecurityPermission (SecurityAction.Deny, ControlThread = true)]
  48. [ExpectedException (typeof (SecurityException))]
  49. public void ParseControl_Deny_ControlThread ()
  50. {
  51. DesignTimeTemplateParser.ParseControl (dtpd);
  52. }
  53. [Test]
  54. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  55. [ExpectedException (typeof (SecurityException))]
  56. public void ParseControl_Deny_UnmanagedCode ()
  57. {
  58. DesignTimeTemplateParser.ParseControl (dtpd);
  59. }
  60. [Test]
  61. [SecurityPermission (SecurityAction.PermitOnly, ControlThread = true, UnmanagedCode = true)]
  62. #if ONLY_1_1
  63. [ExpectedException (typeof (NullReferenceException))]
  64. #endif
  65. public void ParseControl_PermitOnly_ControlThreadUnmanagedCode ()
  66. {
  67. DesignTimeTemplateParser.ParseControl (dtpd);
  68. }
  69. [Test]
  70. [SecurityPermission (SecurityAction.Deny, ControlThread = true)]
  71. [ExpectedException (typeof (SecurityException))]
  72. public void ParseTemplate_Deny_ControlThread ()
  73. {
  74. DesignTimeTemplateParser.ParseTemplate (dtpd);
  75. }
  76. [Test]
  77. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  78. [ExpectedException (typeof (SecurityException))]
  79. public void ParseTemplate_Deny_UnmanagedCode ()
  80. {
  81. DesignTimeTemplateParser.ParseTemplate (dtpd);
  82. }
  83. [Test]
  84. [SecurityPermission (SecurityAction.PermitOnly, ControlThread = true, UnmanagedCode = true)]
  85. #if ONLY_1_1
  86. [ExpectedException (typeof (NullReferenceException))]
  87. #endif
  88. public void ParseTemplate_PermitOnly_ControlThreadUnmanagedCode ()
  89. {
  90. DesignTimeTemplateParser.ParseTemplate (dtpd);
  91. }
  92. #if NET_2_0
  93. [Test]
  94. [SecurityPermission (SecurityAction.Deny, ControlThread = true)]
  95. [ExpectedException (typeof (SecurityException))]
  96. public void ParseControls_Deny_ControlThread ()
  97. {
  98. DesignTimeTemplateParser.ParseControls (dtpd);
  99. }
  100. [Test]
  101. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  102. [ExpectedException (typeof (SecurityException))]
  103. public void ParseControls_Deny_UnmanagedCode ()
  104. {
  105. DesignTimeTemplateParser.ParseControls (dtpd);
  106. }
  107. [Test]
  108. [SecurityPermission (SecurityAction.PermitOnly, ControlThread = true, UnmanagedCode = true)]
  109. public void ParseControls_PermitOnly_ControlThreadUnmanagedCode ()
  110. {
  111. DesignTimeTemplateParser.ParseControls (dtpd);
  112. }
  113. [Test]
  114. [SecurityPermission (SecurityAction.Deny, ControlThread = true)]
  115. [ExpectedException (typeof (SecurityException))]
  116. public void ParseTheme_Deny_ControlThread ()
  117. {
  118. try {
  119. DesignTimeTemplateParser.ParseTheme (null, "theme", "path");
  120. }
  121. catch (Exception) {
  122. // security exception gets hidden :-(
  123. Assert.Ignore ("security exception gets hidden :-(");
  124. }
  125. }
  126. [Test]
  127. [SecurityPermission (SecurityAction.PermitOnly, ControlThread = true)]
  128. public void ParseTheme_PermitOnly_ControlThread ()
  129. {
  130. DesignTimeTemplateParser.ParseTheme (null, "theme", "path");
  131. }
  132. #endif
  133. // LinkDemand
  134. [SecurityPermission (SecurityAction.Assert, UnmanagedCode = true, ControlThread = true)]
  135. public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
  136. {
  137. try {
  138. // static class 2.0 / no public ctor before (1.x)
  139. MethodInfo mi = this.Type.GetMethod ("ParseTemplate");
  140. Assert.IsNotNull (mi, "ParseTemplate");
  141. return mi.Invoke (null, new object[1] { dtpd });
  142. }
  143. catch (TargetInvocationException tie) {
  144. #if ONLY_1_1
  145. if (tie.InnerException is NullReferenceException)
  146. return String.Empty;
  147. #endif
  148. throw tie;
  149. }
  150. }
  151. public override Type Type {
  152. get { return typeof (DesignTimeTemplateParser); }
  153. }
  154. }
  155. }