From 44df65e67a175f999ff6f06682e790f784e8f690 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Fri, 15 Feb 2019 16:04:24 +0100 Subject: [PATCH] SEBWIN-296: Added missing unit tests for password encryption. --- .../Cryptography/PasswordEncryptionTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/SafeExamBrowser.Configuration.UnitTests/Cryptography/PasswordEncryptionTests.cs b/SafeExamBrowser.Configuration.UnitTests/Cryptography/PasswordEncryptionTests.cs index 5c402178..8594da09 100644 --- a/SafeExamBrowser.Configuration.UnitTests/Cryptography/PasswordEncryptionTests.cs +++ b/SafeExamBrowser.Configuration.UnitTests/Cryptography/PasswordEncryptionTests.cs @@ -49,5 +49,24 @@ namespace SafeExamBrowser.Configuration.UnitTests.Cryptography Assert.AreEqual(SaveStatus.Success, saveStatus); Assert.AreEqual(LoadStatus.Success, loadStatus); } + + [TestMethod] + public void MustRequestPasswordForDecryption() + { + var status = sut.Decrypt(new MemoryStream(), null, out _); + + Assert.AreEqual(LoadStatus.PasswordNeeded, status); + } + + [TestMethod] + public void MustRequestPasswordIfInvalid() + { + var password = "test1234"; + var saveStatus = sut.Encrypt(new MemoryStream(Encoding.UTF8.GetBytes("A super secret message!")), password, out var encrypted); + var loadStatus = sut.Decrypt(encrypted, "not the correct password", out _); + + Assert.AreEqual(SaveStatus.Success, saveStatus); + Assert.AreEqual(LoadStatus.PasswordNeeded, loadStatus); + } } }