MembershipProviderTest.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //
  2. // MembershipProviderTest.cs
  3. // - Unit tests for System.Web.Security.MembershipProvider
  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. #if NET_2_0
  30. using System;
  31. using System.Configuration.Provider;
  32. using System.Security.Principal;
  33. using System.Web.Security;
  34. using System.Text;
  35. using NUnit.Framework;
  36. using MonoTests.SystemWeb.Framework;
  37. using System.Web.UI;
  38. namespace MonoTests.System.Web.Security {
  39. class TestMembershipProvider : MembershipProvider {
  40. public override string ApplicationName {
  41. get {
  42. throw new Exception ("The method or operation is not implemented.");
  43. }
  44. set {
  45. throw new Exception ("The method or operation is not implemented.");
  46. }
  47. }
  48. public override bool ChangePassword (string username, string oldPassword, string newPassword)
  49. {
  50. throw new Exception ("The method or operation is not implemented.");
  51. }
  52. public override bool ChangePasswordQuestionAndAnswer (string username, string password, string newPasswordQuestion, string newPasswordAnswer)
  53. {
  54. throw new Exception ("The method or operation is not implemented.");
  55. }
  56. public override MembershipUser CreateUser (string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
  57. {
  58. throw new Exception ("The method or operation is not implemented.");
  59. }
  60. public override bool DeleteUser (string username, bool deleteAllRelatedData)
  61. {
  62. throw new Exception ("The method or operation is not implemented.");
  63. }
  64. public override bool EnablePasswordReset {
  65. get { throw new Exception ("The method or operation is not implemented."); }
  66. }
  67. public override bool EnablePasswordRetrieval {
  68. get { throw new Exception ("The method or operation is not implemented."); }
  69. }
  70. public override MembershipUserCollection FindUsersByEmail (string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
  71. {
  72. throw new Exception ("The method or operation is not implemented.");
  73. }
  74. public override MembershipUserCollection FindUsersByName (string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
  75. {
  76. throw new Exception ("The method or operation is not implemented.");
  77. }
  78. public override MembershipUserCollection GetAllUsers (int pageIndex, int pageSize, out int totalRecords)
  79. {
  80. throw new Exception ("The method or operation is not implemented.");
  81. }
  82. public override int GetNumberOfUsersOnline ()
  83. {
  84. throw new Exception ("The method or operation is not implemented.");
  85. }
  86. public override string GetPassword (string username, string answer)
  87. {
  88. throw new Exception ("The method or operation is not implemented.");
  89. }
  90. public override MembershipUser GetUser (string username, bool userIsOnline)
  91. {
  92. throw new Exception ("The method or operation is not implemented.");
  93. }
  94. public override MembershipUser GetUser (object providerUserKey, bool userIsOnline)
  95. {
  96. throw new Exception ("The method or operation is not implemented.");
  97. }
  98. public override string GetUserNameByEmail (string email)
  99. {
  100. throw new Exception ("The method or operation is not implemented.");
  101. }
  102. public override int MaxInvalidPasswordAttempts
  103. {
  104. get { throw new Exception ("The method or operation is not implemented."); }
  105. }
  106. public override int MinRequiredNonAlphanumericCharacters
  107. {
  108. get { throw new Exception ("The method or operation is not implemented."); }
  109. }
  110. public override int MinRequiredPasswordLength
  111. {
  112. get { throw new Exception ("The method or operation is not implemented."); }
  113. }
  114. public override int PasswordAttemptWindow
  115. {
  116. get { throw new Exception ("The method or operation is not implemented."); }
  117. }
  118. public override MembershipPasswordFormat PasswordFormat
  119. {
  120. get { throw new Exception ("The method or operation is not implemented."); }
  121. }
  122. public override string PasswordStrengthRegularExpression
  123. {
  124. get { throw new Exception ("The method or operation is not implemented."); }
  125. }
  126. public override bool RequiresQuestionAndAnswer
  127. {
  128. get { throw new Exception ("The method or operation is not implemented."); }
  129. }
  130. public override bool RequiresUniqueEmail
  131. {
  132. get { throw new Exception ("The method or operation is not implemented."); }
  133. }
  134. public override string ResetPassword (string username, string answer)
  135. {
  136. throw new Exception ("The method or operation is not implemented.");
  137. }
  138. public override bool UnlockUser (string userName)
  139. {
  140. throw new Exception ("The method or operation is not implemented.");
  141. }
  142. public override void UpdateUser (MembershipUser user)
  143. {
  144. throw new Exception ("The method or operation is not implemented.");
  145. }
  146. public override bool ValidateUser (string username, string password)
  147. {
  148. throw new Exception ("The method or operation is not implemented.");
  149. }
  150. public byte[] Decrypt (byte[] data)
  151. {
  152. return base.DecryptPassword (data);
  153. }
  154. public byte[] Encrypt (byte[] data)
  155. {
  156. return base.EncryptPassword (data);
  157. }
  158. }
  159. [TestFixture]
  160. public class MembershipProviderTest {
  161. [Test]
  162. [ExpectedException (typeof (ProviderException))]
  163. public void EncryptPassword ()
  164. {
  165. WebTest t = new WebTest (PageInvoker.CreateOnLoad (EncryptOnLoad));
  166. t.Run ();
  167. }
  168. public static void EncryptOnLoad (Page p)
  169. {
  170. TestMembershipProvider mp = new TestMembershipProvider ();
  171. string password = "";
  172. byte [] buffer = ASCIIEncoding.Default.GetBytes (password);
  173. mp.Encrypt (buffer);
  174. }
  175. }
  176. }
  177. #endif