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

test(auth-validator): [PM-22975] Client Version Validator - WIP changes.

This commit is contained in:
Patrick Pimentel
2025-12-02 13:46:23 -05:00
parent 8f89694f07
commit 8b8694e589
13 changed files with 65 additions and 35 deletions

View File

@@ -2,5 +2,5 @@
public static class Constants
{
public static readonly Version MinimumClientVersion = new Version("2025.11.0");
public static readonly Version MinimumClientVersionForV2Encryption = new Version("2025.11.0");
}

View File

@@ -15,7 +15,7 @@ public class GetMinimumClientVersionForUserQuery(IIsV2EncryptionUserQuery isV2En
if (await isV2EncryptionUserQuery.Run(user))
{
return Constants.MinimumClientVersion;
return Constants.MinimumClientVersionForV2Encryption;
}
return null;

View File

@@ -260,6 +260,4 @@ public class RotateUserAccountKeysCommand : IRotateUserAccountKeysCommand
throw new InvalidOperationException("No signed security state provider for V2 user");
}
}
// Parsing moved to Bit.Core.KeyManagement.Utilities.EncryptionParsing
}

View File

@@ -16,7 +16,7 @@ public class ClientVersionValidator(
IGetMinimumClientVersionForUserQuery getMinimumClientVersionForUserQuery)
: IClientVersionValidator
{
private static readonly string UpgradeMessage = "Please update your app to continue using Bitwarden";
private const string _upgradeMessage = "Please update your app to continue using Bitwarden";
public async Task<bool> ValidateAsync(User? user, CustomValidatorRequestContext requestContext)
{
@@ -25,10 +25,10 @@ public class ClientVersionValidator(
return true;
}
var clientVersion = currentContext.ClientVersion;
var minVersion = await getMinimumClientVersionForUserQuery.Run(user);
Version clientVersion = currentContext.ClientVersion;
Version? minVersion = await getMinimumClientVersionForUserQuery.Run(user);
// Fail-open if headers are missing or no restriction
// Allow through if headers are missing.
if (minVersion == null)
{
return true;
@@ -39,12 +39,12 @@ public class ClientVersionValidator(
requestContext.ValidationErrorResult = new ValidationResult
{
Error = "invalid_client_version",
ErrorDescription = UpgradeMessage,
ErrorDescription = _upgradeMessage,
IsError = true
};
requestContext.CustomResponse = new Dictionary<string, object>
{
{ "ErrorModel", new ErrorResponseModel(UpgradeMessage) }
{ "ErrorModel", new ErrorResponseModel(_upgradeMessage) }
};
return false;
}