1
0
mirror of https://github.com/bitwarden/server synced 2026-01-07 02:53:38 +00:00

fix(auth-validator): [PM-22975] Client Version Validator - misc changes, trying to get things to work

This commit is contained in:
Patrick Pimentel
2025-12-01 17:49:09 -05:00
parent 53e650976b
commit b3b1b9b91d
6 changed files with 119 additions and 24 deletions

View File

@@ -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;

View File

@@ -5,6 +5,7 @@ using Bit.Core.KeyManagement.Models.Data;
using Bit.Core.KeyManagement.Queries;
using Bit.Core.KeyManagement.Repositories;
using Bit.Core.KeyManagement.UserKey;
using Bit.Test.Common.Constants;
using Xunit;
namespace Bit.Core.Test.KeyManagement.Queries;
@@ -16,7 +17,7 @@ public class IsV2EncryptionUserQueryTests
private readonly bool _hasKeys;
public FakeSigRepo(bool hasKeys) { _hasKeys = hasKeys; }
public Task<SignatureKeyPairData?> GetByUserIdAsync(Guid userId)
=> Task.FromResult(_hasKeys ? new SignatureKeyPairData(SignatureAlgorithm.Ed25519, "7.cose_signing", "vk") : null);
=> Task.FromResult(_hasKeys ? new SignatureKeyPairData(SignatureAlgorithm.Ed25519, TestEncryptionConstants.V2WrappedSigningKey, TestEncryptionConstants.V2VerifyingKey) : null);
// Unused in tests
public Task<IEnumerable<UserSignatureKeyPair>> GetManyAsync(IEnumerable<Guid> ids) => throw new NotImplementedException();
@@ -33,7 +34,7 @@ public class IsV2EncryptionUserQueryTests
[Fact]
public async Task Run_ReturnsTrue_ForV2State()
{
var user = new User { Id = Guid.NewGuid(), PrivateKey = "7.cose" };
var user = new User { Id = Guid.NewGuid(), PrivateKey = TestEncryptionConstants.V2PrivateKey };
var sut = new IsV2EncryptionUserQuery(new FakeSigRepo(true));
var result = await sut.Run(user);
@@ -44,7 +45,7 @@ public class IsV2EncryptionUserQueryTests
[Fact]
public async Task Run_ReturnsFalse_ForV1State()
{
var user = new User { Id = Guid.NewGuid(), PrivateKey = "2.iv|ct|mac" };
var user = new User { Id = Guid.NewGuid(), PrivateKey = TestEncryptionConstants.V1EncryptedBase64 };
var sut = new IsV2EncryptionUserQuery(new FakeSigRepo(false));
var result = await sut.Run(user);
@@ -55,7 +56,7 @@ public class IsV2EncryptionUserQueryTests
[Fact]
public async Task Run_ThrowsForInvalidMixedState()
{
var user = new User { Id = Guid.NewGuid(), PrivateKey = "7.cose" };
var user = new User { Id = Guid.NewGuid(), PrivateKey = TestEncryptionConstants.V2PrivateKey };
var sut = new IsV2EncryptionUserQuery(new FakeSigRepo(false));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sut.Run(user));