1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-06 18:42:49 -05:00

[PM-1635] Invalid license error is inaccurate (#4631)

* Resolve the unclear error messages

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Refactor to return the errormessage from userLicense

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Resolve the pr comments

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* resolve the error returned message

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Add period at the end of error messages

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

---------

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
This commit is contained in:
cyprain-okeke
2024-08-26 14:12:58 +01:00
committed by GitHub
parent a5363c1513
commit e2ec1c4950
3 changed files with 66 additions and 31 deletions

View File

@ -113,21 +113,43 @@ public class UserLicense : ILicense
}
}
public bool CanUse(User user)
public bool CanUse(User user, out string exception)
{
if (Issued > DateTime.UtcNow || Expires < DateTime.UtcNow)
var errorMessages = new StringBuilder();
if (Issued > DateTime.UtcNow)
{
return false;
errorMessages.AppendLine("The license hasn't been issued yet.");
}
if (Version == 1)
if (Expires < DateTime.UtcNow)
{
return user.EmailVerified && user.Email.Equals(Email, StringComparison.InvariantCultureIgnoreCase);
errorMessages.AppendLine("The license has expired.");
}
else
if (Version != 1)
{
throw new NotSupportedException($"Version {Version} is not supported.");
}
if (!user.EmailVerified)
{
errorMessages.AppendLine("The user's email is not verified.");
}
if (!user.Email.Equals(Email, StringComparison.InvariantCultureIgnoreCase))
{
errorMessages.AppendLine("The user's email does not match the license email.");
}
if (errorMessages.Length > 0)
{
exception = $"Invalid license. {errorMessages.ToString().TrimEnd()}";
return false;
}
exception = "";
return true;
}
public bool VerifyData(User user)
@ -144,10 +166,8 @@ public class UserLicense : ILicense
user.Premium == Premium &&
user.Email.Equals(Email, StringComparison.InvariantCultureIgnoreCase);
}
else
{
throw new NotSupportedException($"Version {Version} is not supported.");
}
throw new NotSupportedException($"Version {Version} is not supported.");
}
public bool VerifySignature(X509Certificate2 certificate)