FormsAuthenticationTicketCas.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // FormsAuthenticationTicketCasCas.cs
  3. // - CAS unit tests for System.Web.Security.FormsAuthenticationTicketCas
  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.Security;
  36. namespace MonoCasTests.System.Web.Security {
  37. [TestFixture]
  38. [Category ("CAS")]
  39. public class FormsAuthenticationTicketCas : AspNetHostingMinimal {
  40. [Test]
  41. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  42. public void Constructor3 ()
  43. {
  44. FormsAuthenticationTicket ticket = null;
  45. try {
  46. // this ctor got a problem on MS 1.x
  47. ticket = new FormsAuthenticationTicket ("mine", false, Int32.MaxValue);
  48. }
  49. catch (NullReferenceException) {
  50. #if NET_2_0
  51. Assert.Fail ("this should work on 2.0");
  52. #else
  53. Assert.Ignore ("fails with NullReferenceException on MS 1.x");
  54. #endif
  55. }
  56. Assert.AreEqual ("/", ticket.CookiePath, "CookiePath");
  57. Assert.IsTrue (ticket.Expiration.Year >= 6088, "Expiration");
  58. Assert.IsFalse (ticket.Expired, "Expired");
  59. Assert.IsFalse (ticket.IsPersistent, "IsPersistent");
  60. Assert.IsTrue (ticket.IssueDate <= DateTime.Now, "IssueDate");
  61. Assert.AreEqual ("mine", ticket.Name, "Name");
  62. Assert.AreEqual (String.Empty, ticket.UserData, "UserData");
  63. Assert.IsTrue (ticket.Version > 0, "Version");
  64. }
  65. [Test]
  66. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  67. public void Constructor6 ()
  68. {
  69. FormsAuthenticationTicket ticket = null;
  70. try {
  71. // this ctor got a problem on MS 1.x
  72. ticket = new FormsAuthenticationTicket (1, "mine", DateTime.MinValue, DateTime.MaxValue, true, "data");
  73. }
  74. catch (NullReferenceException) {
  75. #if NET_2_0
  76. Assert.Fail ("this should work on 2.0");
  77. #else
  78. Assert.Ignore ("fails with NullReferenceException on MS 1.x");
  79. #endif
  80. }
  81. Assert.AreEqual ("/", ticket.CookiePath, "CookiePath");
  82. Assert.AreEqual (DateTime.MaxValue, ticket.Expiration, "Expiration");
  83. Assert.IsFalse (ticket.Expired, "Expired");
  84. Assert.IsTrue (ticket.IsPersistent, "IsPersistent");
  85. Assert.AreEqual (DateTime.MinValue, ticket.IssueDate, "IssueDate");
  86. Assert.AreEqual ("mine", ticket.Name, "Name");
  87. Assert.AreEqual ("data", ticket.UserData, "UserData");
  88. Assert.AreEqual (1, ticket.Version, "Version");
  89. }
  90. [Test]
  91. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  92. public void Constructor7 ()
  93. {
  94. FormsAuthenticationTicket ticket = new FormsAuthenticationTicket (3, "mine", DateTime.MinValue, DateTime.Now.AddSeconds (-1), false, "data", "path");
  95. Assert.AreEqual ("path", ticket.CookiePath, "CookiePath");
  96. Assert.IsTrue (ticket.Expiration <= DateTime.Now, "Expiration");
  97. Assert.IsTrue (ticket.Expired, "Expired");
  98. Assert.IsFalse (ticket.IsPersistent, "IsPersistent");
  99. Assert.AreEqual (DateTime.MinValue, ticket.IssueDate, "IssueDate");
  100. Assert.AreEqual ("mine", ticket.Name, "Name");
  101. Assert.AreEqual ("data", ticket.UserData, "UserData");
  102. Assert.AreEqual (3, ticket.Version, "Version");
  103. }
  104. // LinkDemand
  105. public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
  106. {
  107. // we can't take the simpler (3 params) ctor as it fails under 1.x (NRE)
  108. ConstructorInfo ci = this.Type.GetConstructor (new Type[7] { typeof (int), typeof (string), typeof (DateTime), typeof (DateTime), typeof (bool), typeof (string), typeof (string) });
  109. Assert.IsNotNull (ci, ".ctor(string,bool,int)");
  110. return ci.Invoke (new object[7] { 3, "mine", DateTime.MinValue, DateTime.Now.AddSeconds (-1), false, "data", "path" });
  111. }
  112. public override Type Type {
  113. get { return typeof (FormsAuthenticationTicket); }
  114. }
  115. }
  116. }