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

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: Fix 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/conflict_resolver.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 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 GetCryptographer(&trans)->SetNigoriHandler(&fake_encryption_handler_);
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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 526 }
525 527
526 bool Get(int64 metahandle, syncable::IsDelField field) { 528 bool Get(int64 metahandle, syncable::IsDelField field) {
527 return GetField(metahandle, field, false); 529 return GetField(metahandle, field, false);
528 } 530 }
529 531
530 bool Get(int64 metahandle, syncable::BitField field) { 532 bool Get(int64 metahandle, syncable::BitField field) {
531 return GetField(metahandle, field, false); 533 return GetField(metahandle, field, false);
532 } 534 }
533 535
534 Cryptographer* cryptographer(syncable::BaseTransaction* trans) { 536 Cryptographer* GetCryptographer(syncable::BaseTransaction* trans) {
535 return directory()->GetCryptographer(trans); 537 return directory()->GetCryptographer(trans);
536 } 538 }
537 539
538 MessageLoop message_loop_; 540 MessageLoop message_loop_;
539 541
540 // Some ids to aid tests. Only the root one's value is specific. The rest 542 // Some ids to aid tests. Only the root one's value is specific. The rest
541 // are named for test clarity. 543 // are named for test clarity.
542 // TODO(chron): Get rid of these inbuilt IDs. They only make it 544 // TODO(chron): Get rid of these inbuilt IDs. They only make it
543 // more confusing. 545 // more confusing.
544 syncable::Id root_id_; 546 syncable::Id root_id_;
(...skipping 14 matching lines...) Expand all
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 GetCryptographer(&wtrans)->AddKey(key_params);
729 cryptographer(&wtrans)->Encrypt(bookmark, 733 GetCryptographer(&wtrans)->Encrypt(bookmark,
730 encrypted_bookmark.mutable_encrypted()); 734 encrypted_bookmark.mutable_encrypted());
731 cryptographer(&wtrans)->Update(*nigori); 735 GetCryptographer(&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 17 matching lines...) Expand all
759 // Nothing should have commited due to bookmarks being encrypted and 763 // Nothing should have commited due to bookmarks being encrypted and
760 // the cryptographer having pending keys. A would have been resolved 764 // the cryptographer having pending keys. A would have been resolved
761 // as a simple conflict, but still be unsynced until the next sync cycle. 765 // as a simple conflict, but still be unsynced until the next sync cycle.
762 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 766 syncable::ReadTransaction rtrans(FROM_HERE, directory());
763 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans); 767 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans);
764 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans); 768 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans);
765 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 769 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
766 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 770 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
767 771
768 // Resolve the pending keys. 772 // Resolve the pending keys.
769 cryptographer(&rtrans)->DecryptPendingKeys(other_params); 773 GetCryptographer(&rtrans)->DecryptPendingKeys(other_params);
770 } 774 }
771 SyncShareNudge(); 775 SyncShareNudge();
772 { 776 {
773 // All properly encrypted and non-conflicting items should commit. "A" was 777 // All properly encrypted and non-conflicting items should commit. "A" was
774 // conflicting, but last sync cycle resolved it as simple conflict, so on 778 // conflicting, but last sync cycle resolved it as simple conflict, so on
775 // this sync cycle it committed succesfullly. 779 // this sync cycle it committed succesfullly.
776 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 780 syncable::ReadTransaction rtrans(FROM_HERE, directory());
777 // Committed successfully. 781 // Committed successfully.
778 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 782 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
779 // Committed successfully. 783 // Committed successfully.
(...skipping 49 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 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encrypted());
841 cryptographer(&wtrans)->Update(*nigori); 845 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys());
842 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.
852 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 855 syncable::ReadTransaction rtrans(FROM_HERE, directory());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 949 syncable::ReadTransaction rtrans(FROM_HERE, directory());
947 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans); 950 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans);
948 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans); 951 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans);
949 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans); 952 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans);
950 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); 953 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans);
951 } 954 }
952 955
953 { 956 {
954 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 957 syncable::ReadTransaction rtrans(FROM_HERE, directory());
955 // Resolve the pending keys. 958 // Resolve the pending keys.
956 cryptographer(&rtrans)->DecryptPendingKeys(key_params); 959 GetCryptographer(&rtrans)->DecryptPendingKeys(key_params);
957 } 960 }
958 // First cycle resolves conflicts, second cycle commits changes. 961 // First cycle resolves conflicts, second cycle commits changes.
959 SyncShareNudge(); 962 SyncShareNudge();
960 EXPECT_EQ(2, status().model_neutral_state().num_server_overwrites); 963 EXPECT_EQ(2, status().model_neutral_state().num_server_overwrites);
961 EXPECT_EQ(1, status().model_neutral_state().num_local_overwrites); 964 EXPECT_EQ(1, status().model_neutral_state().num_local_overwrites);
962 // We successfully commited item(s). 965 // We successfully commited item(s).
963 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK); 966 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK);
964 SyncShareNudge(); 967 SyncShareNudge();
965 968
966 // Everything should be resolved now. The local changes should have 969 // Everything should be resolved now. The local changes should have
967 // overwritten the server changes for 2 and 4, while the server changes 970 // overwritten the server changes for 2 and 4, while the server changes
968 // overwrote the local for entry 3. 971 // overwrote the local for entry 3.
969 EXPECT_EQ(0, status().model_neutral_state().num_server_overwrites); 972 EXPECT_EQ(0, status().model_neutral_state().num_server_overwrites);
970 EXPECT_EQ(0, status().model_neutral_state().num_local_overwrites); 973 EXPECT_EQ(0, status().model_neutral_state().num_local_overwrites);
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 11 matching lines...) Expand all
1085 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); 1005 our_encrypted_specifics.mutable_bookmark()->set_title("title2");
1086 1006
1087 // Receive the initial nigori node. 1007 // Receive the initial nigori node.
1088 SyncShareNudge(); 1008 SyncShareNudge();
1089 encrypted_types = ModelTypeSet::All(); 1009 encrypted_types = ModelTypeSet::All();
1090 { 1010 {
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 GetCryptographer(&wtrans)->AddKey(local_key_params);
1096 cryptographer(&wtrans)->Encrypt( 1016 GetCryptographer(&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 GetCryptographer(&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 GetCryptographer(&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(GetCryptographer(&wtrans)->has_pending_keys());
1109 EXPECT_TRUE(encrypted_types.Equals( 1031 EXPECT_TRUE(encrypted_types.Equals(
1110 cryptographer(&wtrans)->GetEncryptedTypes())); 1032 GetCryptographer(&wtrans)->GetEncryptedTypes()));
1033 fake_encryption_handler_.set_cryptographer(GetCryptographer(&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(GetCryptographer(&wtrans)->has_pending_keys());
1140 EXPECT_TRUE(encrypted_types.Equals( 1063 EXPECT_TRUE(encrypted_types.Equals(
1141 cryptographer(&wtrans)->GetEncryptedTypes())); 1064 GetCryptographer(&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(
1148 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 1071 GetCryptographer(&wtrans)->DecryptPendingKeys(other_key_params));
1072 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys());
1149 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1073 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1150 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted()); 1074 GetCryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted());
1151 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 1075 GetCryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori, &wtrans);
1152 // Normally this would be written as part of SetPassphrase, but we do it 1076 // Normally this would be written as part of SetPassphrase, but we do it
1153 // manually for the test. 1077 // manually for the test.
1154 nigori_entry.Put(SPECIFICS, specifics); 1078 nigori_entry.Put(SPECIFICS, specifics);
1155 nigori_entry.Put(IS_UNSYNCED, true); 1079 nigori_entry.Put(IS_UNSYNCED, true);
1156 } 1080 }
1157 1081
1158 SyncShareNudge(); 1082 SyncShareNudge();
1159 { 1083 {
1160 // Ensure everything is committed and stable now. The cryptographer 1084 // Ensure everything is committed and stable now. The cryptographer
1161 // should be able to decrypt both sets of keys, and the encrypted types 1085 // should be able to decrypt both sets of keys, and the encrypted types
1162 // should have been unioned. 1086 // should have been unioned.
1163 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1087 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1164 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1088 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1165 ModelTypeToRootTag(NIGORI)); 1089 ModelTypeToRootTag(NIGORI));
1166 ASSERT_TRUE(nigori_entry.good()); 1090 ASSERT_TRUE(nigori_entry.good());
1167 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); 1091 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
1168 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); 1092 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED));
1169 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt( 1093 EXPECT_TRUE(GetCryptographer(&wtrans)->CanDecrypt(
1170 our_encrypted_specifics.encrypted())); 1094 our_encrypted_specifics.encrypted()));
1171 EXPECT_FALSE(cryptographer(&wtrans)-> 1095 EXPECT_FALSE(GetCryptographer(&wtrans)->
1172 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); 1096 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted()));
1173 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt( 1097 EXPECT_TRUE(GetCryptographer(&wtrans)->CanDecrypt(
1174 other_encrypted_specifics.encrypted())); 1098 other_encrypted_specifics.encrypted()));
1175 EXPECT_TRUE(cryptographer(&wtrans)-> 1099 EXPECT_TRUE(GetCryptographer(&wtrans)->
1176 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); 1100 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted()));
1177 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).nigori(). 1101 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).nigori().
1178 using_explicit_passphrase()); 1102 using_explicit_passphrase());
1179 } 1103 }
1180 } 1104 }
1181 1105
1182 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { 1106 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) {
1183 { 1107 {
1184 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1108 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1185 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 1109 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(),
(...skipping 2979 matching lines...) Expand 10 before | Expand all | Expand 10 after
4165 4089
4166 // One update remains undownloaded. 4090 // One update remains undownloaded.
4167 mock_server_->ClearUpdatesQueue(); 4091 mock_server_->ClearUpdatesQueue();
4168 4092
4169 EXPECT_FALSE(initial_sync_ended_for_type(BOOKMARKS)); 4093 EXPECT_FALSE(initial_sync_ended_for_type(BOOKMARKS));
4170 } 4094 }
4171 4095
4172 TEST_F(SyncerTest, GetKeySuccess) { 4096 TEST_F(SyncerTest, GetKeySuccess) {
4173 { 4097 {
4174 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 4098 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4175 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey()); 4099 EXPECT_FALSE(GetCryptographer(&rtrans)->HasKeystoreKey());
4176 } 4100 }
4177 4101
4178 SyncShareConfigure(); 4102 SyncShareConfigure();
4179 4103
4180 EXPECT_EQ(session_->status_controller().last_get_key_result(), SYNCER_OK); 4104 EXPECT_EQ(session_->status_controller().last_get_key_result(), SYNCER_OK);
4181 { 4105 {
4182 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 4106 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4183 EXPECT_TRUE(cryptographer(&rtrans)->HasKeystoreKey()); 4107 EXPECT_TRUE(GetCryptographer(&rtrans)->HasKeystoreKey());
4184 } 4108 }
4185 } 4109 }
4186 4110
4187 TEST_F(SyncerTest, GetKeyEmpty) { 4111 TEST_F(SyncerTest, GetKeyEmpty) {
4188 { 4112 {
4189 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 4113 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4190 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey()); 4114 EXPECT_FALSE(GetCryptographer(&rtrans)->HasKeystoreKey());
4191 } 4115 }
4192 4116
4193 mock_server_->SetKeystoreKey(""); 4117 mock_server_->SetKeystoreKey("");
4194 SyncShareConfigure(); 4118 SyncShareConfigure();
4195 4119
4196 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK); 4120 EXPECT_NE(session_->status_controller().last_get_key_result(), SYNCER_OK);
4197 { 4121 {
4198 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 4122 syncable::ReadTransaction rtrans(FROM_HERE, directory());
4199 EXPECT_FALSE(cryptographer(&rtrans)->HasKeystoreKey()); 4123 EXPECT_FALSE(GetCryptographer(&rtrans)->HasKeystoreKey());
4200 } 4124 }
4201 } 4125 }
4202 4126
4203 // Test what happens if a client deletes, then recreates, an object very 4127 // Test what happens if a client deletes, then recreates, an object very
4204 // quickly. It is possible that the deletion gets sent as a commit, and 4128 // quickly. It is possible that the deletion gets sent as a commit, and
4205 // the undelete happens during the commit request. The principle here 4129 // the undelete happens during the commit request. The principle here
4206 // is that with a single committing client, conflicts should never 4130 // is that with a single committing client, conflicts should never
4207 // be encountered, and a client encountering its past actions during 4131 // be encountered, and a client encountering its past actions during
4208 // getupdates should never feed back to override later actions. 4132 // getupdates should never feed back to override later actions.
4209 // 4133 //
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
4857 4781
4858 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4782 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4859 Add(mid_id_); 4783 Add(mid_id_);
4860 Add(low_id_); 4784 Add(low_id_);
4861 Add(high_id_); 4785 Add(high_id_);
4862 SyncShareNudge(); 4786 SyncShareNudge();
4863 ExpectLocalOrderIsByServerId(); 4787 ExpectLocalOrderIsByServerId();
4864 } 4788 }
4865 4789
4866 } // namespace syncer 4790 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/conflict_resolver.cc ('k') | sync/engine/syncer_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698