You've already forked linux-packaging-mono
Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user