mirror of
https://github.com/bitwarden/server
synced 2025-12-16 00:03:54 +00:00
* Added MasterPasswordUnlock to UserDecryptionOptions as part of identity response * Implement support for authentication data and unlock data in kdf change * Extract to kdf command and add tests * Fix namespace * Delete empty file * Fix build * Clean up tests * Fix tests * Add comments * Cleanup * Cleanup * Cleanup * Clean-up and fix build * Address feedback; force new parameters on KDF change request * Clean-up and add tests * Re-add logger * Update logger to interface * Clean up, remove Kdf Request Model * Remove kdf request model tests * Fix types in test * Address feedback to rename request model and re-add tests * Fix namespace * Move comments * Rename InnerKdfRequestModel to KdfRequestModel --------- Co-authored-by: Maciej Zieniuk <mzieniuk@bitwarden.com>
69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
#nullable enable
|
|
using System.ComponentModel.DataAnnotations;
|
|
using Bit.Api.Auth.Models.Request.Accounts;
|
|
using Bit.Core.Enums;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.KeyManagement.Models.Request;
|
|
|
|
public class MasterPasswordUnlockDataModelTests
|
|
{
|
|
|
|
readonly string _mockEncryptedString = "2.3Uk+WNBIoU5xzmVFNcoWzz==|1MsPIYuRfdOHfu/0uY6H2Q==|/98sp4wb6pHP1VTZ9JcNCYgQjEUMFPlqJgCwRk1YXKg=";
|
|
|
|
[Theory]
|
|
[InlineData(KdfType.PBKDF2_SHA256, 5000, null, null)]
|
|
[InlineData(KdfType.PBKDF2_SHA256, 100000, null, null)]
|
|
[InlineData(KdfType.PBKDF2_SHA256, 600000, null, null)]
|
|
[InlineData(KdfType.Argon2id, 3, 64, 4)]
|
|
public void Validate_Success(KdfType kdfType, int kdfIterations, int? kdfMemory, int? kdfParallelism)
|
|
{
|
|
var model = new MasterPasswordUnlockAndAuthenticationDataModel
|
|
{
|
|
KdfType = kdfType,
|
|
KdfIterations = kdfIterations,
|
|
KdfMemory = kdfMemory,
|
|
KdfParallelism = kdfParallelism,
|
|
Email = "example@example.com",
|
|
MasterKeyAuthenticationHash = "hash",
|
|
MasterKeyEncryptedUserKey = _mockEncryptedString,
|
|
MasterPasswordHint = "hint"
|
|
};
|
|
var result = Validate(model);
|
|
Assert.Empty(result);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(KdfType.Argon2id, 1, null, 1)]
|
|
[InlineData(KdfType.Argon2id, 1, 64, null)]
|
|
[InlineData(KdfType.PBKDF2_SHA256, 5000, 0, null)]
|
|
[InlineData(KdfType.PBKDF2_SHA256, 5000, null, 0)]
|
|
[InlineData(KdfType.PBKDF2_SHA256, 5000, 0, 0)]
|
|
[InlineData((KdfType)2, 100000, null, null)]
|
|
[InlineData((KdfType)2, 2, 64, 4)]
|
|
public void Validate_Failure(KdfType kdfType, int kdfIterations, int? kdfMemory, int? kdfParallelism)
|
|
{
|
|
var model = new MasterPasswordUnlockAndAuthenticationDataModel
|
|
{
|
|
KdfType = kdfType,
|
|
KdfIterations = kdfIterations,
|
|
KdfMemory = kdfMemory,
|
|
KdfParallelism = kdfParallelism,
|
|
Email = "example@example.com",
|
|
MasterKeyAuthenticationHash = "hash",
|
|
MasterKeyEncryptedUserKey = _mockEncryptedString,
|
|
MasterPasswordHint = "hint"
|
|
};
|
|
var result = Validate(model);
|
|
Assert.Single(result);
|
|
Assert.NotNull(result.First().ErrorMessage);
|
|
}
|
|
|
|
private static List<ValidationResult> Validate(MasterPasswordUnlockAndAuthenticationDataModel model)
|
|
{
|
|
var results = new List<ValidationResult>();
|
|
Validator.TryValidateObject(model, new ValidationContext(model), results, true);
|
|
return results;
|
|
}
|
|
}
|