mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
[PM-5938] Prevent permanent vault coruption on key-rotation with desycned vault (#4098)
* Add check to verify the vault state for rotation is not obviously desynced (empty) * Add unit test for key rotation guardrail * Move de-synced vault detection to validators * Add tests
This commit is contained in:
@ -140,4 +140,25 @@ public class OrganizationUserRotationValidatorTests
|
||||
await Assert.ThrowsAsync<BadRequestException>(async () =>
|
||||
await sutProvider.Sut.ValidateAsync(user, resetPasswordKeys));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task ValidateAsync_NoOrganizationsInRequestButInDatabase_Throws(
|
||||
SutProvider<OrganizationUserRotationValidator> sutProvider, User user,
|
||||
IEnumerable<ResetPasswordWithOrgIdRequestModel> resetPasswordKeys)
|
||||
{
|
||||
var existingUserResetPassword = resetPasswordKeys
|
||||
.Select(a =>
|
||||
new OrganizationUser
|
||||
{
|
||||
Id = new Guid(),
|
||||
ResetPasswordKey = a.ResetPasswordKey,
|
||||
OrganizationId = a.OrganizationId
|
||||
}).ToList();
|
||||
sutProvider.GetDependency<IOrganizationUserRepository>().GetManyByUserAsync(user.Id)
|
||||
.Returns(existingUserResetPassword);
|
||||
|
||||
await Assert.ThrowsAsync<BadRequestException>(async () =>
|
||||
await sutProvider.Sut.ValidateAsync(user, Enumerable.Empty<ResetPasswordWithOrgIdRequestModel>()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user