mirror of
https://github.com/bitwarden/server
synced 2026-02-24 08:33:06 +00:00
feat(auth-validator): [Auth/PM-22975] Client Version Validator (#6588)
* feat(auth-validator): [PM-22975] Client Version Validator - Implementation. * test(auth-validator): [PM-22975] Client Version Validator - Added tests.
This commit is contained in:
committed by
GitHub
parent
b5554c6030
commit
3dbd17f61d
@@ -3,7 +3,6 @@ using System.Text;
|
||||
using AutoFixture;
|
||||
using AutoFixture.Kernel;
|
||||
using AutoFixture.Xunit2;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Test.Helpers.Factories;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using NSubstitute;
|
||||
@@ -36,11 +35,11 @@ public class GlobalSettingsBuilder : ISpecimenBuilder
|
||||
var dataProtector = Substitute.For<IDataProtector>();
|
||||
dataProtector.Unprotect(Arg.Any<byte[]>())
|
||||
.Returns(data =>
|
||||
Encoding.UTF8.GetBytes(Constants.DatabaseFieldProtectedPrefix +
|
||||
Encoding.UTF8.GetBytes(Core.Constants.DatabaseFieldProtectedPrefix +
|
||||
Encoding.UTF8.GetString((byte[])data[0])));
|
||||
|
||||
var dataProtectionProvider = Substitute.For<IDataProtectionProvider>();
|
||||
dataProtectionProvider.CreateProtector(Constants.DatabaseFieldProtectorPurpose)
|
||||
dataProtectionProvider.CreateProtector(Core.Constants.DatabaseFieldProtectorPurpose)
|
||||
.Returns(dataProtector);
|
||||
|
||||
return dataProtectionProvider;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.KeyManagement.Utilities;
|
||||
using Bit.Test.Common.Constants;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.KeyManagement.Utilities;
|
||||
|
||||
public class EncryptionParsingTests
|
||||
{
|
||||
[Fact]
|
||||
public void GetEncryptionType_WithNull_ThrowsArgumentNullException()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => EncryptionParsing.GetEncryptionType(null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("2")] // missing '.' separator
|
||||
[InlineData("abc.def")] // non-numeric prefix
|
||||
[InlineData("8.any")] // undefined enum value
|
||||
[InlineData("255.any")] // out of defined enum range
|
||||
public void GetEncryptionType_WithInvalidString_ThrowsArgumentException(string input)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => EncryptionParsing.GetEncryptionType(input));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TestEncryptionConstants.AES256_CBC_B64_Encstring, EncryptionType.AesCbc256_B64)]
|
||||
[InlineData(TestEncryptionConstants.AES256_CBC_HMAC_Encstring, EncryptionType.AesCbc256_HmacSha256_B64)]
|
||||
[InlineData(TestEncryptionConstants.RSA2048_OAEPSHA1_B64_Encstring, EncryptionType.Rsa2048_OaepSha1_B64)]
|
||||
[InlineData(TestEncryptionConstants.V2PrivateKey, EncryptionType.XChaCha20Poly1305_B64)]
|
||||
[InlineData(TestEncryptionConstants.V2WrappedSigningKey, EncryptionType.XChaCha20Poly1305_B64)]
|
||||
[InlineData(TestEncryptionConstants.AES256_CBC_HMAC_EmptySuffix, EncryptionType.AesCbc256_HmacSha256_B64)] // empty suffix still valid
|
||||
[InlineData(TestEncryptionConstants.XCHACHA20POLY1305_B64_Encstring, EncryptionType.XChaCha20Poly1305_B64)]
|
||||
public void GetEncryptionType_WithValidString_ReturnsExpected(string input, EncryptionType expected)
|
||||
{
|
||||
var result = EncryptionParsing.GetEncryptionType(input);
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user