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

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: 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 unified diff | Download patch | Annotate | Revision Log
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "sync/syncable/read_transaction.h" 43 #include "sync/syncable/read_transaction.h"
44 #include "sync/syncable/syncable_util.h" 44 #include "sync/syncable/syncable_util.h"
45 #include "sync/syncable/write_transaction.h" 45 #include "sync/syncable/write_transaction.h"
46 #include "sync/test/engine/fake_model_worker.h" 46 #include "sync/test/engine/fake_model_worker.h"
47 #include "sync/test/engine/mock_connection_manager.h" 47 #include "sync/test/engine/mock_connection_manager.h"
48 #include "sync/test/engine/test_directory_setter_upper.h" 48 #include "sync/test/engine/test_directory_setter_upper.h"
49 #include "sync/test/engine/test_id_factory.h" 49 #include "sync/test/engine/test_id_factory.h"
50 #include "sync/test/engine/test_syncable_utils.h" 50 #include "sync/test/engine/test_syncable_utils.h"
51 #include "sync/test/fake_encryptor.h" 51 #include "sync/test/fake_encryptor.h"
52 #include "sync/test/fake_extensions_activity_monitor.h" 52 #include "sync/test/fake_extensions_activity_monitor.h"
53 #include "sync/test/fake_sync_encryption_handler.h"
53 #include "sync/util/cryptographer.h" 54 #include "sync/util/cryptographer.h"
54 #include "sync/util/time.h" 55 #include "sync/util/time.h"
55 #include "testing/gtest/include/gtest/gtest.h" 56 #include "testing/gtest/include/gtest/gtest.h"
56 57
57 using base::TimeDelta; 58 using base::TimeDelta;
58 59
59 using std::map; 60 using std::map;
60 using std::multimap; 61 using std::multimap;
61 using std::set; 62 using std::set;
62 using std::string; 63 using std::string;
(...skipping 185 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)->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.
258 } 260 }
259 261
260 virtual void TearDown() { 262 virtual void TearDown() {
261 mock_server_.reset(); 263 mock_server_.reset();
262 delete syncer_; 264 delete syncer_;
263 syncer_ = NULL; 265 syncer_ = NULL;
264 dir_maker_.TearDown(); 266 dir_maker_.TearDown();
265 } 267 }
266 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { 268 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) {
267 EXPECT_FALSE(entry->Get(IS_DIR)); 269 EXPECT_FALSE(entry->Get(IS_DIR));
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 scoped_ptr<SyncSessionContext> context_; 561 scoped_ptr<SyncSessionContext> context_;
560 bool saw_syncer_event_; 562 bool saw_syncer_event_;
561 base::TimeDelta last_short_poll_interval_received_; 563 base::TimeDelta last_short_poll_interval_received_;
562 base::TimeDelta last_long_poll_interval_received_; 564 base::TimeDelta last_long_poll_interval_received_;
563 base::TimeDelta last_sessions_commit_delay_seconds_; 565 base::TimeDelta last_sessions_commit_delay_seconds_;
564 scoped_refptr<ModelSafeWorker> worker_; 566 scoped_refptr<ModelSafeWorker> worker_;
565 567
566 ModelTypeSet enabled_datatypes_; 568 ModelTypeSet enabled_datatypes_;
567 TrafficRecorder traffic_recorder_; 569 TrafficRecorder traffic_recorder_;
568 570
571 FakeSyncEncryptionHandler fake_encryption_handler_;
572
569 DISALLOW_COPY_AND_ASSIGN(SyncerTest); 573 DISALLOW_COPY_AND_ASSIGN(SyncerTest);
570 }; 574 };
571 575
572 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { 576 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) {
573 { 577 {
574 Syncer::UnsyncedMetaHandles handles; 578 Syncer::UnsyncedMetaHandles handles;
575 { 579 {
576 syncable::ReadTransaction trans(FROM_HERE, directory()); 580 syncable::ReadTransaction trans(FROM_HERE, directory());
577 GetUnsyncedEntries(&trans, &handles); 581 GetUnsyncedEntries(&trans, &handles);
578 } 582 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); 720 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20);
717 { 721 {
718 // Mark bookmarks as encrypted and set the cryptographer to have pending 722 // Mark bookmarks as encrypted and set the cryptographer to have pending
719 // keys. 723 // keys.
720 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 724 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
721 Cryptographer other_cryptographer(&encryptor_); 725 Cryptographer other_cryptographer(&encryptor_);
722 other_cryptographer.AddKey(other_params); 726 other_cryptographer.AddKey(other_params);
723 sync_pb::EntitySpecifics specifics; 727 sync_pb::EntitySpecifics specifics;
724 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 728 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
725 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 729 other_cryptographer.GetKeys(nigori->mutable_encrypted());
726 nigori->set_encrypt_bookmarks(true); 730 fake_encryption_handler_.EnableEncryptEverything();
727 // Set up with an old passphrase, but have pending keys 731 // Set up with an old passphrase, but have pending keys
728 cryptographer(&wtrans)->AddKey(key_params); 732 cryptographer(&wtrans)->AddKey(key_params);
729 cryptographer(&wtrans)->Encrypt(bookmark, 733 cryptographer(&wtrans)->Encrypt(bookmark,
730 encrypted_bookmark.mutable_encrypted()); 734 encrypted_bookmark.mutable_encrypted());
731 cryptographer(&wtrans)->Update(*nigori); 735 cryptographer(&wtrans)->SetPendingKeys(nigori->encrypted());
732 736
733 // In conflict but properly encrypted. 737 // In conflict but properly encrypted.
734 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 738 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
735 ASSERT_TRUE(A.good()); 739 ASSERT_TRUE(A.good());
736 A.Put(IS_UNSYNCED, true); 740 A.Put(IS_UNSYNCED, true);
737 A.Put(SPECIFICS, encrypted_bookmark); 741 A.Put(SPECIFICS, encrypted_bookmark);
738 A.Put(NON_UNIQUE_NAME, kEncryptedString); 742 A.Put(NON_UNIQUE_NAME, kEncryptedString);
739 // Not in conflict and properly encrypted. 743 // Not in conflict and properly encrypted.
740 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 744 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
741 ASSERT_TRUE(B.good()); 745 ASSERT_TRUE(B.good());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 modified_pref.mutable_preference()->set_name("name2"); 833 modified_pref.mutable_preference()->set_name("name2");
830 other_cryptographer.Encrypt(modified_pref, 834 other_cryptographer.Encrypt(modified_pref,
831 modified_pref.mutable_encrypted()); 835 modified_pref.mutable_encrypted());
832 { 836 {
833 // Mark bookmarks and preferences as encrypted and set the cryptographer to 837 // Mark bookmarks and preferences as encrypted and set the cryptographer to
834 // have pending keys. 838 // have pending keys.
835 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 839 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
836 sync_pb::EntitySpecifics specifics; 840 sync_pb::EntitySpecifics specifics;
837 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 841 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
838 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 842 other_cryptographer.GetKeys(nigori->mutable_encrypted());
839 nigori->set_encrypt_bookmarks(true); 843 fake_encryption_handler_.EnableEncryptEverything();
840 nigori->set_encrypt_preferences(true); 844 cryptographer(&wtrans)->SetPendingKeys(nigori->encrypted());
841 cryptographer(&wtrans)->Update(*nigori);
842 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 845 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
843 } 846 }
844 847
845 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); 848 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark);
846 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); 849 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark);
847 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); 850 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark);
848 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); 851 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
849 SyncShareNudge(); 852 SyncShareNudge();
850 { 853 {
851 // Initial state. Everything is normal. 854 // 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); 974 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK);
972 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 975 syncable::ReadTransaction rtrans(FROM_HERE, directory());
973 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); 976 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans);
974 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); 977 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
975 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); 978 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans);
976 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); 979 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans);
977 } 980 }
978 981
979 #undef VERIFY_ENTRY 982 #undef VERIFY_ENTRY
980 983
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) {
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, 984 // Resolve a confict between two nigori's with different encrypted types,
1065 // and encryption keys (remote is explicit). Afterwards, the encrypted types 985 // and encryption keys (remote is explicit). Afterwards, the encrypted types
1066 // should be unioned and the cryptographer should have both keys and be 986 // should be unioned and the cryptographer should have both keys and be
1067 // encrypting with the remote encryption key by default. 987 // encrypting with the remote encryption key by default.
1068 TEST_F(SyncerTest, NigoriConflicts) { 988 TEST_F(SyncerTest, NigoriConflicts) {
1069 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; 989 KeyParams local_key_params = {"localhost", "dummy", "blargle"};
1070 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; 990 KeyParams other_key_params = {"localhost", "dummy", "foobar"};
1071 Cryptographer other_cryptographer(&encryptor_); 991 Cryptographer other_cryptographer(&encryptor_);
1072 other_cryptographer.AddKey(other_key_params); 992 other_cryptographer.AddKey(other_key_params);
1073 ModelTypeSet encrypted_types(PASSWORDS, NIGORI); 993 ModelTypeSet encrypted_types(PASSWORDS, NIGORI);
(...skipping 17 matching lines...) Expand all
1091 // Local changes with different passphrase, different types. 1011 // Local changes with different passphrase, different types.
1092 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1012 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1093 sync_pb::EntitySpecifics specifics; 1013 sync_pb::EntitySpecifics specifics;
1094 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1014 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1095 cryptographer(&wtrans)->AddKey(local_key_params); 1015 cryptographer(&wtrans)->AddKey(local_key_params);
1096 cryptographer(&wtrans)->Encrypt( 1016 cryptographer(&wtrans)->Encrypt(
1097 our_encrypted_specifics, 1017 our_encrypted_specifics,
1098 our_encrypted_specifics.mutable_encrypted()); 1018 our_encrypted_specifics.mutable_encrypted());
1099 cryptographer(&wtrans)->GetKeys( 1019 cryptographer(&wtrans)->GetKeys(
1100 nigori->mutable_encrypted()); 1020 nigori->mutable_encrypted());
1101 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 1021 fake_encryption_handler_.EnableEncryptEverything();
1102 cryptographer(&wtrans)->set_encrypt_everything(); 1022 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(
1023 nigori,
1024 &wtrans);
1103 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1025 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1104 ModelTypeToRootTag(NIGORI)); 1026 ModelTypeToRootTag(NIGORI));
1105 ASSERT_TRUE(nigori_entry.good()); 1027 ASSERT_TRUE(nigori_entry.good());
1106 nigori_entry.Put(SPECIFICS, specifics); 1028 nigori_entry.Put(SPECIFICS, specifics);
1107 nigori_entry.Put(IS_UNSYNCED, true); 1029 nigori_entry.Put(IS_UNSYNCED, true);
1108 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 1030 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
1109 EXPECT_TRUE(encrypted_types.Equals( 1031 EXPECT_TRUE(encrypted_types.Equals(
1110 cryptographer(&wtrans)->GetEncryptedTypes())); 1032 cryptographer(&wtrans)->GetEncryptedTypes()));
1033 fake_encryption_handler_.set_cryptographer(cryptographer(&wtrans));
1111 } 1034 }
1112 { 1035 {
1113 sync_pb::EntitySpecifics specifics; 1036 sync_pb::EntitySpecifics specifics;
1114 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1037 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1115 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 1038 other_cryptographer.GetKeys(nigori->mutable_encrypted());
1116 nigori->set_encrypt_bookmarks(true); 1039 nigori->set_encrypt_bookmarks(true);
1117 nigori->set_encrypt_preferences(true); 1040 nigori->set_encrypt_preferences(true);
1118 nigori->set_encrypt_everything(false); 1041 nigori->set_encrypt_everything(false);
1119 nigori->set_using_explicit_passphrase(true); 1042 nigori->set_using_explicit_passphrase(true);
1120 mock_server_->SetNigori(1, 20, 20, specifics); 1043 mock_server_->SetNigori(1, 20, 20, specifics);
1121 } 1044 }
1122 1045
1123 // Will result in downloading the server nigori, which puts the local nigori 1046 // 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 1047 // 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 1048 // data (with priority given to the server's encryption keys if they are
1126 // undecryptable), which we then commit. The cryptographer should have pending 1049 // undecryptable), which we then commit. The cryptographer should have pending
1127 // keys and merge the set of encrypted types. 1050 // keys and merge the set of encrypted types.
1128 SyncShareNudge(); // Resolve conflict in this cycle. 1051 SyncShareNudge(); // Resolve conflict in this cycle.
1129 SyncShareNudge(); // Commit local change in this cycle. 1052 SyncShareNudge(); // Commit local change in this cycle.
1130 { 1053 {
1131 // Ensure the nigori data merged (encrypted types). 1054 // Ensure the nigori data merged (encrypted types).
1132 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1055 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1133 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1056 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1134 ModelTypeToRootTag(NIGORI)); 1057 ModelTypeToRootTag(NIGORI));
1135 ASSERT_TRUE(nigori_entry.good()); 1058 ASSERT_TRUE(nigori_entry.good());
1136 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); 1059 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
1137 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); 1060 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED));
1138 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); 1061 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS);
1139 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 1062 ASSERT_TRUE(cryptographer(&wtrans)->has_pending_keys());
1140 EXPECT_TRUE(encrypted_types.Equals( 1063 EXPECT_TRUE(encrypted_types.Equals(
1141 cryptographer(&wtrans)->GetEncryptedTypes())); 1064 cryptographer(&wtrans)->GetEncryptedTypes()));
1142 EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything()); 1065 EXPECT_TRUE(fake_encryption_handler_.EncryptEverythingEnabled());
1143 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); 1066 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase());
1144 // Supply the pending keys. Afterwards, we should be able to decrypt both 1067 // Supply the pending keys. Afterwards, we should be able to decrypt both
1145 // our own encrypted data and data encrypted by the other cryptographer, 1068 // our own encrypted data and data encrypted by the other cryptographer,
1146 // but the key provided by the other cryptographer should be the default. 1069 // but the key provided by the other cryptographer should be the default.
1147 EXPECT_TRUE(cryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); 1070 EXPECT_TRUE(cryptographer(&wtrans)->DecryptPendingKeys(other_key_params));
1148 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 1071 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
1149 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1072 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1150 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted()); 1073 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted());
1151 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 1074 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori, &wtrans);
1152 // Normally this would be written as part of SetPassphrase, but we do it 1075 // Normally this would be written as part of SetPassphrase, but we do it
1153 // manually for the test. 1076 // manually for the test.
1154 nigori_entry.Put(SPECIFICS, specifics); 1077 nigori_entry.Put(SPECIFICS, specifics);
1155 nigori_entry.Put(IS_UNSYNCED, true); 1078 nigori_entry.Put(IS_UNSYNCED, true);
1156 } 1079 }
1157 1080
1158 SyncShareNudge(); 1081 SyncShareNudge();
1159 { 1082 {
1160 // Ensure everything is committed and stable now. The cryptographer 1083 // Ensure everything is committed and stable now. The cryptographer
1161 // should be able to decrypt both sets of keys, and the encrypted types 1084 // should be able to decrypt both sets of keys, and the encrypted types
(...skipping 3695 matching lines...) Expand 10 before | Expand all | Expand 10 after
4857 4780
4858 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4781 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4859 Add(mid_id_); 4782 Add(mid_id_);
4860 Add(low_id_); 4783 Add(low_id_);
4861 Add(high_id_); 4784 Add(high_id_);
4862 SyncShareNudge(); 4785 SyncShareNudge();
4863 ExpectLocalOrderIsByServerId(); 4786 ExpectLocalOrderIsByServerId();
4864 } 4787 }
4865 4788
4866 } // namespace syncer 4789 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698