Chromium Code Reviews| Index: sync/engine/syncer_unittest.cc |
| diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc |
| index 7372f68c1872c29d27e0ccfa820f90220d426cfe..027712aedde0d6e250e619fc93ec1280179aa4a4 100644 |
| --- a/sync/engine/syncer_unittest.cc |
| +++ b/sync/engine/syncer_unittest.cc |
| @@ -33,6 +33,7 @@ |
| #include "sync/engine/traffic_recorder.h" |
| #include "sync/internal_api/public/base/model_type.h" |
| #include "sync/internal_api/public/engine/model_safe_worker.h" |
| +#include "sync/internal_api/public/test/fake_sync_encryption_handler.h" |
| #include "sync/protocol/bookmark_specifics.pb.h" |
| #include "sync/protocol/nigori_specifics.pb.h" |
| #include "sync/protocol/preference_specifics.pb.h" |
| @@ -255,6 +256,8 @@ class SyncerTest : public testing::Test, |
| child_id_ = ids_.MakeServer("child id"); |
| directory()->set_store_birthday(mock_server_->store_birthday()); |
| mock_server_->SetKeystoreKey("encryption_key"); |
| + cryptographer(&trans)->SetSyncEncryptionHandlerDelegate( |
| + &fake_encryption_handler_); |
| } |
| virtual void TearDown() { |
| @@ -566,6 +569,8 @@ class SyncerTest : public testing::Test, |
| ModelTypeSet enabled_datatypes_; |
| TrafficRecorder traffic_recorder_; |
| + FakeSyncEncryptionHandler fake_encryption_handler_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(SyncerTest); |
| }; |
| @@ -723,12 +728,12 @@ TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { |
| sync_pb::EntitySpecifics specifics; |
| sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| - nigori->set_encrypt_bookmarks(true); |
| + fake_encryption_handler_.EnableEncryptEverything(); |
| // Set up with an old passphrase, but have pending keys |
| cryptographer(&wtrans)->AddKey(key_params); |
| cryptographer(&wtrans)->Encrypt(bookmark, |
| encrypted_bookmark.mutable_encrypted()); |
| - cryptographer(&wtrans)->Update(*nigori); |
| + cryptographer(&wtrans)->SetPendingKeys(nigori->encrypted()); |
| // In conflict but properly encrypted. |
| MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| @@ -836,9 +841,8 @@ TEST_F(SyncerTest, EncryptionAwareConflicts) { |
| sync_pb::EntitySpecifics specifics; |
| sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| - nigori->set_encrypt_bookmarks(true); |
| - nigori->set_encrypt_preferences(true); |
| - cryptographer(&wtrans)->Update(*nigori); |
| + fake_encryption_handler_.EnableEncryptEverything(); |
| + cryptographer(&wtrans)->SetPendingKeys(nigori->encrypted()); |
| EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); |
| } |
| @@ -978,89 +982,6 @@ TEST_F(SyncerTest, EncryptionAwareConflicts) { |
| #undef VERIFY_ENTRY |
| -// Receive an old nigori with old encryption keys and encrypted types. We should |
| -// not revert our default key or encrypted types. |
| -TEST_F(SyncerTest, ReceiveOldNigori) { |
|
Nicolas Zea
2012/08/10 02:58:06
this test moved to SyncEncryptionHandlerImplTest
|
| - KeyParams old_key = {"localhost", "dummy", "old"}; |
| - KeyParams current_key = {"localhost", "dummy", "cur"}; |
| - |
| - // Data for testing encryption/decryption. |
| - Cryptographer other_cryptographer(&encryptor_); |
| - other_cryptographer.AddKey(old_key); |
| - sync_pb::EntitySpecifics other_encrypted_specifics; |
| - other_encrypted_specifics.mutable_bookmark()->set_title("title"); |
| - other_cryptographer.Encrypt( |
| - other_encrypted_specifics, |
| - other_encrypted_specifics.mutable_encrypted()); |
| - sync_pb::EntitySpecifics our_encrypted_specifics; |
| - our_encrypted_specifics.mutable_bookmark()->set_title("title2"); |
| - ModelTypeSet encrypted_types = ModelTypeSet::All(); |
| - |
| - |
| - // Receive the initial nigori node. |
| - sync_pb::EntitySpecifics initial_nigori_specifics; |
| - initial_nigori_specifics.mutable_nigori(); |
| - mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); |
| - SyncShareNudge(); |
| - |
| - { |
| - // Set up the current nigori node (containing both keys and encrypt |
| - // everything). |
| - WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| - sync_pb::EntitySpecifics specifics; |
| - sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| - cryptographer(&wtrans)->AddKey(old_key); |
| - cryptographer(&wtrans)->AddKey(current_key); |
| - cryptographer(&wtrans)->Encrypt( |
| - our_encrypted_specifics, |
| - our_encrypted_specifics.mutable_encrypted()); |
| - cryptographer(&wtrans)->GetKeys( |
| - nigori->mutable_encrypted()); |
| - cryptographer(&wtrans)->set_encrypt_everything(); |
| - cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); |
| - MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| - ModelTypeToRootTag(NIGORI)); |
| - ASSERT_TRUE(nigori_entry.good()); |
| - nigori_entry.Put(SPECIFICS, specifics); |
| - nigori_entry.Put(IS_UNSYNCED, true); |
| - EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); |
| - EXPECT_TRUE(encrypted_types.Equals( |
| - cryptographer(&wtrans)->GetEncryptedTypes())); |
| - } |
| - |
| - SyncShareNudge(); // Commit it. |
| - |
| - // Now set up the old nigori node and add it as a server update. |
| - sync_pb::EntitySpecifics old_nigori_specifics; |
| - sync_pb::NigoriSpecifics *old_nigori = old_nigori_specifics.mutable_nigori(); |
| - other_cryptographer.GetKeys(old_nigori->mutable_encrypted()); |
| - other_cryptographer.UpdateNigoriFromEncryptedTypes(old_nigori); |
| - mock_server_->SetNigori(1, 30, 30, old_nigori_specifics); |
| - |
| - SyncShareNudge(); // Download the old nigori and apply it. |
| - |
| - { |
| - // Ensure everything is committed and stable now. The cryptographer |
| - // should be able to decrypt both sets of keys and still be encrypting with |
| - // the newest, and the encrypted types should be the most recent |
| - syncable::ReadTransaction trans(FROM_HERE, directory()); |
| - Entry nigori_entry(&trans, GET_BY_SERVER_TAG, |
| - ModelTypeToRootTag(NIGORI)); |
| - ASSERT_TRUE(nigori_entry.good()); |
| - EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| - EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| - const sync_pb::NigoriSpecifics& nigori = |
| - nigori_entry.Get(SPECIFICS).nigori(); |
| - EXPECT_TRUE(cryptographer(&trans)->CanDecryptUsingDefaultKey( |
| - our_encrypted_specifics.encrypted())); |
| - EXPECT_TRUE(cryptographer(&trans)->CanDecrypt( |
| - other_encrypted_specifics.encrypted())); |
| - EXPECT_TRUE(cryptographer(&trans)->CanDecrypt( |
| - nigori.encrypted())); |
| - EXPECT_TRUE(cryptographer(&trans)->encrypt_everything()); |
| - } |
| -} |
| - |
| // Resolve a confict between two nigori's with different encrypted types, |
| // and encryption keys (remote is explicit). Afterwards, the encrypted types |
| // should be unioned and the cryptographer should have both keys and be |
| @@ -1098,8 +1019,8 @@ TEST_F(SyncerTest, NigoriConflicts) { |
| our_encrypted_specifics.mutable_encrypted()); |
| cryptographer(&wtrans)->GetKeys( |
| nigori->mutable_encrypted()); |
| + fake_encryption_handler_.EnableEncryptEverything(); |
| cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); |
| - cryptographer(&wtrans)->set_encrypt_everything(); |
| MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| ModelTypeToRootTag(NIGORI)); |
| ASSERT_TRUE(nigori_entry.good()); |
| @@ -1108,6 +1029,7 @@ TEST_F(SyncerTest, NigoriConflicts) { |
| EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); |
| EXPECT_TRUE(encrypted_types.Equals( |
| cryptographer(&wtrans)->GetEncryptedTypes())); |
| + fake_encryption_handler_.set_cryptographer(cryptographer(&wtrans)); |
| } |
| { |
| sync_pb::EntitySpecifics specifics; |
| @@ -1136,10 +1058,10 @@ TEST_F(SyncerTest, NigoriConflicts) { |
| EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); |
| - EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); |
| + ASSERT_TRUE(cryptographer(&wtrans)->has_pending_keys()); |
| EXPECT_TRUE(encrypted_types.Equals( |
| - cryptographer(&wtrans)->GetEncryptedTypes())); |
| - EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything()); |
| + cryptographer(&wtrans)->GetEncryptedTypes())); |
| + EXPECT_TRUE(fake_encryption_handler_.EncryptEverythingEnabled()); |
| EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); |
| // Supply the pending keys. Afterwards, we should be able to decrypt both |
| // our own encrypted data and data encrypted by the other cryptographer, |