OLD | NEW |
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 syncable::ReadTransaction trans(FROM_HERE, directory()); | 249 syncable::ReadTransaction trans(FROM_HERE, directory()); |
250 syncable::Directory::ChildHandles children; | 250 syncable::Directory::ChildHandles children; |
251 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); | 251 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); |
252 ASSERT_EQ(0u, children.size()); | 252 ASSERT_EQ(0u, children.size()); |
253 saw_syncer_event_ = false; | 253 saw_syncer_event_ = false; |
254 root_id_ = TestIdFactory::root(); | 254 root_id_ = TestIdFactory::root(); |
255 parent_id_ = ids_.MakeServer("parent id"); | 255 parent_id_ = ids_.MakeServer("parent id"); |
256 child_id_ = ids_.MakeServer("child id"); | 256 child_id_ = ids_.MakeServer("child id"); |
257 directory()->set_store_birthday(mock_server_->store_birthday()); | 257 directory()->set_store_birthday(mock_server_->store_birthday()); |
258 mock_server_->SetKeystoreKey("encryption_key"); | 258 mock_server_->SetKeystoreKey("encryption_key"); |
259 GetCryptographer(&trans)->SetNigoriHandler(&fake_encryption_handler_); | |
260 } | 259 } |
261 | 260 |
262 virtual void TearDown() { | 261 virtual void TearDown() { |
263 mock_server_.reset(); | 262 mock_server_.reset(); |
264 delete syncer_; | 263 delete syncer_; |
265 syncer_ = NULL; | 264 syncer_ = NULL; |
266 dir_maker_.TearDown(); | 265 dir_maker_.TearDown(); |
267 } | 266 } |
268 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { | 267 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { |
269 EXPECT_FALSE(entry->Get(IS_DIR)); | 268 EXPECT_FALSE(entry->Get(IS_DIR)); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 scoped_ptr<SyncSessionContext> context_; | 560 scoped_ptr<SyncSessionContext> context_; |
562 bool saw_syncer_event_; | 561 bool saw_syncer_event_; |
563 base::TimeDelta last_short_poll_interval_received_; | 562 base::TimeDelta last_short_poll_interval_received_; |
564 base::TimeDelta last_long_poll_interval_received_; | 563 base::TimeDelta last_long_poll_interval_received_; |
565 base::TimeDelta last_sessions_commit_delay_seconds_; | 564 base::TimeDelta last_sessions_commit_delay_seconds_; |
566 scoped_refptr<ModelSafeWorker> worker_; | 565 scoped_refptr<ModelSafeWorker> worker_; |
567 | 566 |
568 ModelTypeSet enabled_datatypes_; | 567 ModelTypeSet enabled_datatypes_; |
569 TrafficRecorder traffic_recorder_; | 568 TrafficRecorder traffic_recorder_; |
570 | 569 |
571 FakeSyncEncryptionHandler fake_encryption_handler_; | |
572 | |
573 DISALLOW_COPY_AND_ASSIGN(SyncerTest); | 570 DISALLOW_COPY_AND_ASSIGN(SyncerTest); |
574 }; | 571 }; |
575 | 572 |
576 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { | 573 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { |
577 { | 574 { |
578 Syncer::UnsyncedMetaHandles handles; | 575 Syncer::UnsyncedMetaHandles handles; |
579 { | 576 { |
580 syncable::ReadTransaction trans(FROM_HERE, directory()); | 577 syncable::ReadTransaction trans(FROM_HERE, directory()); |
581 GetUnsyncedEntries(&trans, &handles); | 578 GetUnsyncedEntries(&trans, &handles); |
582 } | 579 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); | 717 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); |
721 { | 718 { |
722 // Mark bookmarks as encrypted and set the cryptographer to have pending | 719 // Mark bookmarks as encrypted and set the cryptographer to have pending |
723 // keys. | 720 // keys. |
724 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 721 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
725 Cryptographer other_cryptographer(&encryptor_); | 722 Cryptographer other_cryptographer(&encryptor_); |
726 other_cryptographer.AddKey(other_params); | 723 other_cryptographer.AddKey(other_params); |
727 sync_pb::EntitySpecifics specifics; | 724 sync_pb::EntitySpecifics specifics; |
728 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 725 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
729 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 726 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
730 fake_encryption_handler_.EnableEncryptEverything(); | 727 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
731 // Set up with an old passphrase, but have pending keys | 728 // Set up with an old passphrase, but have pending keys |
732 GetCryptographer(&wtrans)->AddKey(key_params); | 729 GetCryptographer(&wtrans)->AddKey(key_params); |
733 GetCryptographer(&wtrans)->Encrypt(bookmark, | 730 GetCryptographer(&wtrans)->Encrypt(bookmark, |
734 encrypted_bookmark.mutable_encrypted()); | 731 encrypted_bookmark.mutable_encrypted()); |
735 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encrypted()); | 732 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encrypted()); |
736 | 733 |
737 // In conflict but properly encrypted. | 734 // In conflict but properly encrypted. |
738 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 735 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
739 ASSERT_TRUE(A.good()); | 736 ASSERT_TRUE(A.good()); |
740 A.Put(IS_UNSYNCED, true); | 737 A.Put(IS_UNSYNCED, true); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 modified_pref.mutable_preference()->set_name("name2"); | 830 modified_pref.mutable_preference()->set_name("name2"); |
834 other_cryptographer.Encrypt(modified_pref, | 831 other_cryptographer.Encrypt(modified_pref, |
835 modified_pref.mutable_encrypted()); | 832 modified_pref.mutable_encrypted()); |
836 { | 833 { |
837 // Mark bookmarks and preferences as encrypted and set the cryptographer to | 834 // Mark bookmarks and preferences as encrypted and set the cryptographer to |
838 // have pending keys. | 835 // have pending keys. |
839 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 836 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
840 sync_pb::EntitySpecifics specifics; | 837 sync_pb::EntitySpecifics specifics; |
841 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 838 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
842 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 839 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
843 fake_encryption_handler_.EnableEncryptEverything(); | 840 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
844 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encrypted()); | 841 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encrypted()); |
845 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); | 842 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); |
846 } | 843 } |
847 | 844 |
848 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); | 845 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); |
849 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); | 846 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); |
850 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); | 847 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); |
851 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); | 848 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); |
852 SyncShareNudge(); | 849 SyncShareNudge(); |
853 { | 850 { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 // Local changes with different passphrase, different types. | 1008 // Local changes with different passphrase, different types. |
1012 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1009 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1013 sync_pb::EntitySpecifics specifics; | 1010 sync_pb::EntitySpecifics specifics; |
1014 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1011 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
1015 GetCryptographer(&wtrans)->AddKey(local_key_params); | 1012 GetCryptographer(&wtrans)->AddKey(local_key_params); |
1016 GetCryptographer(&wtrans)->Encrypt( | 1013 GetCryptographer(&wtrans)->Encrypt( |
1017 our_encrypted_specifics, | 1014 our_encrypted_specifics, |
1018 our_encrypted_specifics.mutable_encrypted()); | 1015 our_encrypted_specifics.mutable_encrypted()); |
1019 GetCryptographer(&wtrans)->GetKeys( | 1016 GetCryptographer(&wtrans)->GetKeys( |
1020 nigori->mutable_encrypted()); | 1017 nigori->mutable_encrypted()); |
1021 fake_encryption_handler_.EnableEncryptEverything(); | 1018 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
1022 GetCryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes( | 1019 directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( |
1023 nigori, | 1020 nigori, |
1024 &wtrans); | 1021 &wtrans); |
1025 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1022 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
1026 ModelTypeToRootTag(NIGORI)); | 1023 ModelTypeToRootTag(NIGORI)); |
1027 ASSERT_TRUE(nigori_entry.good()); | 1024 ASSERT_TRUE(nigori_entry.good()); |
1028 nigori_entry.Put(SPECIFICS, specifics); | 1025 nigori_entry.Put(SPECIFICS, specifics); |
1029 nigori_entry.Put(IS_UNSYNCED, true); | 1026 nigori_entry.Put(IS_UNSYNCED, true); |
1030 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); | 1027 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); |
1031 EXPECT_TRUE(encrypted_types.Equals( | 1028 EXPECT_TRUE(encrypted_types.Equals( |
1032 GetCryptographer(&wtrans)->GetEncryptedTypes())); | 1029 directory()->GetNigoriHandler()->GetEncryptedTypes(&wtrans))); |
1033 fake_encryption_handler_.set_cryptographer(GetCryptographer(&wtrans)); | |
1034 } | 1030 } |
1035 { | 1031 { |
1036 sync_pb::EntitySpecifics specifics; | 1032 sync_pb::EntitySpecifics specifics; |
1037 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1033 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
1038 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 1034 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
1039 nigori->set_encrypt_bookmarks(true); | 1035 nigori->set_encrypt_bookmarks(true); |
1040 nigori->set_encrypt_preferences(true); | 1036 nigori->set_encrypt_preferences(true); |
1041 nigori->set_encrypt_everything(false); | 1037 nigori->set_encrypt_everything(false); |
1042 nigori->set_using_explicit_passphrase(true); | 1038 nigori->set_using_explicit_passphrase(true); |
1043 mock_server_->SetNigori(1, 20, 20, specifics); | 1039 mock_server_->SetNigori(1, 20, 20, specifics); |
(...skipping 10 matching lines...) Expand all Loading... |
1054 // Ensure the nigori data merged (encrypted types). | 1050 // Ensure the nigori data merged (encrypted types). |
1055 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1051 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1056 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1052 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
1057 ModelTypeToRootTag(NIGORI)); | 1053 ModelTypeToRootTag(NIGORI)); |
1058 ASSERT_TRUE(nigori_entry.good()); | 1054 ASSERT_TRUE(nigori_entry.good()); |
1059 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | 1055 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
1060 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | 1056 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
1061 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); | 1057 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); |
1062 ASSERT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); | 1058 ASSERT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); |
1063 EXPECT_TRUE(encrypted_types.Equals( | 1059 EXPECT_TRUE(encrypted_types.Equals( |
1064 GetCryptographer(&wtrans)->GetEncryptedTypes())); | 1060 directory()->GetNigoriHandler()->GetEncryptedTypes(&wtrans))); |
1065 EXPECT_TRUE(fake_encryption_handler_.EncryptEverythingEnabled()); | 1061 EXPECT_TRUE(dir_maker_.encryption_handler()->EncryptEverythingEnabled()); |
1066 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); | 1062 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); |
1067 // Supply the pending keys. Afterwards, we should be able to decrypt both | 1063 // Supply the pending keys. Afterwards, we should be able to decrypt both |
1068 // our own encrypted data and data encrypted by the other cryptographer, | 1064 // our own encrypted data and data encrypted by the other cryptographer, |
1069 // but the key provided by the other cryptographer should be the default. | 1065 // but the key provided by the other cryptographer should be the default. |
1070 EXPECT_TRUE( | 1066 EXPECT_TRUE( |
1071 GetCryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); | 1067 GetCryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); |
1072 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); | 1068 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); |
1073 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1069 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
1074 GetCryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted()); | 1070 GetCryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted()); |
1075 GetCryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori, &wtrans); | 1071 directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( |
| 1072 nigori, |
| 1073 &wtrans); |
1076 // 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 |
1077 // manually for the test. | 1075 // manually for the test. |
1078 nigori_entry.Put(SPECIFICS, specifics); | 1076 nigori_entry.Put(SPECIFICS, specifics); |
1079 nigori_entry.Put(IS_UNSYNCED, true); | 1077 nigori_entry.Put(IS_UNSYNCED, true); |
1080 } | 1078 } |
1081 | 1079 |
1082 SyncShareNudge(); | 1080 SyncShareNudge(); |
1083 { | 1081 { |
1084 // Ensure everything is committed and stable now. The cryptographer | 1082 // Ensure everything is committed and stable now. The cryptographer |
1085 // should be able to decrypt both sets of keys, and the encrypted types | 1083 // 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 Loading... |
4781 | 4779 |
4782 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4780 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
4783 Add(mid_id_); | 4781 Add(mid_id_); |
4784 Add(low_id_); | 4782 Add(low_id_); |
4785 Add(high_id_); | 4783 Add(high_id_); |
4786 SyncShareNudge(); | 4784 SyncShareNudge(); |
4787 ExpectLocalOrderIsByServerId(); | 4785 ExpectLocalOrderIsByServerId(); |
4788 } | 4786 } |
4789 | 4787 |
4790 } // namespace syncer | 4788 } // namespace syncer |
OLD | NEW |