FormsAuthenticationTest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // FormsAuthenticationTest.cs - NUnit Test Cases for FormsAuthentication
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. using System;
  10. using System.Security.Cryptography;
  11. using System.Text;
  12. using System.Web.Security;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Web.Security {
  15. [TestFixture]
  16. public class FormsAuthenticationTest {
  17. [Test]
  18. [ExpectedException (typeof (ArgumentNullException))]
  19. public void HashPasswordForStoringInConfigFile_NullPassword ()
  20. {
  21. FormsAuthentication.HashPasswordForStoringInConfigFile (null, "MD5");
  22. }
  23. [Test]
  24. [ExpectedException (typeof (ArgumentNullException))]
  25. public void HashPasswordForStoringInConfigFile_NullPasswordFormat ()
  26. {
  27. FormsAuthentication.HashPasswordForStoringInConfigFile ("Mono", null);
  28. }
  29. [Test]
  30. public void HashPasswordForStoringInConfigFile_MD5 ()
  31. {
  32. // § (C2-A7)
  33. string s = Encoding.UTF8.GetString (new byte [2] { 0xC2, 0xA7 });
  34. Assert.AreEqual ("BD9A4C255DEEC8944D99E01A64C1E322", FormsAuthentication.HashPasswordForStoringInConfigFile (s, "MD5"));
  35. // ä (C3-A4)
  36. s = Encoding.UTF8.GetString (new byte [2] { 0xC3, 0xA4 });
  37. Assert.AreEqual ("8419B71C87A225A2C70B50486FBEE545", FormsAuthentication.HashPasswordForStoringInConfigFile (s, "MD5"));
  38. }
  39. [Test]
  40. public void HashPasswordForStoringInConfigFile_SHA1 ()
  41. {
  42. // § (C2-A7)
  43. string s = Encoding.UTF8.GetString (new byte [2] { 0xC2, 0xA7 });
  44. Assert.AreEqual ("EB2CB244889599F736B6CDD633C5E324F521D1BB", FormsAuthentication.HashPasswordForStoringInConfigFile (s, "SHA1"));
  45. // ä (C3-A4)
  46. s = Encoding.UTF8.GetString (new byte [2] { 0xC3, 0xA4 });
  47. Assert.AreEqual ("961FA22F61A56E19F3F5F8867901AC8CF5E6D11F", FormsAuthentication.HashPasswordForStoringInConfigFile (s, "SHA1"));
  48. }
  49. [Test]
  50. [ExpectedException (typeof (ArgumentException))]
  51. public void HashPasswordForStoringInConfigFile_SHA256 ()
  52. {
  53. FormsAuthentication.HashPasswordForStoringInConfigFile ("mono", "SHA256");
  54. }
  55. }
  56. }