1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-31 18:27:49 +01:00

Merge pull request #767 from themikecom/master

Add unit test coverage for EncryptedStringAttribute
This commit is contained in:
Chad Scharf 2020-06-05 15:08:42 -04:00 committed by GitHub
commit 1ee2c813d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,43 @@
using Bit.Core.Utilities;
using Xunit;
namespace Bit.Core.Test.Utilities
{
public class EncryptedStringAttributeTests
{
[Theory]
[InlineData(null)]
[InlineData("aXY=|Y3Q=")] // Valid AesCbc256_B64
[InlineData("aXY=|Y3Q=|cnNhQ3Q=")] // Valid AesCbc128_HmacSha256_B64
[InlineData("Rsa2048_OaepSha256_B64.cnNhQ3Q=")]
public void IsValid_ReturnsTrue_WhenValid(string input)
{
var sut = new EncryptedStringAttribute();
var actual = sut.IsValid(input);
Assert.True(actual);
}
[Theory]
[InlineData("")]
[InlineData(".")]
[InlineData("|")]
[InlineData("!|!")] // Invalid base 64
[InlineData("Rsa2048_OaepSha1_HmacSha256_B64.1")] // Invalid length
[InlineData("Rsa2048_OaepSha1_HmacSha256_B64.|")] // Empty iv & ct
[InlineData("AesCbc128_HmacSha256_B64.1")] // Invalid length
[InlineData("AesCbc128_HmacSha256_B64.aXY=|Y3Q=|")] // Empty mac
[InlineData("Rsa2048_OaepSha1_HmacSha256_B64.aXY=|Y3Q=|")] // Empty mac
[InlineData("Rsa2048_OaepSha256_B64.1|2")] // Invalid length
[InlineData("Rsa2048_OaepSha1_HmacSha256_B64.aXY=|")] // Empty mac
public void IsValid_ReturnsFalse_WhenInvalid(string input)
{
var sut = new EncryptedStringAttribute();
var actual = sut.IsValid(input);
Assert.False(actual);
}
}
}