Fixed EncryptWithMachineKey to handle values longer than FormsAuthentication.Encrypt max length limit

http://issues.umbraco.org/issue/U4-1455
This commit is contained in:
pcw@pcw-PC.shout.local
2013-01-15 20:09:29 +00:00
parent dec5e8ad6c
commit f4f91fba78

View File

@@ -4,6 +4,7 @@ using System.Security;
using System.Text;
using NUnit.Framework;
using Umbraco.Core;
using System.Security.Cryptography;
namespace Umbraco.Tests
{
@@ -11,7 +12,10 @@ namespace Umbraco.Tests
public class StringExtensionsTests
{
[TestCase("This is a string to encrypt")]
[TestCase("This is a string to encrypt")]
[TestCase("This is a string to encrypt\nThis is a second line")]
[TestCase(" White space is preserved ")]
[TestCase("\nWhite space is preserved\n")]
public void Encrypt_And_Decrypt(string input)
{
var encrypted = input.EncryptWithMachineKey();
@@ -20,6 +24,25 @@ namespace Umbraco.Tests
Assert.AreEqual(input, decrypted);
}
[Test()]
public void Encrypt_And_Decrypt_Long_Value()
{
// Generate a really long string
char[] chars = { 'a', 'b', 'c', '1', '2', '3', '\n' };
string valueToTest = string.Empty;
// Create a string 7035 chars long
for (int i = 0; i < 1005; i++)
for (int j = 0; j < chars.Length; j++)
valueToTest += chars[j].ToString();
var encrypted = valueToTest.ToString().EncryptWithMachineKey();
var decrypted = encrypted.DecryptWithMachineKey();
Assert.AreNotEqual(valueToTest, encrypted);
Assert.AreEqual(valueToTest, decrypted);
}
[TestCase("Hello this is my string", " string", "Hello this is my")]
[TestCase("Hello this is my string strung", " string", "Hello this is my string strung")]
[TestCase("Hello this is my string string", " string", "Hello this is my")]