2020-06-04 22:22:34 +02:00
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2022-08-29 20:53:16 +02:00
|
|
|
|
namespace Bit.Core.Test.Utilities;
|
|
|
|
|
|
|
|
|
|
public class EncryptedStringAttributeTests
|
2020-06-04 22:22:34 +02:00
|
|
|
|
{
|
2022-08-29 20:53:16 +02:00
|
|
|
|
[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)
|
2020-06-04 22:22:34 +02:00
|
|
|
|
{
|
2022-08-29 20:53:16 +02:00
|
|
|
|
var sut = new EncryptedStringAttribute();
|
2020-06-04 22:22:34 +02:00
|
|
|
|
|
2022-08-29 20:53:16 +02:00
|
|
|
|
var actual = sut.IsValid(input);
|
2021-12-16 15:35:09 +01:00
|
|
|
|
|
2022-08-29 20:53:16 +02:00
|
|
|
|
Assert.True(actual);
|
|
|
|
|
}
|
2021-12-16 15:35:09 +01:00
|
|
|
|
|
2022-08-29 20:53:16 +02:00
|
|
|
|
[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();
|
2020-06-04 22:22:34 +02:00
|
|
|
|
|
2022-08-29 20:53:16 +02:00
|
|
|
|
var actual = sut.IsValid(input);
|
2021-12-16 15:35:09 +01:00
|
|
|
|
|
2022-08-29 20:53:16 +02:00
|
|
|
|
Assert.False(actual);
|
2020-06-04 22:22:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|