Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@ -25,6 +25,9 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Security.Cryptography;
#if NET_4_0
using System;
using System.Text;
@ -166,6 +169,39 @@ namespace MonoTests.System.Web.Security
// Success
}
}
#if NET_4_5
[Test]
public void Protect ()
{
AssertExtensions.Throws<ArgumentNullException> (() =>
MachineKey.Protect (null, null),
"MachineKey.Protect not throwing an ArgumentNullException");
AssertExtensions.Throws<ArgumentNullException> (() =>
MachineKey.Protect (null, new [] { "test" }),
"MachineKey.Protect not throwing an ArgumentNullException");
var testString = "asfgasd43tqrt4";
var validUsages = new [] { "usage1", "usage2" };
var oneUsage = new [] { "usage1" };
var invalidUsages = new [] { "usage1", "invalidUsage" };
var plainBytes = Encoding.ASCII.GetBytes (testString);
var encryptedBytes = MachineKey.Protect (plainBytes, validUsages);
var validDecryptedBytes = MachineKey.Unprotect (encryptedBytes, validUsages);
Assert.AreEqual (plainBytes, validDecryptedBytes, "Decryption didn't work");
AssertExtensions.Throws<CryptographicException> (() =>
MachineKey.Unprotect (encryptedBytes, invalidUsages),
"Purposes not encrypting properly");
AssertExtensions.Throws<CryptographicException> (() =>
MachineKey.Unprotect (encryptedBytes, oneUsage),
"Single purpose working when multiple supplied");
}
#endif
}
}
#endif
#endif