mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 08:32:50 -05:00
PM-3925 - Tech Debt - Add missed tests for SSO Email 2FA Tokenable (#3270)
* PM-3925 - (1) Slightly refactor SsoEmail2faSessionTokenable to provide public static GetTokenLifeTime() method for testing (2) Add missed tests to SsoEmail2faSessionTokenable * PM-3925 - Take into account PR feedback
This commit is contained in:
@ -6,11 +6,12 @@ namespace Bit.Core.Auth.Models.Business.Tokenables;
|
||||
|
||||
// This token just provides a verifiable authN mechanism for the API service
|
||||
// TwoFactorController.cs SendEmailLogin anonymous endpoint so it cannot be
|
||||
// used maliciously.
|
||||
// used maliciously.
|
||||
public class SsoEmail2faSessionTokenable : ExpiringTokenable
|
||||
{
|
||||
// Just over 2 min expiration (client expires session after 2 min)
|
||||
private static readonly TimeSpan _tokenLifetime = TimeSpan.FromMinutes(2.05);
|
||||
public static TimeSpan GetTokenLifetime() => TimeSpan.FromMinutes(2.05);
|
||||
|
||||
public const string ClearTextPrefix = "BwSsoEmail2FaSessionToken_";
|
||||
public const string DataProtectorPurpose = "SsoEmail2faSessionTokenDataProtector";
|
||||
|
||||
@ -24,7 +25,7 @@ public class SsoEmail2faSessionTokenable : ExpiringTokenable
|
||||
[JsonConstructor]
|
||||
public SsoEmail2faSessionTokenable()
|
||||
{
|
||||
ExpirationDate = DateTime.UtcNow.Add(_tokenLifetime);
|
||||
ExpirationDate = DateTime.UtcNow.Add(GetTokenLifetime());
|
||||
}
|
||||
|
||||
public SsoEmail2faSessionTokenable(User user) : this()
|
||||
@ -44,7 +45,7 @@ public class SsoEmail2faSessionTokenable : ExpiringTokenable
|
||||
Email.Equals(user.Email, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
// Validates deserialized
|
||||
// Validates deserialized
|
||||
protected override bool TokenIsValid() =>
|
||||
Identifier == TokenIdentifier && Id != default && !string.IsNullOrWhiteSpace(Email);
|
||||
}
|
||||
|
Reference in New Issue
Block a user