mirror of
https://github.com/bitwarden/server
synced 2026-01-09 03:53:42 +00:00
fix(auth-validator): [PM-22975] Client Version Validator - Added more tests and added comment.
This commit is contained in:
@@ -222,6 +222,11 @@ public class User : ITableObject<Guid>, IStorableSubscriber, IRevisable, ITwoFac
|
|||||||
return EncryptionParsing.GetEncryptionType(PrivateKey) == EncryptionType.XChaCha20Poly1305_B64;
|
return EncryptionParsing.GetEncryptionType(PrivateKey) == EncryptionType.XChaCha20Poly1305_B64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This technically is correct but all versions after 1 are considered v2 encryption. Leaving for now with
|
||||||
|
/// KM's blessing that when a new version comes along they will handle migration.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
private bool IsSecurityVersionTwo()
|
private bool IsSecurityVersionTwo()
|
||||||
{
|
{
|
||||||
return SecurityVersion == 2;
|
return SecurityVersion == 2;
|
||||||
|
|||||||
@@ -26,6 +26,43 @@ public class GetMinimumClientVersionForUserQueryTests
|
|||||||
var version = await sut.Run(new User
|
var version = await sut.Run(new User
|
||||||
{
|
{
|
||||||
SecurityVersion = 1,
|
SecurityVersion = 1,
|
||||||
|
PrivateKey = TestEncryptionConstants.V1EncryptedBase64,
|
||||||
|
});
|
||||||
|
Assert.Null(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Run_ReturnsNull_ForSecurityVersion1ButPrivateKeyV2User()
|
||||||
|
{
|
||||||
|
var sut = new GetMinimumClientVersionForUserQuery();
|
||||||
|
var version = await sut.Run(new User
|
||||||
|
{
|
||||||
|
SecurityVersion = 1,
|
||||||
|
PrivateKey = TestEncryptionConstants.V2PrivateKey,
|
||||||
|
});
|
||||||
|
Assert.Null(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Run_ReturnsNull_ForPrivateKeyV1ButSecurityVersion2User()
|
||||||
|
{
|
||||||
|
var sut = new GetMinimumClientVersionForUserQuery();
|
||||||
|
var version = await sut.Run(new User
|
||||||
|
{
|
||||||
|
SecurityVersion = 2,
|
||||||
|
PrivateKey = TestEncryptionConstants.V1EncryptedBase64,
|
||||||
|
});
|
||||||
|
Assert.Null(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Run_ReturnsNull_ForV1UserWithNull()
|
||||||
|
{
|
||||||
|
var sut = new GetMinimumClientVersionForUserQuery();
|
||||||
|
var version = await sut.Run(new User
|
||||||
|
{
|
||||||
|
SecurityVersion = null,
|
||||||
PrivateKey = TestEncryptionConstants.V2PrivateKey,
|
PrivateKey = TestEncryptionConstants.V2PrivateKey,
|
||||||
});
|
});
|
||||||
Assert.Null(version);
|
Assert.Null(version);
|
||||||
|
|||||||
Reference in New Issue
Block a user