| 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
| 6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
| 7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "sync/internal_api/public/engine/model_safe_worker.h" | 29 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 30 #include "sync/internal_api/public/engine/polling_constants.h" | 30 #include "sync/internal_api/public/engine/polling_constants.h" |
| 31 #include "sync/internal_api/public/http_post_provider_factory.h" | 31 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 32 #include "sync/internal_api/public/http_post_provider_interface.h" | 32 #include "sync/internal_api/public/http_post_provider_interface.h" |
| 33 #include "sync/internal_api/public/read_node.h" | 33 #include "sync/internal_api/public/read_node.h" |
| 34 #include "sync/internal_api/public/read_transaction.h" | 34 #include "sync/internal_api/public/read_transaction.h" |
| 35 #include "sync/internal_api/public/test/test_internal_components_factory.h" | 35 #include "sync/internal_api/public/test/test_internal_components_factory.h" |
| 36 #include "sync/internal_api/public/test/test_user_share.h" | 36 #include "sync/internal_api/public/test/test_user_share.h" |
| 37 #include "sync/internal_api/public/write_node.h" | 37 #include "sync/internal_api/public/write_node.h" |
| 38 #include "sync/internal_api/public/write_transaction.h" | 38 #include "sync/internal_api/public/write_transaction.h" |
| 39 #include "sync/internal_api/sync_encryption_handler_impl.h" |
| 39 #include "sync/internal_api/sync_manager_impl.h" | 40 #include "sync/internal_api/sync_manager_impl.h" |
| 40 #include "sync/internal_api/syncapi_internal.h" | 41 #include "sync/internal_api/syncapi_internal.h" |
| 41 #include "sync/js/js_arg_list.h" | 42 #include "sync/js/js_arg_list.h" |
| 42 #include "sync/js/js_backend.h" | 43 #include "sync/js/js_backend.h" |
| 43 #include "sync/js/js_event_handler.h" | 44 #include "sync/js/js_event_handler.h" |
| 44 #include "sync/js/js_reply_handler.h" | 45 #include "sync/js/js_reply_handler.h" |
| 45 #include "sync/js/js_test_util.h" | 46 #include "sync/js/js_test_util.h" |
| 46 #include "sync/notifier/sync_notifier.h" | 47 #include "sync/notifier/sync_notifier.h" |
| 47 #include "sync/notifier/sync_notifier_observer.h" | 48 #include "sync/notifier/sync_notifier_observer.h" |
| 48 #include "sync/protocol/bookmark_specifics.pb.h" | 49 #include "sync/protocol/bookmark_specifics.pb.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 70 #include "testing/gmock/include/gmock/gmock.h" | 71 #include "testing/gmock/include/gmock/gmock.h" |
| 71 #include "testing/gtest/include/gtest/gtest.h" | 72 #include "testing/gtest/include/gtest/gtest.h" |
| 72 | 73 |
| 73 using base::ExpectDictStringValue; | 74 using base::ExpectDictStringValue; |
| 74 using testing::_; | 75 using testing::_; |
| 75 using testing::AnyNumber; | 76 using testing::AnyNumber; |
| 76 using testing::AtLeast; | 77 using testing::AtLeast; |
| 77 using testing::DoAll; | 78 using testing::DoAll; |
| 78 using testing::InSequence; | 79 using testing::InSequence; |
| 79 using testing::Invoke; | 80 using testing::Invoke; |
| 81 using testing::NiceMock; |
| 80 using testing::Return; | 82 using testing::Return; |
| 81 using testing::SaveArg; | 83 using testing::SaveArg; |
| 82 using testing::StrictMock; | 84 using testing::StrictMock; |
| 83 | 85 |
| 84 namespace syncer { | 86 namespace syncer { |
| 85 | 87 |
| 86 using sessions::SyncSessionSnapshot; | 88 using sessions::SyncSessionSnapshot; |
| 87 using syncable::IS_DEL; | 89 using syncable::IS_DEL; |
| 88 using syncable::IS_UNSYNCED; | 90 using syncable::IS_UNSYNCED; |
| 89 using syncable::kEncryptedString; | 91 using syncable::kEncryptedString; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 entry.Put(syncable::SPECIFICS, specifics); | 220 entry.Put(syncable::SPECIFICS, specifics); |
| 219 return entry.Get(syncable::META_HANDLE); | 221 return entry.Get(syncable::META_HANDLE); |
| 220 } | 222 } |
| 221 | 223 |
| 222 } // namespace | 224 } // namespace |
| 223 | 225 |
| 224 class SyncApiTest : public testing::Test { | 226 class SyncApiTest : public testing::Test { |
| 225 public: | 227 public: |
| 226 virtual void SetUp() { | 228 virtual void SetUp() { |
| 227 test_user_share_.SetUp(); | 229 test_user_share_.SetUp(); |
| 230 SetUpEncryption(); |
| 228 } | 231 } |
| 229 | 232 |
| 230 virtual void TearDown() { | 233 virtual void TearDown() { |
| 231 test_user_share_.TearDown(); | 234 test_user_share_.TearDown(); |
| 232 } | 235 } |
| 233 | 236 |
| 237 void SetUpEncryption() { |
| 238 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 239 encryption_handler_.reset( |
| 240 new SyncEncryptionHandlerImpl(test_user_share_.user_share(), |
| 241 trans.GetCryptographer())); |
| 242 trans.GetCryptographer()->SetNigoriHandler(encryption_handler_.get()); |
| 243 } |
| 244 |
| 234 protected: | 245 protected: |
| 235 MessageLoop message_loop_; | 246 MessageLoop message_loop_; |
| 236 TestUserShare test_user_share_; | 247 TestUserShare test_user_share_; |
| 248 scoped_ptr<SyncEncryptionHandlerImpl> encryption_handler_; |
| 237 }; | 249 }; |
| 238 | 250 |
| 239 TEST_F(SyncApiTest, SanityCheckTest) { | 251 TEST_F(SyncApiTest, SanityCheckTest) { |
| 240 { | 252 { |
| 241 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 253 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 242 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); | 254 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); |
| 243 } | 255 } |
| 244 { | 256 { |
| 245 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 257 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 246 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); | 258 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 password_node.GetPasswordSpecifics(); | 477 password_node.GetPasswordSpecifics(); |
| 466 EXPECT_EQ("secret", data.password_value()); | 478 EXPECT_EQ("secret", data.password_value()); |
| 467 } | 479 } |
| 468 } | 480 } |
| 469 | 481 |
| 470 TEST_F(SyncApiTest, WriteEncryptedTitle) { | 482 TEST_F(SyncApiTest, WriteEncryptedTitle) { |
| 471 KeyParams params = {"localhost", "username", "passphrase"}; | 483 KeyParams params = {"localhost", "username", "passphrase"}; |
| 472 { | 484 { |
| 473 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 485 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 474 trans.GetCryptographer()->AddKey(params); | 486 trans.GetCryptographer()->AddKey(params); |
| 475 trans.GetCryptographer()->set_encrypt_everything(); | |
| 476 } | 487 } |
| 488 encryption_handler_->EnableEncryptEverything(); |
| 477 { | 489 { |
| 478 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 490 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 479 ReadNode root_node(&trans); | 491 ReadNode root_node(&trans); |
| 480 root_node.InitByRootLookup(); | 492 root_node.InitByRootLookup(); |
| 481 | 493 |
| 482 WriteNode bookmark_node(&trans); | 494 WriteNode bookmark_node(&trans); |
| 483 WriteNode::InitUniqueByCreationResult result = | 495 WriteNode::InitUniqueByCreationResult result = |
| 484 bookmark_node.InitUniqueByCreation(BOOKMARKS, | 496 bookmark_node.InitUniqueByCreation(BOOKMARKS, |
| 485 root_node, "foo"); | 497 root_node, "foo"); |
| 486 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 498 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 }; | 685 }; |
| 674 | 686 |
| 675 class SyncManagerObserverMock : public SyncManager::Observer { | 687 class SyncManagerObserverMock : public SyncManager::Observer { |
| 676 public: | 688 public: |
| 677 MOCK_METHOD1(OnSyncCycleCompleted, | 689 MOCK_METHOD1(OnSyncCycleCompleted, |
| 678 void(const SyncSessionSnapshot&)); // NOLINT | 690 void(const SyncSessionSnapshot&)); // NOLINT |
| 679 MOCK_METHOD3(OnInitializationComplete, | 691 MOCK_METHOD3(OnInitializationComplete, |
| 680 void(const WeakHandle<JsBackend>&, bool, | 692 void(const WeakHandle<JsBackend>&, bool, |
| 681 syncer::ModelTypeSet)); // NOLINT | 693 syncer::ModelTypeSet)); // NOLINT |
| 682 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT | 694 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT |
| 695 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT |
| 696 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT |
| 697 MOCK_METHOD1(OnActionableError, |
| 698 void(const SyncProtocolError&)); // NOLINT |
| 699 }; |
| 700 |
| 701 class SyncEncryptionHandlerObserverMock |
| 702 : public SyncEncryptionHandler::Observer { |
| 703 public: |
| 683 MOCK_METHOD2(OnPassphraseRequired, | 704 MOCK_METHOD2(OnPassphraseRequired, |
| 684 void(PassphraseRequiredReason, | 705 void(PassphraseRequiredReason, |
| 685 const sync_pb::EncryptedData&)); // NOLINT | 706 const sync_pb::EncryptedData&)); // NOLINT |
| 686 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT | 707 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT |
| 687 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT | 708 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT |
| 688 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT | |
| 689 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT | |
| 690 MOCK_METHOD2(OnEncryptedTypesChanged, | 709 MOCK_METHOD2(OnEncryptedTypesChanged, |
| 691 void(ModelTypeSet, bool)); // NOLINT | 710 void(ModelTypeSet, bool)); // NOLINT |
| 692 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT | 711 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT |
| 693 MOCK_METHOD1(OnActionableError, | 712 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT |
| 694 void(const SyncProtocolError&)); // NOLINT | |
| 695 }; | 713 }; |
| 696 | 714 |
| 697 class SyncNotifierMock : public SyncNotifier { | 715 class SyncNotifierMock : public SyncNotifier { |
| 698 public: | 716 public: |
| 699 MOCK_METHOD1(RegisterHandler, void(SyncNotifierObserver*)); | 717 MOCK_METHOD1(RegisterHandler, void(SyncNotifierObserver*)); |
| 700 MOCK_METHOD2(UpdateRegisteredIds, | 718 MOCK_METHOD2(UpdateRegisteredIds, |
| 701 void(SyncNotifierObserver*, const ObjectIdSet&)); | 719 void(SyncNotifierObserver*, const ObjectIdSet&)); |
| 702 MOCK_METHOD1(UnregisterHandler, void(SyncNotifierObserver*)); | 720 MOCK_METHOD1(UnregisterHandler, void(SyncNotifierObserver*)); |
| 703 MOCK_METHOD1(SetUniqueId, void(const std::string&)); | 721 MOCK_METHOD1(SetUniqueId, void(const std::string&)); |
| 704 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); | 722 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); | 763 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); |
| 746 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); | 764 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); |
| 747 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); | 765 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); |
| 748 EXPECT_CALL(*sync_notifier_mock_, | 766 EXPECT_CALL(*sync_notifier_mock_, |
| 749 UpdateCredentials(credentials.email, credentials.sync_token)); | 767 UpdateCredentials(credentials.email, credentials.sync_token)); |
| 750 EXPECT_CALL(*sync_notifier_mock_, RegisterHandler(_)); | 768 EXPECT_CALL(*sync_notifier_mock_, RegisterHandler(_)); |
| 751 | 769 |
| 752 // Called by ShutdownOnSyncThread(). | 770 // Called by ShutdownOnSyncThread(). |
| 753 EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(_)); | 771 EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(_)); |
| 754 | 772 |
| 755 sync_manager_.AddObserver(&observer_); | 773 sync_manager_.AddObserver(&manager_observer_); |
| 756 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). | 774 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _)). |
| 757 WillOnce(SaveArg<0>(&js_backend_)); | 775 WillOnce(SaveArg<0>(&js_backend_)); |
| 758 | 776 |
| 759 EXPECT_FALSE(js_backend_.IsInitialized()); | 777 EXPECT_FALSE(js_backend_.IsInitialized()); |
| 760 | 778 |
| 761 std::vector<ModelSafeWorker*> workers; | 779 std::vector<ModelSafeWorker*> workers; |
| 762 ModelSafeRoutingInfo routing_info; | 780 ModelSafeRoutingInfo routing_info; |
| 763 GetModelSafeRoutingInfo(&routing_info); | 781 GetModelSafeRoutingInfo(&routing_info); |
| 764 | 782 |
| 765 // Takes ownership of |sync_notifier_mock_|. | 783 // Takes ownership of |sync_notifier_mock_|. |
| 766 sync_manager_.Init(temp_dir_.path(), | 784 sync_manager_.Init(temp_dir_.path(), |
| 767 WeakHandle<JsEventHandler>(), | 785 WeakHandle<JsEventHandler>(), |
| 768 "bogus", 0, false, | 786 "bogus", 0, false, |
| 769 base::MessageLoopProxy::current(), | 787 base::MessageLoopProxy::current(), |
| 770 scoped_ptr<HttpPostProviderFactory>( | 788 scoped_ptr<HttpPostProviderFactory>( |
| 771 new TestHttpPostProviderFactory()), | 789 new TestHttpPostProviderFactory()), |
| 772 workers, &extensions_activity_monitor_, this, | 790 workers, &extensions_activity_monitor_, this, |
| 773 credentials, | 791 credentials, |
| 774 scoped_ptr<SyncNotifier>(sync_notifier_mock_), | 792 scoped_ptr<SyncNotifier>(sync_notifier_mock_), |
| 775 "", "", // bootstrap tokens | 793 "", "", // bootstrap tokens |
| 776 scoped_ptr<InternalComponentsFactory>(GetFactory()), | 794 scoped_ptr<InternalComponentsFactory>(GetFactory()), |
| 777 &encryptor_, | 795 &encryptor_, |
| 778 &handler_, | 796 &handler_, |
| 779 NULL); | 797 NULL); |
| 780 | 798 |
| 799 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
| 800 |
| 781 EXPECT_TRUE(js_backend_.IsInitialized()); | 801 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 782 | 802 |
| 783 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 803 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 784 i != routing_info.end(); ++i) { | 804 i != routing_info.end(); ++i) { |
| 785 type_roots_[i->first] = MakeServerNodeForType( | 805 type_roots_[i->first] = MakeServerNodeForType( |
| 786 sync_manager_.GetUserShare(), i->first); | 806 sync_manager_.GetUserShare(), i->first); |
| 787 } | 807 } |
| 788 PumpLoop(); | 808 PumpLoop(); |
| 789 } | 809 } |
| 790 | 810 |
| 791 void TearDown() { | 811 void TearDown() { |
| 792 sync_manager_.RemoveObserver(&observer_); | 812 sync_manager_.RemoveObserver(&manager_observer_); |
| 793 // |sync_notifier_mock_| is strict, which ensures we don't do anything but | 813 // |sync_notifier_mock_| is strict, which ensures we don't do anything but |
| 794 // unregister |sync_manager_| as a handler on shutdown. | 814 // unregister |sync_manager_| as a handler on shutdown. |
| 795 sync_manager_.ShutdownOnSyncThread(); | 815 sync_manager_.ShutdownOnSyncThread(); |
| 796 sync_notifier_mock_ = NULL; | 816 sync_notifier_mock_ = NULL; |
| 797 PumpLoop(); | 817 PumpLoop(); |
| 798 } | 818 } |
| 799 | 819 |
| 800 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 820 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 801 (*out)[NIGORI] = GROUP_PASSIVE; | 821 (*out)[NIGORI] = GROUP_PASSIVE; |
| 802 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 822 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 818 EncryptionStatus encryption_status) { | 838 EncryptionStatus encryption_status) { |
| 819 UserShare* share = sync_manager_.GetUserShare(); | 839 UserShare* share = sync_manager_.GetUserShare(); |
| 820 share->directory->set_initial_sync_ended_for_type(NIGORI, true); | 840 share->directory->set_initial_sync_ended_for_type(NIGORI, true); |
| 821 | 841 |
| 822 // We need to create the nigori node as if it were an applied server update. | 842 // We need to create the nigori node as if it were an applied server update. |
| 823 int64 nigori_id = GetIdForDataType(NIGORI); | 843 int64 nigori_id = GetIdForDataType(NIGORI); |
| 824 if (nigori_id == kInvalidId) | 844 if (nigori_id == kInvalidId) |
| 825 return false; | 845 return false; |
| 826 | 846 |
| 827 // Set the nigori cryptographer information. | 847 // Set the nigori cryptographer information. |
| 848 if (encryption_status == FULL_ENCRYPTION) |
| 849 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 850 |
| 828 WriteTransaction trans(FROM_HERE, share); | 851 WriteTransaction trans(FROM_HERE, share); |
| 829 Cryptographer* cryptographer = trans.GetCryptographer(); | 852 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 830 if (!cryptographer) | 853 if (!cryptographer) |
| 831 return false; | 854 return false; |
| 832 if (encryption_status != UNINITIALIZED) { | 855 if (encryption_status != UNINITIALIZED) { |
| 833 KeyParams params = {"localhost", "dummy", "foobar"}; | 856 KeyParams params = {"localhost", "dummy", "foobar"}; |
| 834 cryptographer->AddKey(params); | 857 cryptographer->AddKey(params); |
| 835 } else { | 858 } else { |
| 836 DCHECK_NE(nigori_status, WRITE_TO_NIGORI); | 859 DCHECK_NE(nigori_status, WRITE_TO_NIGORI); |
| 837 } | 860 } |
| 838 if (encryption_status == FULL_ENCRYPTION) | |
| 839 cryptographer->set_encrypt_everything(); | |
| 840 if (nigori_status == WRITE_TO_NIGORI) { | 861 if (nigori_status == WRITE_TO_NIGORI) { |
| 841 sync_pb::NigoriSpecifics nigori; | 862 sync_pb::NigoriSpecifics nigori; |
| 842 cryptographer->GetKeys(nigori.mutable_encrypted()); | 863 cryptographer->GetKeys(nigori.mutable_encrypted()); |
| 843 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); | 864 cryptographer->UpdateNigoriFromEncryptedTypes( |
| 865 &nigori, |
| 866 trans.GetWrappedTrans()); |
| 844 WriteNode node(&trans); | 867 WriteNode node(&trans); |
| 845 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id)); | 868 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id)); |
| 846 node.SetNigoriSpecifics(nigori); | 869 node.SetNigoriSpecifics(nigori); |
| 847 } | 870 } |
| 848 return cryptographer->is_ready(); | 871 return cryptographer->is_ready(); |
| 849 } | 872 } |
| 850 | 873 |
| 851 int64 GetIdForDataType(ModelType type) { | 874 int64 GetIdForDataType(ModelType type) { |
| 852 if (type_roots_.count(type) == 0) | 875 if (type_roots_.count(type) == 0) |
| 853 return 0; | 876 return 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 return true; | 912 return true; |
| 890 } | 913 } |
| 891 | 914 |
| 892 virtual InternalComponentsFactory* GetFactory() { | 915 virtual InternalComponentsFactory* GetFactory() { |
| 893 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_IN_MEMORY); | 916 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_IN_MEMORY); |
| 894 } | 917 } |
| 895 | 918 |
| 896 // Returns true if we are currently encrypting all sync data. May | 919 // Returns true if we are currently encrypting all sync data. May |
| 897 // be called on any thread. | 920 // be called on any thread. |
| 898 bool EncryptEverythingEnabledForTest() { | 921 bool EncryptEverythingEnabledForTest() { |
| 899 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 922 return sync_manager_.GetEncryptionHandler()->EncryptEverythingEnabled(); |
| 900 return trans.GetCryptographer()->encrypt_everything(); | |
| 901 } | 923 } |
| 902 | 924 |
| 903 // Gets the set of encrypted types from the cryptographer | 925 // Gets the set of encrypted types from the cryptographer |
| 904 // Note: opens a transaction. May be called from any thread. | 926 // Note: opens a transaction. May be called from any thread. |
| 905 syncer::ModelTypeSet GetEncryptedDataTypesForTest() { | 927 syncer::ModelTypeSet GetEncryptedDataTypesForTest() { |
| 906 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 928 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 907 return GetEncryptedTypes(&trans); | 929 return GetEncryptedTypes(&trans); |
| 908 } | 930 } |
| 909 | 931 |
| 910 void SimulateEnableNotificationsForTest() { | 932 void SimulateEnableNotificationsForTest() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 // Sync Id's for the roots of the enabled datatypes. | 977 // Sync Id's for the roots of the enabled datatypes. |
| 956 std::map<ModelType, int64> type_roots_; | 978 std::map<ModelType, int64> type_roots_; |
| 957 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 979 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 958 | 980 |
| 959 protected: | 981 protected: |
| 960 FakeEncryptor encryptor_; | 982 FakeEncryptor encryptor_; |
| 961 TestUnrecoverableErrorHandler handler_; | 983 TestUnrecoverableErrorHandler handler_; |
| 962 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 984 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
| 963 SyncManagerImpl sync_manager_; | 985 SyncManagerImpl sync_manager_; |
| 964 WeakHandle<JsBackend> js_backend_; | 986 WeakHandle<JsBackend> js_backend_; |
| 965 StrictMock<SyncManagerObserverMock> observer_; | 987 StrictMock<SyncManagerObserverMock> manager_observer_; |
| 988 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; |
| 966 InternalComponentsFactory::Switches switches_; | 989 InternalComponentsFactory::Switches switches_; |
| 967 }; | 990 }; |
| 968 | 991 |
| 969 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 992 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
| 970 ModelSafeRoutingInfo routes; | 993 ModelSafeRoutingInfo routes; |
| 971 GetModelSafeRoutingInfo(&routes); | 994 GetModelSafeRoutingInfo(&routes); |
| 972 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | 995 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); |
| 973 EXPECT_CALL(*sync_notifier_mock_, | 996 EXPECT_CALL(*sync_notifier_mock_, |
| 974 UpdateRegisteredIds( | 997 UpdateRegisteredIds( |
| 975 _, ModelTypeSetToObjectIdSet(enabled_types))); | 998 _, ModelTypeSetToObjectIdSet(enabled_types))); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 | 1370 |
| 1348 TriggerOnIncomingNotificationForTest(empty_model_types); | 1371 TriggerOnIncomingNotificationForTest(empty_model_types); |
| 1349 TriggerOnIncomingNotificationForTest(model_types); | 1372 TriggerOnIncomingNotificationForTest(model_types); |
| 1350 | 1373 |
| 1351 // Should trigger the replies. | 1374 // Should trigger the replies. |
| 1352 PumpLoop(); | 1375 PumpLoop(); |
| 1353 } | 1376 } |
| 1354 | 1377 |
| 1355 TEST_F(SyncManagerTest, RefreshEncryptionReady) { | 1378 TEST_F(SyncManagerTest, RefreshEncryptionReady) { |
| 1356 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1379 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1357 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1380 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1381 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1358 | 1382 |
| 1359 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 1383 sync_manager_.GetEncryptionHandler()->Init(); |
| 1360 PumpLoop(); | 1384 PumpLoop(); |
| 1361 | 1385 |
| 1362 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); | 1386 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); |
| 1363 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); | 1387 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); |
| 1364 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1388 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1365 | 1389 |
| 1366 { | 1390 { |
| 1367 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1391 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1368 ReadNode node(&trans); | 1392 ReadNode node(&trans); |
| 1369 EXPECT_EQ(BaseNode::INIT_OK, | 1393 EXPECT_EQ(BaseNode::INIT_OK, |
| 1370 node.InitByIdLookup(GetIdForDataType(NIGORI))); | 1394 node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 1371 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1395 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1372 EXPECT_TRUE(nigori.has_encrypted()); | 1396 EXPECT_TRUE(nigori.has_encrypted()); |
| 1373 Cryptographer* cryptographer = trans.GetCryptographer(); | 1397 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1374 EXPECT_TRUE(cryptographer->is_ready()); | 1398 EXPECT_TRUE(cryptographer->is_ready()); |
| 1375 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1399 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); |
| 1376 } | 1400 } |
| 1377 } | 1401 } |
| 1378 | 1402 |
| 1379 // Attempt to refresh encryption when nigori not downloaded. | 1403 // Attempt to refresh encryption when nigori not downloaded. |
| 1380 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { | 1404 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { |
| 1381 // Don't set up encryption (no nigori node created). | 1405 // Don't set up encryption (no nigori node created). |
| 1382 | 1406 |
| 1383 // Should fail. | 1407 // Should fail. Triggers an OnPassphraseRequired because the cryptographer |
| 1384 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 1408 // is not ready. |
| 1409 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)).Times(1); |
| 1410 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1411 sync_manager_.GetEncryptionHandler()->Init(); |
| 1385 PumpLoop(); | 1412 PumpLoop(); |
| 1386 | 1413 |
| 1387 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); | 1414 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); |
| 1388 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. | 1415 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. |
| 1389 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1416 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1390 } | 1417 } |
| 1391 | 1418 |
| 1392 // Attempt to refresh encryption when nigori is empty. | 1419 // Attempt to refresh encryption when nigori is empty. |
| 1393 TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) { | 1420 TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) { |
| 1394 EXPECT_TRUE(SetUpEncryption(DONT_WRITE_NIGORI, DEFAULT_ENCRYPTION)); | 1421 EXPECT_TRUE(SetUpEncryption(DONT_WRITE_NIGORI, DEFAULT_ENCRYPTION)); |
| 1395 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1422 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(1); |
| 1423 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1396 | 1424 |
| 1397 // Should write to nigori. | 1425 // Should write to nigori. |
| 1398 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 1426 sync_manager_.GetEncryptionHandler()->Init(); |
| 1399 PumpLoop(); | 1427 PumpLoop(); |
| 1400 | 1428 |
| 1401 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); | 1429 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); |
| 1402 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. | 1430 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. |
| 1403 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1431 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1404 | 1432 |
| 1405 { | 1433 { |
| 1406 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1434 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1407 ReadNode node(&trans); | 1435 ReadNode node(&trans); |
| 1408 EXPECT_EQ(BaseNode::INIT_OK, | 1436 EXPECT_EQ(BaseNode::INIT_OK, |
| 1409 node.InitByIdLookup(GetIdForDataType(NIGORI))); | 1437 node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 1410 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1438 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1411 EXPECT_TRUE(nigori.has_encrypted()); | 1439 EXPECT_TRUE(nigori.has_encrypted()); |
| 1412 Cryptographer* cryptographer = trans.GetCryptographer(); | 1440 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1413 EXPECT_TRUE(cryptographer->is_ready()); | 1441 EXPECT_TRUE(cryptographer->is_ready()); |
| 1414 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1442 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); |
| 1415 } | 1443 } |
| 1416 } | 1444 } |
| 1417 | 1445 |
| 1418 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { | 1446 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { |
| 1419 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1447 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1420 EXPECT_CALL(observer_, | 1448 EXPECT_CALL(encryption_observer_, |
| 1421 OnEncryptedTypesChanged( | 1449 OnEncryptedTypesChanged( |
| 1422 HasModelTypes(ModelTypeSet::All()), true)); | 1450 HasModelTypes(ModelTypeSet::All()), true)); |
| 1423 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1451 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1424 sync_manager_.EnableEncryptEverything(); | 1452 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1425 EXPECT_TRUE(EncryptEverythingEnabledForTest()); | 1453 EXPECT_TRUE(EncryptEverythingEnabledForTest()); |
| 1426 } | 1454 } |
| 1427 | 1455 |
| 1428 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { | 1456 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { |
| 1429 size_t batch_size = 5; | 1457 size_t batch_size = 5; |
| 1430 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1458 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1431 | 1459 |
| 1432 // Create some unencrypted unsynced data. | 1460 // Create some unencrypted unsynced data. |
| 1433 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), | 1461 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), |
| 1434 BOOKMARKS, | 1462 BOOKMARKS, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1449 // Last batch_size nodes are a third type that will not need encryption. | 1477 // Last batch_size nodes are a third type that will not need encryption. |
| 1450 for (; i < 3*batch_size; ++i) { | 1478 for (; i < 3*batch_size; ++i) { |
| 1451 MakeNodeWithParent(sync_manager_.GetUserShare(), THEMES, | 1479 MakeNodeWithParent(sync_manager_.GetUserShare(), THEMES, |
| 1452 base::StringPrintf("%"PRIuS"", i), | 1480 base::StringPrintf("%"PRIuS"", i), |
| 1453 GetIdForDataType(THEMES)); | 1481 GetIdForDataType(THEMES)); |
| 1454 } | 1482 } |
| 1455 | 1483 |
| 1456 { | 1484 { |
| 1457 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1485 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1458 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( | 1486 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( |
| 1459 Cryptographer::SensitiveTypes())); | 1487 SyncEncryptionHandler::SensitiveTypes())); |
| 1460 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1488 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1461 trans.GetWrappedTrans(), | 1489 trans.GetWrappedTrans(), |
| 1462 trans.GetCryptographer(), | 1490 trans.GetCryptographer(), |
| 1463 BOOKMARKS, | 1491 BOOKMARKS, |
| 1464 false /* not encrypted */)); | 1492 false /* not encrypted */)); |
| 1465 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1493 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1466 trans.GetWrappedTrans(), | 1494 trans.GetWrappedTrans(), |
| 1467 trans.GetCryptographer(), | 1495 trans.GetCryptographer(), |
| 1468 SESSIONS, | 1496 SESSIONS, |
| 1469 false /* not encrypted */)); | 1497 false /* not encrypted */)); |
| 1470 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1498 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1471 trans.GetWrappedTrans(), | 1499 trans.GetWrappedTrans(), |
| 1472 trans.GetCryptographer(), | 1500 trans.GetCryptographer(), |
| 1473 THEMES, | 1501 THEMES, |
| 1474 false /* not encrypted */)); | 1502 false /* not encrypted */)); |
| 1475 } | 1503 } |
| 1476 | 1504 |
| 1477 EXPECT_CALL(observer_, | 1505 EXPECT_CALL(encryption_observer_, |
| 1478 OnEncryptedTypesChanged( | 1506 OnEncryptedTypesChanged( |
| 1479 HasModelTypes(ModelTypeSet::All()), true)); | 1507 HasModelTypes(ModelTypeSet::All()), true)); |
| 1480 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1508 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1481 sync_manager_.EnableEncryptEverything(); | 1509 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1482 EXPECT_TRUE(EncryptEverythingEnabledForTest()); | 1510 EXPECT_TRUE(EncryptEverythingEnabledForTest()); |
| 1483 { | 1511 { |
| 1484 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1512 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1485 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( | 1513 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( |
| 1486 ModelTypeSet::All())); | 1514 ModelTypeSet::All())); |
| 1487 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1515 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1488 trans.GetWrappedTrans(), | 1516 trans.GetWrappedTrans(), |
| 1489 trans.GetCryptographer(), | 1517 trans.GetCryptographer(), |
| 1490 BOOKMARKS, | 1518 BOOKMARKS, |
| 1491 true /* is encrypted */)); | 1519 true /* is encrypted */)); |
| 1492 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1520 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1493 trans.GetWrappedTrans(), | 1521 trans.GetWrappedTrans(), |
| 1494 trans.GetCryptographer(), | 1522 trans.GetCryptographer(), |
| 1495 SESSIONS, | 1523 SESSIONS, |
| 1496 true /* is encrypted */)); | 1524 true /* is encrypted */)); |
| 1497 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1525 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1498 trans.GetWrappedTrans(), | 1526 trans.GetWrappedTrans(), |
| 1499 trans.GetCryptographer(), | 1527 trans.GetCryptographer(), |
| 1500 THEMES, | 1528 THEMES, |
| 1501 true /* is encrypted */)); | 1529 true /* is encrypted */)); |
| 1502 } | 1530 } |
| 1503 | 1531 |
| 1504 // Trigger's a ReEncryptEverything with new passphrase. | 1532 // Trigger's a ReEncryptEverything with new passphrase. |
| 1505 testing::Mock::VerifyAndClearExpectations(&observer_); | 1533 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1506 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1534 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1507 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1535 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1508 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1536 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1509 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 1537 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1538 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1539 "new_passphrase", true); |
| 1510 EXPECT_TRUE(EncryptEverythingEnabledForTest()); | 1540 EXPECT_TRUE(EncryptEverythingEnabledForTest()); |
| 1511 { | 1541 { |
| 1512 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1542 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1513 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All())); | 1543 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All())); |
| 1514 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1544 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1515 trans.GetWrappedTrans(), | 1545 trans.GetWrappedTrans(), |
| 1516 trans.GetCryptographer(), | 1546 trans.GetCryptographer(), |
| 1517 BOOKMARKS, | 1547 BOOKMARKS, |
| 1518 true /* is encrypted */)); | 1548 true /* is encrypted */)); |
| 1519 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1549 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1520 trans.GetWrappedTrans(), | 1550 trans.GetWrappedTrans(), |
| 1521 trans.GetCryptographer(), | 1551 trans.GetCryptographer(), |
| 1522 SESSIONS, | 1552 SESSIONS, |
| 1523 true /* is encrypted */)); | 1553 true /* is encrypted */)); |
| 1524 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1554 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1525 trans.GetWrappedTrans(), | 1555 trans.GetWrappedTrans(), |
| 1526 trans.GetCryptographer(), | 1556 trans.GetCryptographer(), |
| 1527 THEMES, | 1557 THEMES, |
| 1528 true /* is encrypted */)); | 1558 true /* is encrypted */)); |
| 1529 } | 1559 } |
| 1530 // Calling EncryptDataTypes with an empty encrypted types should not trigger | 1560 // Calling EncryptDataTypes with an empty encrypted types should not trigger |
| 1531 // a reencryption and should just notify immediately. | 1561 // a reencryption and should just notify immediately. |
| 1532 // TODO(zea): add logic to ensure nothing was written. | 1562 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1533 testing::Mock::VerifyAndClearExpectations(&observer_); | 1563 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)).Times(0); |
| 1534 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)).Times(0); | 1564 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()).Times(0); |
| 1535 EXPECT_CALL(observer_, OnPassphraseAccepted()).Times(0); | 1565 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(0); |
| 1536 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1566 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1537 sync_manager_.EnableEncryptEverything(); | |
| 1538 } | 1567 } |
| 1539 | 1568 |
| 1540 // Test that when there are no pending keys and the cryptographer is not | 1569 // Test that when there are no pending keys and the cryptographer is not |
| 1541 // initialized, we add a key based on the current GAIA password. | 1570 // initialized, we add a key based on the current GAIA password. |
| 1542 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) | 1571 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) |
| 1543 TEST_F(SyncManagerTest, SetInitialGaiaPass) { | 1572 TEST_F(SyncManagerTest, SetInitialGaiaPass) { |
| 1544 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); | 1573 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); |
| 1545 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1574 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1546 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1575 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1547 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1576 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1548 sync_manager_.SetEncryptionPassphrase("new_passphrase", false); | 1577 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1578 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1579 "new_passphrase", |
| 1580 false); |
| 1581 EXPECT_FALSE( |
| 1582 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1549 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1583 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1550 { | 1584 { |
| 1551 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1585 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1552 ReadNode node(&trans); | 1586 ReadNode node(&trans); |
| 1553 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1587 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1554 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1588 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1555 Cryptographer* cryptographer = trans.GetCryptographer(); | 1589 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1556 EXPECT_TRUE(cryptographer->is_ready()); | 1590 EXPECT_TRUE(cryptographer->is_ready()); |
| 1557 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1591 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); |
| 1558 } | 1592 } |
| 1559 } | 1593 } |
| 1560 | 1594 |
| 1561 // Test that when there are no pending keys and we have on the old GAIA | 1595 // Test that when there are no pending keys and we have on the old GAIA |
| 1562 // password, we update and re-encrypt everything with the new GAIA password. | 1596 // password, we update and re-encrypt everything with the new GAIA password. |
| 1563 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) | 1597 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) |
| 1564 TEST_F(SyncManagerTest, UpdateGaiaPass) { | 1598 TEST_F(SyncManagerTest, UpdateGaiaPass) { |
| 1565 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1599 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1566 Cryptographer verifier(&encryptor_); | 1600 Cryptographer verifier(&encryptor_); |
| 1567 { | 1601 { |
| 1568 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1602 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1569 Cryptographer* cryptographer = trans.GetCryptographer(); | 1603 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1570 std::string bootstrap_token; | 1604 std::string bootstrap_token; |
| 1571 cryptographer->GetBootstrapToken(&bootstrap_token); | 1605 cryptographer->GetBootstrapToken(&bootstrap_token); |
| 1572 verifier.Bootstrap(bootstrap_token); | 1606 verifier.Bootstrap(bootstrap_token); |
| 1573 } | 1607 } |
| 1574 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1608 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1575 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1609 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1576 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1610 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1577 sync_manager_.SetEncryptionPassphrase("new_passphrase", false); | 1611 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1612 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1613 "new_passphrase", |
| 1614 false); |
| 1615 EXPECT_FALSE( |
| 1616 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1578 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1617 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1579 { | 1618 { |
| 1580 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1619 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1581 Cryptographer* cryptographer = trans.GetCryptographer(); | 1620 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1582 EXPECT_TRUE(cryptographer->is_ready()); | 1621 EXPECT_TRUE(cryptographer->is_ready()); |
| 1583 // Verify the default key has changed. | 1622 // Verify the default key has changed. |
| 1584 sync_pb::EncryptedData encrypted; | 1623 sync_pb::EncryptedData encrypted; |
| 1585 cryptographer->GetKeys(&encrypted); | 1624 cryptographer->GetKeys(&encrypted); |
| 1586 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); | 1625 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); |
| 1587 } | 1626 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1606 | 1645 |
| 1607 WriteNode password_node(&trans); | 1646 WriteNode password_node(&trans); |
| 1608 WriteNode::InitUniqueByCreationResult result = | 1647 WriteNode::InitUniqueByCreationResult result = |
| 1609 password_node.InitUniqueByCreation(PASSWORDS, | 1648 password_node.InitUniqueByCreation(PASSWORDS, |
| 1610 root_node, "foo"); | 1649 root_node, "foo"); |
| 1611 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 1650 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 1612 sync_pb::PasswordSpecificsData data; | 1651 sync_pb::PasswordSpecificsData data; |
| 1613 data.set_password_value("secret"); | 1652 data.set_password_value("secret"); |
| 1614 password_node.SetPasswordSpecifics(data); | 1653 password_node.SetPasswordSpecifics(data); |
| 1615 } | 1654 } |
| 1616 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1655 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1617 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1656 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1618 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1657 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1619 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 1658 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1659 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1660 "new_passphrase", |
| 1661 true); |
| 1662 EXPECT_TRUE( |
| 1663 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1620 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1664 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1621 { | 1665 { |
| 1622 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1666 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1623 Cryptographer* cryptographer = trans.GetCryptographer(); | 1667 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1624 EXPECT_TRUE(cryptographer->is_ready()); | 1668 EXPECT_TRUE(cryptographer->is_ready()); |
| 1625 // Verify the default key has changed. | 1669 // Verify the default key has changed. |
| 1626 sync_pb::EncryptedData encrypted; | 1670 sync_pb::EncryptedData encrypted; |
| 1627 cryptographer->GetKeys(&encrypted); | 1671 cryptographer->GetKeys(&encrypted); |
| 1628 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); | 1672 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); |
| 1629 | 1673 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1652 other_cryptographer.Bootstrap(bootstrap_token); | 1696 other_cryptographer.Bootstrap(bootstrap_token); |
| 1653 | 1697 |
| 1654 // Now update the nigori to reflect the new keys, and update the | 1698 // Now update the nigori to reflect the new keys, and update the |
| 1655 // cryptographer to have pending keys. | 1699 // cryptographer to have pending keys. |
| 1656 KeyParams params = {"localhost", "dummy", "passphrase2"}; | 1700 KeyParams params = {"localhost", "dummy", "passphrase2"}; |
| 1657 other_cryptographer.AddKey(params); | 1701 other_cryptographer.AddKey(params); |
| 1658 WriteNode node(&trans); | 1702 WriteNode node(&trans); |
| 1659 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1703 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1660 sync_pb::NigoriSpecifics nigori; | 1704 sync_pb::NigoriSpecifics nigori; |
| 1661 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1705 other_cryptographer.GetKeys(nigori.mutable_encrypted()); |
| 1662 cryptographer->Update(nigori); | 1706 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1663 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1707 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1664 node.SetNigoriSpecifics(nigori); | 1708 node.SetNigoriSpecifics(nigori); |
| 1665 } | 1709 } |
| 1666 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1710 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1667 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1711 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1668 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1712 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1669 sync_manager_.SetDecryptionPassphrase("passphrase2"); | 1713 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1714 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); |
| 1715 EXPECT_FALSE( |
| 1716 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1670 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1717 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1671 { | 1718 { |
| 1672 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1719 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1673 Cryptographer* cryptographer = trans.GetCryptographer(); | 1720 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1674 EXPECT_TRUE(cryptographer->is_ready()); | 1721 EXPECT_TRUE(cryptographer->is_ready()); |
| 1675 // Verify we're encrypting with the new key. | 1722 // Verify we're encrypting with the new key. |
| 1676 sync_pb::EncryptedData encrypted; | 1723 sync_pb::EncryptedData encrypted; |
| 1677 cryptographer->GetKeys(&encrypted); | 1724 cryptographer->GetKeys(&encrypted); |
| 1678 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1725 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| 1679 } | 1726 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1697 | 1744 |
| 1698 // Now update the nigori to reflect the new keys, and update the | 1745 // Now update the nigori to reflect the new keys, and update the |
| 1699 // cryptographer to have pending keys. | 1746 // cryptographer to have pending keys. |
| 1700 KeyParams params = {"localhost", "dummy", "old_gaia"}; | 1747 KeyParams params = {"localhost", "dummy", "old_gaia"}; |
| 1701 other_cryptographer.AddKey(params); | 1748 other_cryptographer.AddKey(params); |
| 1702 WriteNode node(&trans); | 1749 WriteNode node(&trans); |
| 1703 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1750 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1704 sync_pb::NigoriSpecifics nigori; | 1751 sync_pb::NigoriSpecifics nigori; |
| 1705 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1752 other_cryptographer.GetKeys(nigori.mutable_encrypted()); |
| 1706 node.SetNigoriSpecifics(nigori); | 1753 node.SetNigoriSpecifics(nigori); |
| 1707 cryptographer->Update(nigori); | 1754 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1708 | 1755 |
| 1709 // other_cryptographer now contains all encryption keys, and is encrypting | 1756 // other_cryptographer now contains all encryption keys, and is encrypting |
| 1710 // with the newest gaia. | 1757 // with the newest gaia. |
| 1711 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; | 1758 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; |
| 1712 other_cryptographer.AddKey(new_params); | 1759 other_cryptographer.AddKey(new_params); |
| 1713 } | 1760 } |
| 1714 // The bootstrap token should have been updated. Save it to ensure it's based | 1761 // The bootstrap token should have been updated. Save it to ensure it's based |
| 1715 // on the new GAIA password. | 1762 // on the new GAIA password. |
| 1716 std::string bootstrap_token; | 1763 std::string bootstrap_token; |
| 1717 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)) | 1764 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)) |
| 1718 .WillOnce(SaveArg<0>(&bootstrap_token)); | 1765 .WillOnce(SaveArg<0>(&bootstrap_token)); |
| 1719 EXPECT_CALL(observer_, OnPassphraseRequired(_,_)); | 1766 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); |
| 1720 sync_manager_.SetEncryptionPassphrase("new_gaia", false); | 1767 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1768 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1769 "new_gaia", |
| 1770 false); |
| 1771 EXPECT_FALSE( |
| 1772 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1721 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1773 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1722 testing::Mock::VerifyAndClearExpectations(&observer_); | 1774 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1723 { | 1775 { |
| 1724 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1776 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1725 Cryptographer* cryptographer = trans.GetCryptographer(); | 1777 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1726 EXPECT_TRUE(cryptographer->is_initialized()); | 1778 EXPECT_TRUE(cryptographer->is_initialized()); |
| 1727 EXPECT_FALSE(cryptographer->is_ready()); | 1779 EXPECT_FALSE(cryptographer->is_ready()); |
| 1728 // Verify we're encrypting with the new key, even though we have pending | 1780 // Verify we're encrypting with the new key, even though we have pending |
| 1729 // keys. | 1781 // keys. |
| 1730 sync_pb::EncryptedData encrypted; | 1782 sync_pb::EncryptedData encrypted; |
| 1731 other_cryptographer.GetKeys(&encrypted); | 1783 other_cryptographer.GetKeys(&encrypted); |
| 1732 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); | 1784 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); |
| 1733 } | 1785 } |
| 1734 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1786 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1735 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1787 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1736 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1788 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1737 sync_manager_.SetEncryptionPassphrase("old_gaia", false); | 1789 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1790 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1791 "old_gaia", |
| 1792 false); |
| 1793 EXPECT_FALSE( |
| 1794 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1738 { | 1795 { |
| 1739 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1796 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1740 Cryptographer* cryptographer = trans.GetCryptographer(); | 1797 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1741 EXPECT_TRUE(cryptographer->is_ready()); | 1798 EXPECT_TRUE(cryptographer->is_ready()); |
| 1742 | 1799 |
| 1743 // Verify we're encrypting with the new key. | 1800 // Verify we're encrypting with the new key. |
| 1744 sync_pb::EncryptedData encrypted; | 1801 sync_pb::EncryptedData encrypted; |
| 1745 other_cryptographer.GetKeys(&encrypted); | 1802 other_cryptographer.GetKeys(&encrypted); |
| 1746 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); | 1803 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); |
| 1747 | 1804 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1767 other_cryptographer.Bootstrap(bootstrap_token); | 1824 other_cryptographer.Bootstrap(bootstrap_token); |
| 1768 | 1825 |
| 1769 // Now update the nigori to reflect the new keys, and update the | 1826 // Now update the nigori to reflect the new keys, and update the |
| 1770 // cryptographer to have pending keys. | 1827 // cryptographer to have pending keys. |
| 1771 KeyParams params = {"localhost", "dummy", "explicit"}; | 1828 KeyParams params = {"localhost", "dummy", "explicit"}; |
| 1772 other_cryptographer.AddKey(params); | 1829 other_cryptographer.AddKey(params); |
| 1773 WriteNode node(&trans); | 1830 WriteNode node(&trans); |
| 1774 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1831 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1775 sync_pb::NigoriSpecifics nigori; | 1832 sync_pb::NigoriSpecifics nigori; |
| 1776 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1833 other_cryptographer.GetKeys(nigori.mutable_encrypted()); |
| 1777 cryptographer->Update(nigori); | 1834 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1778 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1835 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1779 nigori.set_using_explicit_passphrase(true); | 1836 nigori.set_using_explicit_passphrase(true); |
| 1780 node.SetNigoriSpecifics(nigori); | 1837 node.SetNigoriSpecifics(nigori); |
| 1781 } | 1838 } |
| 1782 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1839 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1783 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1840 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1784 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1841 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1785 sync_manager_.SetDecryptionPassphrase("explicit"); | 1842 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1843 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); |
| 1844 EXPECT_TRUE( |
| 1845 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1786 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1846 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1787 { | 1847 { |
| 1788 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1848 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1789 Cryptographer* cryptographer = trans.GetCryptographer(); | 1849 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1790 EXPECT_TRUE(cryptographer->is_ready()); | 1850 EXPECT_TRUE(cryptographer->is_ready()); |
| 1791 // Verify we're encrypting with the new key. | 1851 // Verify we're encrypting with the new key. |
| 1792 sync_pb::EncryptedData encrypted; | 1852 sync_pb::EncryptedData encrypted; |
| 1793 cryptographer->GetKeys(&encrypted); | 1853 cryptographer->GetKeys(&encrypted); |
| 1794 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1854 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| 1795 } | 1855 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1807 Cryptographer* cryptographer = trans.GetCryptographer(); | 1867 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1808 // Now update the nigori to reflect the new keys, and update the | 1868 // Now update the nigori to reflect the new keys, and update the |
| 1809 // cryptographer to have pending keys. | 1869 // cryptographer to have pending keys. |
| 1810 KeyParams params = {"localhost", "dummy", "passphrase"}; | 1870 KeyParams params = {"localhost", "dummy", "passphrase"}; |
| 1811 other_cryptographer.AddKey(params); | 1871 other_cryptographer.AddKey(params); |
| 1812 WriteNode node(&trans); | 1872 WriteNode node(&trans); |
| 1813 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1873 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1814 sync_pb::NigoriSpecifics nigori; | 1874 sync_pb::NigoriSpecifics nigori; |
| 1815 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1875 other_cryptographer.GetKeys(nigori.mutable_encrypted()); |
| 1816 node.SetNigoriSpecifics(nigori); | 1876 node.SetNigoriSpecifics(nigori); |
| 1817 cryptographer->Update(nigori); | 1877 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1818 EXPECT_FALSE(cryptographer->is_ready()); | 1878 EXPECT_FALSE(cryptographer->is_ready()); |
| 1819 } | 1879 } |
| 1820 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1880 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1821 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1881 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1822 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1882 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1823 sync_manager_.SetEncryptionPassphrase("passphrase", false); | 1883 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1884 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1885 "passphrase", |
| 1886 false); |
| 1887 EXPECT_FALSE( |
| 1888 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1824 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1889 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1825 { | 1890 { |
| 1826 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1891 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1827 Cryptographer* cryptographer = trans.GetCryptographer(); | 1892 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1828 EXPECT_TRUE(cryptographer->is_ready()); | 1893 EXPECT_TRUE(cryptographer->is_ready()); |
| 1829 } | 1894 } |
| 1830 } | 1895 } |
| 1831 | 1896 |
| 1832 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { | 1897 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { |
| 1833 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1898 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1834 int64 node_id = 0; | 1899 int64 node_id = 0; |
| 1835 std::string tag = "foo"; | 1900 std::string tag = "foo"; |
| 1836 { | 1901 { |
| 1837 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1902 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1838 ReadNode root_node(&trans); | 1903 ReadNode root_node(&trans); |
| 1839 root_node.InitByRootLookup(); | 1904 root_node.InitByRootLookup(); |
| 1840 | 1905 |
| 1841 WriteNode password_node(&trans); | 1906 WriteNode password_node(&trans); |
| 1842 WriteNode::InitUniqueByCreationResult result = | 1907 WriteNode::InitUniqueByCreationResult result = |
| 1843 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); | 1908 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); |
| 1844 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 1909 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 1845 node_id = password_node.GetId(); | 1910 node_id = password_node.GetId(); |
| 1846 } | 1911 } |
| 1847 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1912 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 1848 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1913 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1849 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1914 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1850 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 1915 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1916 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1917 "new_passphrase", |
| 1918 true); |
| 1919 EXPECT_TRUE( |
| 1920 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 1851 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1921 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1852 { | 1922 { |
| 1853 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1923 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1854 ReadNode password_node(&trans); | 1924 ReadNode password_node(&trans); |
| 1855 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, | 1925 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, |
| 1856 password_node.InitByClientTagLookup(PASSWORDS, | 1926 password_node.InitByClientTagLookup(PASSWORDS, |
| 1857 tag)); | 1927 tag)); |
| 1858 } | 1928 } |
| 1859 { | 1929 { |
| 1860 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1930 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1942 | 2012 |
| 1943 { | 2013 { |
| 1944 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2014 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1945 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 2015 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1946 trans.GetWrappedTrans(), | 2016 trans.GetWrappedTrans(), |
| 1947 trans.GetCryptographer(), | 2017 trans.GetCryptographer(), |
| 1948 BOOKMARKS, | 2018 BOOKMARKS, |
| 1949 false /* not encrypted */)); | 2019 false /* not encrypted */)); |
| 1950 } | 2020 } |
| 1951 | 2021 |
| 1952 EXPECT_CALL(observer_, | 2022 EXPECT_CALL(encryption_observer_, |
| 1953 OnEncryptedTypesChanged( | 2023 OnEncryptedTypesChanged( |
| 1954 HasModelTypes(ModelTypeSet::All()), true)); | 2024 HasModelTypes(ModelTypeSet::All()), true)); |
| 1955 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2025 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1956 sync_manager_.EnableEncryptEverything(); | 2026 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1957 EXPECT_TRUE(EncryptEverythingEnabledForTest()); | 2027 EXPECT_TRUE(EncryptEverythingEnabledForTest()); |
| 1958 | 2028 |
| 1959 { | 2029 { |
| 1960 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2030 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1961 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All())); | 2031 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All())); |
| 1962 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 2032 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1963 trans.GetWrappedTrans(), | 2033 trans.GetWrappedTrans(), |
| 1964 trans.GetCryptographer(), | 2034 trans.GetCryptographer(), |
| 1965 BOOKMARKS, | 2035 BOOKMARKS, |
| 1966 true /* is encrypted */)); | 2036 true /* is encrypted */)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 { | 2100 { |
| 2031 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2101 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2032 WriteNode node(&trans); | 2102 WriteNode node(&trans); |
| 2033 EXPECT_EQ(BaseNode::INIT_OK, | 2103 EXPECT_EQ(BaseNode::INIT_OK, |
| 2034 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2104 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2035 node.SetEntitySpecifics(entity_specifics); | 2105 node.SetEntitySpecifics(entity_specifics); |
| 2036 } | 2106 } |
| 2037 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2107 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2038 | 2108 |
| 2039 // Encrypt the datatatype, should set is_unsynced. | 2109 // Encrypt the datatatype, should set is_unsynced. |
| 2040 EXPECT_CALL(observer_, | 2110 EXPECT_CALL(encryption_observer_, |
| 2041 OnEncryptedTypesChanged( | 2111 OnEncryptedTypesChanged( |
| 2042 HasModelTypes(ModelTypeSet::All()), true)); | 2112 HasModelTypes(ModelTypeSet::All()), true)); |
| 2043 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2113 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2044 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2114 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2045 | 2115 |
| 2046 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2116 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2117 sync_manager_.GetEncryptionHandler()->Init(); |
| 2047 PumpLoop(); | 2118 PumpLoop(); |
| 2048 { | 2119 { |
| 2049 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2120 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2050 ReadNode node(&trans); | 2121 ReadNode node(&trans); |
| 2051 EXPECT_EQ(BaseNode::INIT_OK, | 2122 EXPECT_EQ(BaseNode::INIT_OK, |
| 2052 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2123 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2053 const syncable::Entry* node_entry = node.GetEntry(); | 2124 const syncable::Entry* node_entry = node.GetEntry(); |
| 2054 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2125 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2055 EXPECT_TRUE(specifics.has_encrypted()); | 2126 EXPECT_TRUE(specifics.has_encrypted()); |
| 2056 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2127 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2057 Cryptographer* cryptographer = trans.GetCryptographer(); | 2128 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2058 EXPECT_TRUE(cryptographer->is_ready()); | 2129 EXPECT_TRUE(cryptographer->is_ready()); |
| 2059 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2130 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2060 specifics.encrypted())); | 2131 specifics.encrypted())); |
| 2061 } | 2132 } |
| 2062 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2133 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2063 | 2134 |
| 2064 // Set a new passphrase. Should set is_unsynced. | 2135 // Set a new passphrase. Should set is_unsynced. |
| 2065 testing::Mock::VerifyAndClearExpectations(&observer_); | 2136 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2066 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 2137 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 2067 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 2138 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 2068 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2139 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2069 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 2140 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2141 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 2142 "new_passphrase", |
| 2143 true); |
| 2070 { | 2144 { |
| 2071 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2145 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2072 ReadNode node(&trans); | 2146 ReadNode node(&trans); |
| 2073 EXPECT_EQ(BaseNode::INIT_OK, | 2147 EXPECT_EQ(BaseNode::INIT_OK, |
| 2074 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2148 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2075 const syncable::Entry* node_entry = node.GetEntry(); | 2149 const syncable::Entry* node_entry = node.GetEntry(); |
| 2076 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2150 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2077 EXPECT_TRUE(specifics.has_encrypted()); | 2151 EXPECT_TRUE(specifics.has_encrypted()); |
| 2078 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2152 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2079 Cryptographer* cryptographer = trans.GetCryptographer(); | 2153 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2080 EXPECT_TRUE(cryptographer->is_ready()); | 2154 EXPECT_TRUE(cryptographer->is_ready()); |
| 2081 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2155 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2082 specifics.encrypted())); | 2156 specifics.encrypted())); |
| 2083 } | 2157 } |
| 2084 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2158 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2085 | 2159 |
| 2086 // Force a re-encrypt everything. Should not set is_unsynced. | 2160 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2087 testing::Mock::VerifyAndClearExpectations(&observer_); | 2161 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2088 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2162 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2163 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2089 | 2164 |
| 2090 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2165 sync_manager_.GetEncryptionHandler()->Init(); |
| 2091 PumpLoop(); | 2166 PumpLoop(); |
| 2092 | 2167 |
| 2093 { | 2168 { |
| 2094 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2169 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2095 ReadNode node(&trans); | 2170 ReadNode node(&trans); |
| 2096 EXPECT_EQ(BaseNode::INIT_OK, | 2171 EXPECT_EQ(BaseNode::INIT_OK, |
| 2097 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2172 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2098 const syncable::Entry* node_entry = node.GetEntry(); | 2173 const syncable::Entry* node_entry = node.GetEntry(); |
| 2099 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2174 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2100 EXPECT_TRUE(specifics.has_encrypted()); | 2175 EXPECT_TRUE(specifics.has_encrypted()); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2246 entity_specifics.mutable_password()->mutable_encrypted()); | 2321 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2247 } | 2322 } |
| 2248 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2323 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2249 BaseNode::GenerateSyncableHash(PASSWORDS, | 2324 BaseNode::GenerateSyncableHash(PASSWORDS, |
| 2250 client_tag), | 2325 client_tag), |
| 2251 entity_specifics); | 2326 entity_specifics); |
| 2252 // New node shouldn't start off unsynced. | 2327 // New node shouldn't start off unsynced. |
| 2253 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2328 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2254 | 2329 |
| 2255 // Set a new passphrase. Should set is_unsynced. | 2330 // Set a new passphrase. Should set is_unsynced. |
| 2256 testing::Mock::VerifyAndClearExpectations(&observer_); | 2331 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2257 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 2332 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); |
| 2258 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 2333 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 2259 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2334 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2260 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 2335 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2336 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 2337 "new_passphrase", |
| 2338 true); |
| 2339 EXPECT_TRUE( |
| 2340 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); |
| 2261 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2341 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2262 } | 2342 } |
| 2263 | 2343 |
| 2264 // Passwords have their own handling for encryption. Verify it does not result | 2344 // Passwords have their own handling for encryption. Verify it does not result |
| 2265 // in unnecessary writes via ReencryptEverything. | 2345 // in unnecessary writes via ReencryptEverything. |
| 2266 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { | 2346 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { |
| 2267 std::string client_tag = "title"; | 2347 std::string client_tag = "title"; |
| 2268 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2348 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2269 sync_pb::EntitySpecifics entity_specifics; | 2349 sync_pb::EntitySpecifics entity_specifics; |
| 2270 { | 2350 { |
| 2271 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2351 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2272 Cryptographer* cryptographer = trans.GetCryptographer(); | 2352 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2273 sync_pb::PasswordSpecificsData data; | 2353 sync_pb::PasswordSpecificsData data; |
| 2274 data.set_password_value("secret"); | 2354 data.set_password_value("secret"); |
| 2275 cryptographer->Encrypt( | 2355 cryptographer->Encrypt( |
| 2276 data, | 2356 data, |
| 2277 entity_specifics.mutable_password()->mutable_encrypted()); | 2357 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2278 } | 2358 } |
| 2279 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2359 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2280 BaseNode::GenerateSyncableHash(PASSWORDS, | 2360 BaseNode::GenerateSyncableHash(PASSWORDS, |
| 2281 client_tag), | 2361 client_tag), |
| 2282 entity_specifics); | 2362 entity_specifics); |
| 2283 // New node shouldn't start off unsynced. | 2363 // New node shouldn't start off unsynced. |
| 2284 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2364 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2285 | 2365 |
| 2286 // Force a re-encrypt everything. Should not set is_unsynced. | 2366 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2287 testing::Mock::VerifyAndClearExpectations(&observer_); | 2367 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2288 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2368 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2289 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2369 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2370 sync_manager_.GetEncryptionHandler()->Init(); |
| 2290 PumpLoop(); | 2371 PumpLoop(); |
| 2291 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2372 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2292 } | 2373 } |
| 2293 | 2374 |
| 2294 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks | 2375 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks |
| 2295 // when we write the same data, but does set it when we write new data. | 2376 // when we write the same data, but does set it when we write new data. |
| 2296 TEST_F(SyncManagerTest, SetBookmarkTitle) { | 2377 TEST_F(SyncManagerTest, SetBookmarkTitle) { |
| 2297 std::string client_tag = "title"; | 2378 std::string client_tag = "title"; |
| 2298 sync_pb::EntitySpecifics entity_specifics; | 2379 sync_pb::EntitySpecifics entity_specifics; |
| 2299 entity_specifics.mutable_bookmark()->set_url("url"); | 2380 entity_specifics.mutable_bookmark()->set_url("url"); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2335 entity_specifics.mutable_bookmark()->set_url("url"); | 2416 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2336 entity_specifics.mutable_bookmark()->set_title("title"); | 2417 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2337 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2418 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2338 BaseNode::GenerateSyncableHash(BOOKMARKS, | 2419 BaseNode::GenerateSyncableHash(BOOKMARKS, |
| 2339 client_tag), | 2420 client_tag), |
| 2340 entity_specifics); | 2421 entity_specifics); |
| 2341 // New node shouldn't start off unsynced. | 2422 // New node shouldn't start off unsynced. |
| 2342 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2423 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2343 | 2424 |
| 2344 // Encrypt the datatatype, should set is_unsynced. | 2425 // Encrypt the datatatype, should set is_unsynced. |
| 2345 EXPECT_CALL(observer_, | 2426 EXPECT_CALL(encryption_observer_, |
| 2346 OnEncryptedTypesChanged( | 2427 OnEncryptedTypesChanged( |
| 2347 HasModelTypes(ModelTypeSet::All()), true)); | 2428 HasModelTypes(ModelTypeSet::All()), true)); |
| 2348 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2429 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2349 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2430 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2350 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2431 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2432 sync_manager_.GetEncryptionHandler()->Init(); |
| 2351 PumpLoop(); | 2433 PumpLoop(); |
| 2352 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2434 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2353 | 2435 |
| 2354 // Manually change to the same title. Should not set is_unsynced. | 2436 // Manually change to the same title. Should not set is_unsynced. |
| 2355 // NON_UNIQUE_NAME should be kEncryptedString. | 2437 // NON_UNIQUE_NAME should be kEncryptedString. |
| 2356 { | 2438 { |
| 2357 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2439 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2358 WriteNode node(&trans); | 2440 WriteNode node(&trans); |
| 2359 EXPECT_EQ(BaseNode::INIT_OK, | 2441 EXPECT_EQ(BaseNode::INIT_OK, |
| 2360 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2442 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 MakeServerNode(sync_manager_.GetUserShare(), | 2512 MakeServerNode(sync_manager_.GetUserShare(), |
| 2431 PREFERENCES, | 2513 PREFERENCES, |
| 2432 client_tag, | 2514 client_tag, |
| 2433 BaseNode::GenerateSyncableHash(PREFERENCES, | 2515 BaseNode::GenerateSyncableHash(PREFERENCES, |
| 2434 client_tag), | 2516 client_tag), |
| 2435 entity_specifics); | 2517 entity_specifics); |
| 2436 // New node shouldn't start off unsynced. | 2518 // New node shouldn't start off unsynced. |
| 2437 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); | 2519 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2438 | 2520 |
| 2439 // Encrypt the datatatype, should set is_unsynced. | 2521 // Encrypt the datatatype, should set is_unsynced. |
| 2440 EXPECT_CALL(observer_, | 2522 EXPECT_CALL(encryption_observer_, |
| 2441 OnEncryptedTypesChanged( | 2523 OnEncryptedTypesChanged( |
| 2442 HasModelTypes(ModelTypeSet::All()), true)); | 2524 HasModelTypes(ModelTypeSet::All()), true)); |
| 2443 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2525 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2444 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2526 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2445 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2527 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2528 sync_manager_.GetEncryptionHandler()->Init(); |
| 2446 PumpLoop(); | 2529 PumpLoop(); |
| 2447 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag)); | 2530 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2448 | 2531 |
| 2449 // Manually change to the same title. Should not set is_unsynced. | 2532 // Manually change to the same title. Should not set is_unsynced. |
| 2450 // NON_UNIQUE_NAME should be kEncryptedString. | 2533 // NON_UNIQUE_NAME should be kEncryptedString. |
| 2451 { | 2534 { |
| 2452 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2535 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2453 WriteNode node(&trans); | 2536 WriteNode node(&trans); |
| 2454 EXPECT_EQ(BaseNode::INIT_OK, | 2537 EXPECT_EQ(BaseNode::INIT_OK, |
| 2455 node.InitByClientTagLookup(PREFERENCES, client_tag)); | 2538 node.InitByClientTagLookup(PREFERENCES, client_tag)); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2807 | 2890 |
| 2808 // Verify only the non-disabled types remain after cleanup. | 2891 // Verify only the non-disabled types remain after cleanup. |
| 2809 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2892 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
| 2810 EXPECT_TRUE(new_enabled_types.Equals( | 2893 EXPECT_TRUE(new_enabled_types.Equals( |
| 2811 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2894 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
| 2812 EXPECT_TRUE(disabled_types.Equals( | 2895 EXPECT_TRUE(disabled_types.Equals( |
| 2813 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2896 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
| 2814 } | 2897 } |
| 2815 | 2898 |
| 2816 } // namespace | 2899 } // namespace |
| OLD | NEW |