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

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