diff --git a/vb-migration/Strata.Base.Internal.Tests/Security/SecurityUtilsTests.cs b/vb-migration/Strata.Base.Internal.Tests/Security/SecurityUtilsTests.cs index edaf1e7..64490ac 100644 --- a/vb-migration/Strata.Base.Internal.Tests/Security/SecurityUtilsTests.cs +++ b/vb-migration/Strata.Base.Internal.Tests/Security/SecurityUtilsTests.cs @@ -1,4 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Security.Cryptography; +using System; namespace Strata.Base.Internal.Tests.Security { @@ -9,50 +11,97 @@ namespace Strata.Base.Internal.Tests.Security public void EncryptValue_WithValidInput_EncryptsAndDecryptsCorrectly() { // Arrange - string originalValue = "Test sensitive data"; - string key = "MySecretKey123"; + string originalValue = "test value"; + string key = "testkey12345678"; // AES requires at least a 128-bit (16-byte) key // Act - string encrypted = SecurityUtils.EncryptValue(originalValue, key); - string decrypted = SecurityUtils.DecryptValue(encrypted, key); + string encryptedValue = SecurityUtils.EncryptValue(originalValue, key); + string decryptedValue = SecurityUtils.DecryptValue(encryptedValue, key); // Assert - Assert.AreNotEqual(originalValue, encrypted, "Encrypted value should be different from original"); - Assert.AreEqual(originalValue, decrypted, "Decrypted value should match original"); - } - - [TestMethod] - public void EncryptValue_WithEmptyString_HandlesCorrectly() - { - // Arrange - string originalValue = ""; - string key = "MySecretKey123"; - - // Act - string encrypted = SecurityUtils.EncryptValue(originalValue, key); - string decrypted = SecurityUtils.DecryptValue(encrypted, key); - - // Assert - Assert.AreNotEqual(originalValue, encrypted, "Encrypted value should be different from empty string"); - Assert.AreEqual(originalValue, decrypted, "Decrypted value should be empty string"); + Assert.AreEqual(originalValue, decryptedValue); } [TestMethod] public void DecryptValue_WithWrongKey_ThrowsException() { // Arrange - string originalValue = "Test sensitive data"; - string correctKey = "CorrectKey123"; - string wrongKey = "WrongKey123"; + string originalValue = "test value"; + string correctKey = "testkey12345678"; // AES requires at least a 128-bit (16-byte) key + string wrongKey = "wrongkey12345678"; // Act - string encrypted = SecurityUtils.EncryptValue(originalValue, correctKey); + string encryptedValue = SecurityUtils.EncryptValue(originalValue, correctKey); // Assert - Assert.ThrowsException( - () => SecurityUtils.DecryptValue(encrypted, wrongKey), - "Decryption with wrong key should throw CryptographicException" - ); + Assert.ThrowsException(() => SecurityUtils.DecryptValue(encryptedValue, wrongKey)); + } + + [TestMethod] + public void EncryptValue_WithEmptyString_ReturnsEmptyString() + { + // Arrange + string originalValue = ""; + string key = "testkey12345678"; + + // Act + string encryptedValue = SecurityUtils.EncryptValue(originalValue, key); + + // Assert + Assert.AreEqual("", encryptedValue); + } + + [TestMethod] + public void DecryptValue_WithEmptyString_ReturnsEmptyString() + { + // Arrange + string encryptedValue = ""; + string key = "testkey12345678"; + + // Act + string decryptedValue = SecurityUtils.DecryptValue(encryptedValue, key); + + // Assert + Assert.AreEqual("", decryptedValue); + } + + [TestMethod] + public void EncryptValue_WithNullString_ReturnsNull() + { + // Arrange + var originalValue = null as string; + string key = "testkey12345678"; + + // Act + string encryptedValue = SecurityUtils.EncryptValue(originalValue, key); + + // Assert + Assert.IsNull(encryptedValue); + } + + [TestMethod] + public void DecryptValue_WithNullString_ReturnsNull() + { + // Arrange + var encryptedValue = null as string; + string key = "testkey12345678"; + + // Act + string decryptedValue = SecurityUtils.DecryptValue(encryptedValue, key); + + // Assert + Assert.IsNull(decryptedValue); + } + + [TestMethod] + public void DecryptValue_WithInvalidBase64_ThrowsException() + { + // Arrange + string invalidBase64 = "Not a valid base64 string"; + string key = "testkey12345678"; + + // Assert + Assert.ThrowsException(() => SecurityUtils.DecryptValue(invalidBase64, key)); } } } diff --git a/vb-migration/Strata.Base.Internal.Tests/Strata.Base.Internal.Tests.csproj b/vb-migration/Strata.Base.Internal.Tests/Strata.Base.Internal.Tests.csproj index 6207637..7303785 100644 --- a/vb-migration/Strata.Base.Internal.Tests/Strata.Base.Internal.Tests.csproj +++ b/vb-migration/Strata.Base.Internal.Tests/Strata.Base.Internal.Tests.csproj @@ -14,7 +14,10 @@ - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/vb-migration/coverage.runsettings b/vb-migration/coverage.runsettings new file mode 100644 index 0000000..9e63cc7 --- /dev/null +++ b/vb-migration/coverage.runsettings @@ -0,0 +1,18 @@ + + + + + + + cobertura + [Strata.*]* + ExcludeFromCodeCoverageAttribute + false + true + false + true + + + + + \ No newline at end of file