mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 08:32:50 -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:
@ -42,4 +42,16 @@ public class CipherRotationValidatorTests
|
||||
|
||||
Assert.DoesNotContain(result, c => c.Id == ciphers.First().Id);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task ValidateAsync_SentCiphersAreEmptyButDatabaseCiphersAreNot_Throws(
|
||||
SutProvider<CipherRotationValidator> sutProvider, User user, IEnumerable<CipherWithIdRequestModel> ciphers)
|
||||
{
|
||||
var userCiphers = ciphers.Select(c => new CipherDetails { Id = c.Id.GetValueOrDefault(), Type = c.Type })
|
||||
.ToList();
|
||||
sutProvider.GetDependency<ICipherRepository>().GetManyByUserIdAsync(user.Id, Arg.Any<bool>())
|
||||
.Returns(userCiphers);
|
||||
|
||||
await Assert.ThrowsAsync<BadRequestException>(async () => await sutProvider.Sut.ValidateAsync(user, Enumerable.Empty<CipherWithIdRequestModel>()));
|
||||
}
|
||||
}
|
||||
|
@ -39,4 +39,14 @@ public class FolderRotationValidatorTests
|
||||
|
||||
Assert.DoesNotContain(result, c => c.Id == folders.First().Id);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task ValidateAsync_SentFoldersAreEmptyButDatabaseFoldersAreNot_Throws(
|
||||
SutProvider<FolderRotationValidator> sutProvider, User user, IEnumerable<FolderWithIdRequestModel> folders)
|
||||
{
|
||||
var userFolders = folders.Select(f => f.ToFolder(new Folder())).ToList();
|
||||
sutProvider.GetDependency<IFolderRepository>().GetManyByUserIdAsync(user.Id).Returns(userFolders);
|
||||
|
||||
await Assert.ThrowsAsync<BadRequestException>(async () => await sutProvider.Sut.ValidateAsync(user, Enumerable.Empty<FolderWithIdRequestModel>()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user