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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 10827266: [Sync] Add SyncEncryptionHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/apply_updates_command_unittest.cc ('k') | sync/engine/syncer_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 15 matching lines...) Expand all
26 #include "sync/engine/get_commit_ids_command.h" 26 #include "sync/engine/get_commit_ids_command.h"
27 #include "sync/engine/net/server_connection_manager.h" 27 #include "sync/engine/net/server_connection_manager.h"
28 #include "sync/engine/process_updates_command.h" 28 #include "sync/engine/process_updates_command.h"
29 #include "sync/engine/sync_scheduler_impl.h" 29 #include "sync/engine/sync_scheduler_impl.h"
30 #include "sync/engine/syncer.h" 30 #include "sync/engine/syncer.h"
31 #include "sync/engine/syncer_proto_util.h" 31 #include "sync/engine/syncer_proto_util.h"
32 #include "sync/engine/throttled_data_type_tracker.h" 32 #include "sync/engine/throttled_data_type_tracker.h"
33 #include "sync/engine/traffic_recorder.h" 33 #include "sync/engine/traffic_recorder.h"
34 #include "sync/internal_api/public/base/model_type.h" 34 #include "sync/internal_api/public/base/model_type.h"
35 #include "sync/internal_api/public/engine/model_safe_worker.h" 35 #include "sync/internal_api/public/engine/model_safe_worker.h"
36 #include "sync/internal_api/public/test/fake_sync_encryption_handler.h"
36 #include "sync/protocol/bookmark_specifics.pb.h" 37 #include "sync/protocol/bookmark_specifics.pb.h"
37 #include "sync/protocol/nigori_specifics.pb.h" 38 #include "sync/protocol/nigori_specifics.pb.h"
38 #include "sync/protocol/preference_specifics.pb.h" 39 #include "sync/protocol/preference_specifics.pb.h"
39 #include "sync/protocol/sync.pb.h" 40 #include "sync/protocol/sync.pb.h"
40 #include "sync/sessions/sync_session_context.h" 41 #include "sync/sessions/sync_session_context.h"
41 #include "sync/syncable/mutable_entry.h" 42 #include "sync/syncable/mutable_entry.h"
42 #include "sync/syncable/nigori_util.h" 43 #include "sync/syncable/nigori_util.h"
43 #include "sync/syncable/read_transaction.h" 44 #include "sync/syncable/read_transaction.h"
44 #include "sync/syncable/syncable_util.h" 45 #include "sync/syncable/syncable_util.h"
45 #include "sync/syncable/write_transaction.h" 46 #include "sync/syncable/write_transaction.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 syncable::ReadTransaction trans(FROM_HERE, directory()); 249 syncable::ReadTransaction trans(FROM_HERE, directory());
249 syncable::Directory::ChildHandles children; 250 syncable::Directory::ChildHandles children;
250 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); 251 directory()->GetChildHandlesById(&trans, trans.root_id(), &children);
251 ASSERT_EQ(0u, children.size()); 252 ASSERT_EQ(0u, children.size());
252 saw_syncer_event_ = false; 253 saw_syncer_event_ = false;
253 root_id_ = TestIdFactory::root(); 254 root_id_ = TestIdFactory::root();
254 parent_id_ = ids_.MakeServer("parent id"); 255 parent_id_ = ids_.MakeServer("parent id");
255 child_id_ = ids_.MakeServer("child id"); 256 child_id_ = ids_.MakeServer("child id");
256 directory()->set_store_birthday(mock_server_->store_birthday()); 257 directory()->set_store_birthday(mock_server_->store_birthday());
257 mock_server_->SetKeystoreKey("encryption_key"); 258 mock_server_->SetKeystoreKey("encryption_key");
259 cryptographer(&trans)->SetSyncEncryptionHandlerDelegate(
260 &fake_encryption_handler_);
258 } 261 }
259 262
260 virtual void TearDown() { 263 virtual void TearDown() {
261 mock_server_.reset(); 264 mock_server_.reset();
262 delete syncer_; 265 delete syncer_;
263 syncer_ = NULL; 266 syncer_ = NULL;
264 dir_maker_.TearDown(); 267 dir_maker_.TearDown();
265 } 268 }
266 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { 269 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) {
267 EXPECT_FALSE(entry->Get(IS_DIR)); 270 EXPECT_FALSE(entry->Get(IS_DIR));
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 scoped_ptr<SyncSessionContext> context_; 562 scoped_ptr<SyncSessionContext> context_;
560 bool saw_syncer_event_; 563 bool saw_syncer_event_;
561 base::TimeDelta last_short_poll_interval_received_; 564 base::TimeDelta last_short_poll_interval_received_;
562 base::TimeDelta last_long_poll_interval_received_; 565 base::TimeDelta last_long_poll_interval_received_;
563 base::TimeDelta last_sessions_commit_delay_seconds_; 566 base::TimeDelta last_sessions_commit_delay_seconds_;
564 scoped_refptr<ModelSafeWorker> worker_; 567 scoped_refptr<ModelSafeWorker> worker_;
565 568
566 ModelTypeSet enabled_datatypes_; 569 ModelTypeSet enabled_datatypes_;
567 TrafficRecorder traffic_recorder_; 570 TrafficRecorder traffic_recorder_;
568 571
572 FakeSyncEncryptionHandler fake_encryption_handler_;
573
569 DISALLOW_COPY_AND_ASSIGN(SyncerTest); 574 DISALLOW_COPY_AND_ASSIGN(SyncerTest);
570 }; 575 };
571 576
572 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { 577 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) {
573 { 578 {
574 Syncer::UnsyncedMetaHandles handles; 579 Syncer::UnsyncedMetaHandles handles;
575 { 580 {
576 syncable::ReadTransaction trans(FROM_HERE, directory()); 581 syncable::ReadTransaction trans(FROM_HERE, directory());
577 GetUnsyncedEntries(&trans, &handles); 582 GetUnsyncedEntries(&trans, &handles);
578 } 583 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); 721 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20);
717 { 722 {
718 // Mark bookmarks as encrypted and set the cryptographer to have pending 723 // Mark bookmarks as encrypted and set the cryptographer to have pending
719 // keys. 724 // keys.
720 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 725 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
721 Cryptographer other_cryptographer(&encryptor_); 726 Cryptographer other_cryptographer(&encryptor_);
722 other_cryptographer.AddKey(other_params); 727 other_cryptographer.AddKey(other_params);
723 sync_pb::EntitySpecifics specifics; 728 sync_pb::EntitySpecifics specifics;
724 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 729 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
725 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 730 other_cryptographer.GetKeys(nigori->mutable_encrypted());
726 nigori->set_encrypt_bookmarks(true); 731 fake_encryption_handler_.EnableEncryptEverything();
727 // Set up with an old passphrase, but have pending keys 732 // Set up with an old passphrase, but have pending keys
728 cryptographer(&wtrans)->AddKey(key_params); 733 cryptographer(&wtrans)->AddKey(key_params);
729 cryptographer(&wtrans)->Encrypt(bookmark, 734 cryptographer(&wtrans)->Encrypt(bookmark,
730 encrypted_bookmark.mutable_encrypted()); 735 encrypted_bookmark.mutable_encrypted());
731 cryptographer(&wtrans)->Update(*nigori); 736 cryptographer(&wtrans)->SetPendingKeys(nigori->encrypted());
732 737
733 // In conflict but properly encrypted. 738 // In conflict but properly encrypted.
734 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 739 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
735 ASSERT_TRUE(A.good()); 740 ASSERT_TRUE(A.good());
736 A.Put(IS_UNSYNCED, true); 741 A.Put(IS_UNSYNCED, true);
737 A.Put(SPECIFICS, encrypted_bookmark); 742 A.Put(SPECIFICS, encrypted_bookmark);
738 A.Put(NON_UNIQUE_NAME, kEncryptedString); 743 A.Put(NON_UNIQUE_NAME, kEncryptedString);
739 // Not in conflict and properly encrypted. 744 // Not in conflict and properly encrypted.
740 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 745 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
741 ASSERT_TRUE(B.good()); 746 ASSERT_TRUE(B.good());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 modified_pref.mutable_preference()->set_name("name2"); 834 modified_pref.mutable_preference()->set_name("name2");
830 other_cryptographer.Encrypt(modified_pref, 835 other_cryptographer.Encrypt(modified_pref,
831 modified_pref.mutable_encrypted()); 836 modified_pref.mutable_encrypted());
832 { 837 {
833 // Mark bookmarks and preferences as encrypted and set the cryptographer to 838 // Mark bookmarks and preferences as encrypted and set the cryptographer to
834 // have pending keys. 839 // have pending keys.
835 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 840 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
836 sync_pb::EntitySpecifics specifics; 841 sync_pb::EntitySpecifics specifics;
837 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 842 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
838 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 843 other_cryptographer.GetKeys(nigori->mutable_encrypted());
839 nigori->set_encrypt_bookmarks(true); 844 fake_encryption_handler_.EnableEncryptEverything();
840 nigori->set_encrypt_preferences(true); 845 cryptographer(&wtrans)->SetPendingKeys(nigori->encrypted());
841 cryptographer(&wtrans)->Update(*nigori);
842 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 846 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
843 } 847 }
844 848
845 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); 849 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark);
846 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); 850 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark);
847 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); 851 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark);
848 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); 852 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
849 SyncShareNudge(); 853 SyncShareNudge();
850 { 854 {
851 // Initial state. Everything is normal. 855 // Initial state. Everything is normal.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK); 975 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK);
972 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 976 syncable::ReadTransaction rtrans(FROM_HERE, directory());
973 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); 977 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans);
974 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); 978 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
975 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); 979 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans);
976 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); 980 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans);
977 } 981 }
978 982
979 #undef VERIFY_ENTRY 983 #undef VERIFY_ENTRY
980 984
981 // Receive an old nigori with old encryption keys and encrypted types. We should
982 // not revert our default key or encrypted types.
983 TEST_F(SyncerTest, ReceiveOldNigori) {
Nicolas Zea 2012/08/10 02:58:06 this test moved to SyncEncryptionHandlerImplTest
984 KeyParams old_key = {"localhost", "dummy", "old"};
985 KeyParams current_key = {"localhost", "dummy", "cur"};
986
987 // Data for testing encryption/decryption.
988 Cryptographer other_cryptographer(&encryptor_);
989 other_cryptographer.AddKey(old_key);
990 sync_pb::EntitySpecifics other_encrypted_specifics;
991 other_encrypted_specifics.mutable_bookmark()->set_title("title");
992 other_cryptographer.Encrypt(
993 other_encrypted_specifics,
994 other_encrypted_specifics.mutable_encrypted());
995 sync_pb::EntitySpecifics our_encrypted_specifics;
996 our_encrypted_specifics.mutable_bookmark()->set_title("title2");
997 ModelTypeSet encrypted_types = ModelTypeSet::All();
998
999
1000 // Receive the initial nigori node.
1001 sync_pb::EntitySpecifics initial_nigori_specifics;
1002 initial_nigori_specifics.mutable_nigori();
1003 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics);
1004 SyncShareNudge();
1005
1006 {
1007 // Set up the current nigori node (containing both keys and encrypt
1008 // everything).
1009 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1010 sync_pb::EntitySpecifics specifics;
1011 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1012 cryptographer(&wtrans)->AddKey(old_key);
1013 cryptographer(&wtrans)->AddKey(current_key);
1014 cryptographer(&wtrans)->Encrypt(
1015 our_encrypted_specifics,
1016 our_encrypted_specifics.mutable_encrypted());
1017 cryptographer(&wtrans)->GetKeys(
1018 nigori->mutable_encrypted());
1019 cryptographer(&wtrans)->set_encrypt_everything();
1020 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
1021 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1022 ModelTypeToRootTag(NIGORI));
1023 ASSERT_TRUE(nigori_entry.good());
1024 nigori_entry.Put(SPECIFICS, specifics);
1025 nigori_entry.Put(IS_UNSYNCED, true);
1026 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
1027 EXPECT_TRUE(encrypted_types.Equals(
1028 cryptographer(&wtrans)->GetEncryptedTypes()));
1029 }
1030
1031 SyncShareNudge(); // Commit it.
1032
1033 // Now set up the old nigori node and add it as a server update.
1034 sync_pb::EntitySpecifics old_nigori_specifics;
1035 sync_pb::NigoriSpecifics *old_nigori = old_nigori_specifics.mutable_nigori();
1036 other_cryptographer.GetKeys(old_nigori->mutable_encrypted());
1037 other_cryptographer.UpdateNigoriFromEncryptedTypes(old_nigori);
1038 mock_server_->SetNigori(1, 30, 30, old_nigori_specifics);
1039
1040 SyncShareNudge(); // Download the old nigori and apply it.
1041
1042 {
1043 // Ensure everything is committed and stable now. The cryptographer
1044 // should be able to decrypt both sets of keys and still be encrypting with
1045 // the newest, and the encrypted types should be the most recent
1046 syncable::ReadTransaction trans(FROM_HERE, directory());
1047 Entry nigori_entry(&trans, GET_BY_SERVER_TAG,
1048 ModelTypeToRootTag(NIGORI));
1049 ASSERT_TRUE(nigori_entry.good());
1050 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
1051 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED));
1052 const sync_pb::NigoriSpecifics& nigori =
1053 nigori_entry.Get(SPECIFICS).nigori();
1054 EXPECT_TRUE(cryptographer(&trans)->CanDecryptUsingDefaultKey(
1055 our_encrypted_specifics.encrypted()));
1056 EXPECT_TRUE(cryptographer(&trans)->CanDecrypt(
1057 other_encrypted_specifics.encrypted()));
1058 EXPECT_TRUE(cryptographer(&trans)->CanDecrypt(
1059 nigori.encrypted()));
1060 EXPECT_TRUE(cryptographer(&trans)->encrypt_everything());
1061 }
1062 }
1063
1064 // Resolve a confict between two nigori's with different encrypted types, 985 // Resolve a confict between two nigori's with different encrypted types,
1065 // and encryption keys (remote is explicit). Afterwards, the encrypted types 986 // and encryption keys (remote is explicit). Afterwards, the encrypted types
1066 // should be unioned and the cryptographer should have both keys and be 987 // should be unioned and the cryptographer should have both keys and be
1067 // encrypting with the remote encryption key by default. 988 // encrypting with the remote encryption key by default.
1068 TEST_F(SyncerTest, NigoriConflicts) { 989 TEST_F(SyncerTest, NigoriConflicts) {
1069 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; 990 KeyParams local_key_params = {"localhost", "dummy", "blargle"};
1070 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; 991 KeyParams other_key_params = {"localhost", "dummy", "foobar"};
1071 Cryptographer other_cryptographer(&encryptor_); 992 Cryptographer other_cryptographer(&encryptor_);
1072 other_cryptographer.AddKey(other_key_params); 993 other_cryptographer.AddKey(other_key_params);
1073 ModelTypeSet encrypted_types(PASSWORDS, NIGORI); 994 ModelTypeSet encrypted_types(PASSWORDS, NIGORI);
(...skipping 17 matching lines...) Expand all
1091 // Local changes with different passphrase, different types. 1012 // Local changes with different passphrase, different types.
1092 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1013 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1093 sync_pb::EntitySpecifics specifics; 1014 sync_pb::EntitySpecifics specifics;
1094 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1015 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1095 cryptographer(&wtrans)->AddKey(local_key_params); 1016 cryptographer(&wtrans)->AddKey(local_key_params);
1096 cryptographer(&wtrans)->Encrypt( 1017 cryptographer(&wtrans)->Encrypt(
1097 our_encrypted_specifics, 1018 our_encrypted_specifics,
1098 our_encrypted_specifics.mutable_encrypted()); 1019 our_encrypted_specifics.mutable_encrypted());
1099 cryptographer(&wtrans)->GetKeys( 1020 cryptographer(&wtrans)->GetKeys(
1100 nigori->mutable_encrypted()); 1021 nigori->mutable_encrypted());
1022 fake_encryption_handler_.EnableEncryptEverything();
1101 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 1023 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
1102 cryptographer(&wtrans)->set_encrypt_everything();
1103 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1024 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1104 ModelTypeToRootTag(NIGORI)); 1025 ModelTypeToRootTag(NIGORI));
1105 ASSERT_TRUE(nigori_entry.good()); 1026 ASSERT_TRUE(nigori_entry.good());
1106 nigori_entry.Put(SPECIFICS, specifics); 1027 nigori_entry.Put(SPECIFICS, specifics);
1107 nigori_entry.Put(IS_UNSYNCED, true); 1028 nigori_entry.Put(IS_UNSYNCED, true);
1108 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 1029 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
1109 EXPECT_TRUE(encrypted_types.Equals( 1030 EXPECT_TRUE(encrypted_types.Equals(
1110 cryptographer(&wtrans)->GetEncryptedTypes())); 1031 cryptographer(&wtrans)->GetEncryptedTypes()));
1032 fake_encryption_handler_.set_cryptographer(cryptographer(&wtrans));
1111 } 1033 }
1112 { 1034 {
1113 sync_pb::EntitySpecifics specifics; 1035 sync_pb::EntitySpecifics specifics;
1114 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1036 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1115 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 1037 other_cryptographer.GetKeys(nigori->mutable_encrypted());
1116 nigori->set_encrypt_bookmarks(true); 1038 nigori->set_encrypt_bookmarks(true);
1117 nigori->set_encrypt_preferences(true); 1039 nigori->set_encrypt_preferences(true);
1118 nigori->set_encrypt_everything(false); 1040 nigori->set_encrypt_everything(false);
1119 nigori->set_using_explicit_passphrase(true); 1041 nigori->set_using_explicit_passphrase(true);
1120 mock_server_->SetNigori(1, 20, 20, specifics); 1042 mock_server_->SetNigori(1, 20, 20, specifics);
1121 } 1043 }
1122 1044
1123 // Will result in downloading the server nigori, which puts the local nigori 1045 // Will result in downloading the server nigori, which puts the local nigori
1124 // in a state of conflict. This is resolved by merging the local and server 1046 // in a state of conflict. This is resolved by merging the local and server
1125 // data (with priority given to the server's encryption keys if they are 1047 // data (with priority given to the server's encryption keys if they are
1126 // undecryptable), which we then commit. The cryptographer should have pending 1048 // undecryptable), which we then commit. The cryptographer should have pending
1127 // keys and merge the set of encrypted types. 1049 // keys and merge the set of encrypted types.
1128 SyncShareNudge(); // Resolve conflict in this cycle. 1050 SyncShareNudge(); // Resolve conflict in this cycle.
1129 SyncShareNudge(); // Commit local change in this cycle. 1051 SyncShareNudge(); // Commit local change in this cycle.
1130 { 1052 {
1131 // Ensure the nigori data merged (encrypted types). 1053 // Ensure the nigori data merged (encrypted types).
1132 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1054 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1133 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1055 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1134 ModelTypeToRootTag(NIGORI)); 1056 ModelTypeToRootTag(NIGORI));
1135 ASSERT_TRUE(nigori_entry.good()); 1057 ASSERT_TRUE(nigori_entry.good());
1136 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); 1058 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
1137 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); 1059 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED));
1138 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); 1060 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS);
1139 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 1061 ASSERT_TRUE(cryptographer(&wtrans)->has_pending_keys());
1140 EXPECT_TRUE(encrypted_types.Equals( 1062 EXPECT_TRUE(encrypted_types.Equals(
1141 cryptographer(&wtrans)->GetEncryptedTypes())); 1063 cryptographer(&wtrans)->GetEncryptedTypes()));
1142 EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything()); 1064 EXPECT_TRUE(fake_encryption_handler_.EncryptEverythingEnabled());
1143 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); 1065 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase());
1144 // Supply the pending keys. Afterwards, we should be able to decrypt both 1066 // Supply the pending keys. Afterwards, we should be able to decrypt both
1145 // our own encrypted data and data encrypted by the other cryptographer, 1067 // our own encrypted data and data encrypted by the other cryptographer,
1146 // but the key provided by the other cryptographer should be the default. 1068 // but the key provided by the other cryptographer should be the default.
1147 EXPECT_TRUE(cryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); 1069 EXPECT_TRUE(cryptographer(&wtrans)->DecryptPendingKeys(other_key_params));
1148 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 1070 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
1149 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1071 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1150 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted()); 1072 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted());
1151 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 1073 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
1152 // Normally this would be written as part of SetPassphrase, but we do it 1074 // Normally this would be written as part of SetPassphrase, but we do it
(...skipping 3704 matching lines...) Expand 10 before | Expand all | Expand 10 after
4857 4779
4858 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4780 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4859 Add(mid_id_); 4781 Add(mid_id_);
4860 Add(low_id_); 4782 Add(low_id_);
4861 Add(high_id_); 4783 Add(high_id_);
4862 SyncShareNudge(); 4784 SyncShareNudge();
4863 ExpectLocalOrderIsByServerId(); 4785 ExpectLocalOrderIsByServerId();
4864 } 4786 }
4865 4787
4866 } // namespace syncer 4788 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/apply_updates_command_unittest.cc ('k') | sync/engine/syncer_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698