From 1d4ef9474f56c7b4e2cf894856924cb57c99cf68 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Wed, 12 Oct 2016 09:33:18 -0600 Subject: [PATCH] Added tests of all BlockCipherEngine and BlockCipherMode combinations to ensure encryption/decryption is working. --- .../Security/AeadCryptographyProviderTests.cs | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/mRemoteNGTests/Security/AeadCryptographyProviderTests.cs b/mRemoteNGTests/Security/AeadCryptographyProviderTests.cs index c1b1f2975..8d3511626 100644 --- a/mRemoteNGTests/Security/AeadCryptographyProviderTests.cs +++ b/mRemoteNGTests/Security/AeadCryptographyProviderTests.cs @@ -1,4 +1,6 @@ -using System.Security; +using System; +using System.Collections; +using System.Security; using mRemoteNG.Security; using mRemoteNG.Security.SymmetricEncryption; using NUnit.Framework; @@ -39,11 +41,12 @@ namespace mRemoteNGTests.Security Assert.That(cipherText.IsBase64String, Is.True); } - [Test] - public void DecryptedTextIsEqualToOriginalPlainText() + [TestCaseSource(nameof(GetAllBlockCipherEngineAndModeCombinations))] + public void DecryptedTextIsEqualToOriginalPlainText(BlockCipherEngines engine, BlockCipherModes mode) { - var cipherText = _cryptographyProvider.Encrypt(_plainText, _encryptionKey); - var decryptedCipherText = _cryptographyProvider.Decrypt(cipherText, _encryptionKey); + var cryptoProvider = new CryptographyProviderFactory().CreateAeadCryptographyProvider(engine, mode); + var cipherText = cryptoProvider.Encrypt(_plainText, _encryptionKey); + var decryptedCipherText = cryptoProvider.Decrypt(cipherText, _encryptionKey); Assert.That(decryptedCipherText, Is.EqualTo(_plainText)); } @@ -54,5 +57,20 @@ namespace mRemoteNGTests.Security var cipherText2 = _cryptographyProvider.Encrypt(_plainText, _encryptionKey); Assert.That(cipherText1, Is.Not.EqualTo(cipherText2)); } + + private static IEnumerable GetAllBlockCipherEngineAndModeCombinations() + { + var combinationList = new ArrayList(); + var engineChoices = Enum.GetValues(typeof(BlockCipherEngines)); + var modeChoices = Enum.GetValues(typeof(BlockCipherModes)); + foreach (var engine in engineChoices) + { + foreach (var mode in modeChoices) + { + combinationList.Add(new[] { engine, mode }); + } + } + return combinationList; + } } } \ No newline at end of file