Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1460)

Unified Diff: sync/engine/syncer_unittest.cc

Issue 10827266: [Sync] Add SyncEncryptionHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 2 Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/engine/syncer_unittest.cc
diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc
index 7372f68c1872c29d27e0ccfa820f90220d426cfe..c7886f0752fcff45508d4ffeb079ca7a3d6841ff 100644
--- a/sync/engine/syncer_unittest.cc
+++ b/sync/engine/syncer_unittest.cc
@@ -50,6 +50,7 @@
#include "sync/test/engine/test_syncable_utils.h"
#include "sync/test/fake_encryptor.h"
#include "sync/test/fake_extensions_activity_monitor.h"
+#include "sync/test/fake_sync_encryption_handler.h"
#include "sync/util/cryptographer.h"
#include "sync/util/time.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -255,6 +256,7 @@ 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)->SetNigoriHandler(&fake_encryption_handler_);
tim (not reviewing) 2012/08/15 00:23:30 This accessor should really be called GetCryptogra
Nicolas Zea 2012/08/15 01:08:29 Done.
}
virtual void TearDown() {
@@ -566,6 +568,8 @@ class SyncerTest : public testing::Test,
ModelTypeSet enabled_datatypes_;
TrafficRecorder traffic_recorder_;
+ FakeSyncEncryptionHandler fake_encryption_handler_;
+
DISALLOW_COPY_AND_ASSIGN(SyncerTest);
};
@@ -723,12 +727,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 +840,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 +981,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) {
- 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 +1018,10 @@ TEST_F(SyncerTest, NigoriConflicts) {
our_encrypted_specifics.mutable_encrypted());
cryptographer(&wtrans)->GetKeys(
nigori->mutable_encrypted());
- cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
- cryptographer(&wtrans)->set_encrypt_everything();
+ fake_encryption_handler_.EnableEncryptEverything();
+ cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(
+ nigori,
+ &wtrans);
MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
ModelTypeToRootTag(NIGORI));
ASSERT_TRUE(nigori_entry.good());
@@ -1108,6 +1030,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 +1059,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,
@@ -1148,7 +1071,7 @@ TEST_F(SyncerTest, NigoriConflicts) {
EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted());
- cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
+ cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori, &wtrans);
// Normally this would be written as part of SetPassphrase, but we do it
// manually for the test.
nigori_entry.Put(SPECIFICS, specifics);

Powered by Google App Engine
This is Rietveld 408576698