Commit c74aa170 authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

[sync] Fix ModelTypeWorker not overwriting undecryptable updates with...

... decryptable ones.

Before this CL, if the sync server sent an update for "ServerId"
encrypted with an unknown key, then sent an update for the same id
encrypted with a known key, the data type would remain blocked.

The CL fixes this by removing any entry in entries_pending_decryption_
with the same id as an incoming successfully decrypted update.

Fixed: 1148359
Change-Id: I56ef2d8c73686ff9375cfd1ff7d48da1a5fe53c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2535230Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Victor Vianna <victorvianna@google.com>
Cr-Commit-Position: refs/heads/master@{#826991}
parent d7ba8589
...@@ -195,6 +195,8 @@ SyncerError ModelTypeWorker::ProcessGetUpdatesResponse( ...@@ -195,6 +195,8 @@ SyncerError ModelTypeWorker::ProcessGetUpdatesResponse(
*update_entity, &response_data)) { *update_entity, &response_data)) {
case SUCCESS: case SUCCESS:
pending_updates_.push_back(std::move(response_data)); pending_updates_.push_back(std::move(response_data));
// Override any previously undecryptable update for the same id.
entries_pending_decryption_.erase(update_entity->id_string());
break; break;
case DECRYPTION_PENDING: case DECRYPTION_PENDING:
// Cannot decrypt now, copy the sync entity for later decryption. // Cannot decrypt now, copy the sync entity for later decryption.
......
...@@ -1265,6 +1265,26 @@ TEST_F(ModelTypeWorkerTest, ReceiveUndecryptableEntries) { ...@@ -1265,6 +1265,26 @@ TEST_F(ModelTypeWorkerTest, ReceiveUndecryptableEntries) {
EXPECT_EQ(GetLocalCryptographerKeyName(), update.encryption_key_name); EXPECT_EQ(GetLocalCryptographerKeyName(), update.encryption_key_name);
} }
TEST_F(ModelTypeWorkerTest, OverwriteUndecryptableUpdateWithDecryptableOne) {
NormalInitialize();
// The cryptographer can decrypt data encrypted with key 1.
AddPendingKey();
DecryptPendingKey();
// The worker receives an update encrypted with an unknown key 2.
SetUpdateEncryptionFilter(2);
TriggerUpdateFromServer(10, kTag1, kValue1);
// The data can't be decrypted yet.
ASSERT_FALSE(processor()->HasUpdateResponse(kHash1));
// The server sends an update for the same server id now encrypted with key 1.
SetUpdateEncryptionFilter(1);
TriggerUpdateFromServer(10, kTag1, kValue1);
// The previous undecryptable update should be overwritten, unblocking the
// worker.
EXPECT_TRUE(processor()->HasUpdateResponse(kHash1));
}
// Verify that corrupted encrypted updates don't cause crashes. // Verify that corrupted encrypted updates don't cause crashes.
TEST_F(ModelTypeWorkerTest, ReceiveCorruptEncryption) { TEST_F(ModelTypeWorkerTest, ReceiveCorruptEncryption) {
// Initialize the worker with basic encryption state. // Initialize the worker with basic encryption state.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment