1
0
mirror of https://github.com/bitwarden/server synced 2026-01-02 08:33:48 +00:00

fix(auth-validator): [PM-22975] Client Version Validator - Made enough changes so that it's ready for review by KM

This commit is contained in:
Patrick Pimentel
2025-12-02 14:22:17 -05:00
parent 8b8694e589
commit ed89cf8161
7 changed files with 40 additions and 47 deletions

View File

@@ -12,10 +12,10 @@ namespace Bit.Core.Test.KeyManagement.Queries;
public class IsV2EncryptionUserQueryTests
{
private class FakeSigRepo : IUserSignatureKeyPairRepository
private class FakeUserSignatureKeyPairRepository : IUserSignatureKeyPairRepository
{
private readonly bool _hasKeys;
public FakeSigRepo(bool hasKeys) { _hasKeys = hasKeys; }
public FakeUserSignatureKeyPairRepository(bool hasKeys) { _hasKeys = hasKeys; }
public Task<SignatureKeyPairData?> GetByUserIdAsync(Guid userId)
=> Task.FromResult(_hasKeys ? new SignatureKeyPairData(SignatureAlgorithm.Ed25519, TestEncryptionConstants.V2WrappedSigningKey, TestEncryptionConstants.V2VerifyingKey) : null);
@@ -35,7 +35,7 @@ public class IsV2EncryptionUserQueryTests
public async Task Run_ReturnsTrue_ForV2State()
{
var user = new User { Id = Guid.NewGuid(), PrivateKey = TestEncryptionConstants.V2PrivateKey };
var sut = new IsV2EncryptionUserQuery(new FakeSigRepo(true));
var sut = new IsV2EncryptionUserQuery(new FakeUserSignatureKeyPairRepository(true));
var result = await sut.Run(user);
@@ -46,7 +46,7 @@ public class IsV2EncryptionUserQueryTests
public async Task Run_ReturnsFalse_ForV1State()
{
var user = new User { Id = Guid.NewGuid(), PrivateKey = TestEncryptionConstants.V1EncryptedBase64 };
var sut = new IsV2EncryptionUserQuery(new FakeSigRepo(false));
var sut = new IsV2EncryptionUserQuery(new FakeUserSignatureKeyPairRepository(false));
var result = await sut.Run(user);
@@ -57,7 +57,7 @@ public class IsV2EncryptionUserQueryTests
public async Task Run_ThrowsForInvalidMixedState()
{
var user = new User { Id = Guid.NewGuid(), PrivateKey = TestEncryptionConstants.V2PrivateKey };
var sut = new IsV2EncryptionUserQuery(new FakeSigRepo(false));
var sut = new IsV2EncryptionUserQuery(new FakeUserSignatureKeyPairRepository(false));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await sut.Run(user));
}