EncryptedBlockStore crashed when a modified block was removed. Fixed crash and added test case.

This commit is contained in:
Sebastian Messmer 2015-09-29 18:51:59 +02:00
parent d916408a01
commit 52bb855627
2 changed files with 11 additions and 1 deletions

View File

@ -151,6 +151,7 @@ void EncryptedBlock<Cipher>::_encryptToBaseBlock() {
template<class Cipher> template<class Cipher>
cpputils::unique_ref<Block> EncryptedBlock<Cipher>::releaseBlock() { cpputils::unique_ref<Block> EncryptedBlock<Cipher>::releaseBlock() {
_encryptToBaseBlock();
return std::move(_baseBlock); return std::move(_baseBlock);
} }

View File

@ -100,6 +100,14 @@ TYPED_TEST_P(BlockStoreTest, NumBlocksIsCorrectAfterRemovingABlock) {
EXPECT_EQ(1, blockStore->numBlocks()); EXPECT_EQ(1, blockStore->numBlocks());
} }
TYPED_TEST_P(BlockStoreTest, CanRemoveModifiedBlock) {
auto blockStore = this->fixture.createBlockStore();
auto block = blockStore->create(cpputils::Data(5));
block->write("data", 0, 4);
blockStore->remove(std::move(block));
EXPECT_EQ(0, blockStore->numBlocks());
}
#include "BlockStoreTest_Size.h" #include "BlockStoreTest_Size.h"
#include "BlockStoreTest_Data.h" #include "BlockStoreTest_Data.h"
@ -129,7 +137,8 @@ REGISTER_TYPED_TEST_CASE_P(BlockStoreTest,
NumBlocksIsCorrectAfterRemovingABlock, NumBlocksIsCorrectAfterRemovingABlock,
WriteAndReadImmediately, WriteAndReadImmediately,
WriteAndReadAfterLoading, WriteAndReadAfterLoading,
OverwriteAndRead OverwriteAndRead,
CanRemoveModifiedBlock
); );