| 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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 // Server side change will put A in conflict. | 716 // Server side change will put A in conflict. |
| 717 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); | 717 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); |
| 718 { | 718 { |
| 719 // Mark bookmarks as encrypted and set the cryptographer to have pending | 719 // Mark bookmarks as encrypted and set the cryptographer to have pending |
| 720 // keys. | 720 // keys. |
| 721 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 721 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 722 Cryptographer other_cryptographer(&encryptor_); | 722 Cryptographer other_cryptographer(&encryptor_); |
| 723 other_cryptographer.AddKey(other_params); | 723 other_cryptographer.AddKey(other_params); |
| 724 sync_pb::EntitySpecifics specifics; | 724 sync_pb::EntitySpecifics specifics; |
| 725 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 725 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 726 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 726 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); |
| 727 dir_maker_.encryption_handler()->EnableEncryptEverything(); | 727 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
| 728 // Set up with an old passphrase, but have pending keys | 728 // Set up with an old passphrase, but have pending keys |
| 729 GetCryptographer(&wtrans)->AddKey(key_params); | 729 GetCryptographer(&wtrans)->AddKey(key_params); |
| 730 GetCryptographer(&wtrans)->Encrypt(bookmark, | 730 GetCryptographer(&wtrans)->Encrypt(bookmark, |
| 731 encrypted_bookmark.mutable_encrypted()); | 731 encrypted_bookmark.mutable_encrypted()); |
| 732 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encrypted()); | 732 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); |
| 733 | 733 |
| 734 // In conflict but properly encrypted. | 734 // In conflict but properly encrypted. |
| 735 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 735 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 736 ASSERT_TRUE(A.good()); | 736 ASSERT_TRUE(A.good()); |
| 737 A.Put(IS_UNSYNCED, true); | 737 A.Put(IS_UNSYNCED, true); |
| 738 A.Put(SPECIFICS, encrypted_bookmark); | 738 A.Put(SPECIFICS, encrypted_bookmark); |
| 739 A.Put(NON_UNIQUE_NAME, kEncryptedString); | 739 A.Put(NON_UNIQUE_NAME, kEncryptedString); |
| 740 // Not in conflict and properly encrypted. | 740 // Not in conflict and properly encrypted. |
| 741 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 741 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
| 742 ASSERT_TRUE(B.good()); | 742 ASSERT_TRUE(B.good()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 encrypted_pref.mutable_encrypted()); | 829 encrypted_pref.mutable_encrypted()); |
| 830 modified_pref.mutable_preference()->set_name("name2"); | 830 modified_pref.mutable_preference()->set_name("name2"); |
| 831 other_cryptographer.Encrypt(modified_pref, | 831 other_cryptographer.Encrypt(modified_pref, |
| 832 modified_pref.mutable_encrypted()); | 832 modified_pref.mutable_encrypted()); |
| 833 { | 833 { |
| 834 // Mark bookmarks and preferences as encrypted and set the cryptographer to | 834 // Mark bookmarks and preferences as encrypted and set the cryptographer to |
| 835 // have pending keys. | 835 // have pending keys. |
| 836 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 836 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 837 sync_pb::EntitySpecifics specifics; | 837 sync_pb::EntitySpecifics specifics; |
| 838 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 838 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 839 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 839 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); |
| 840 dir_maker_.encryption_handler()->EnableEncryptEverything(); | 840 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
| 841 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encrypted()); | 841 GetCryptographer(&wtrans)->SetPendingKeys(nigori->encryption_keybag()); |
| 842 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); | 842 EXPECT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); |
| 843 } | 843 } |
| 844 | 844 |
| 845 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); | 845 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); |
| 846 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); | 846 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); |
| 847 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); | 847 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); |
| 848 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); | 848 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); |
| 849 SyncShareNudge(); | 849 SyncShareNudge(); |
| 850 { | 850 { |
| 851 // Initial state. Everything is normal. | 851 // Initial state. Everything is normal. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); | 975 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); |
| 976 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); | 976 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); |
| 977 } | 977 } |
| 978 | 978 |
| 979 #undef VERIFY_ENTRY | 979 #undef VERIFY_ENTRY |
| 980 | 980 |
| 981 // Resolve a confict between two nigori's with different encrypted types, | 981 // Resolve a confict between two nigori's with different encrypted types, |
| 982 // and encryption keys (remote is explicit). Afterwards, the encrypted types | 982 // and encryption keys (remote is explicit). Afterwards, the encrypted types |
| 983 // should be unioned and the cryptographer should have both keys and be | 983 // should be unioned and the cryptographer should have both keys and be |
| 984 // encrypting with the remote encryption key by default. | 984 // encrypting with the remote encryption key by default. |
| 985 // TODO(zea): Test conflicts with keystore migration. |
| 985 TEST_F(SyncerTest, NigoriConflicts) { | 986 TEST_F(SyncerTest, NigoriConflicts) { |
| 986 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; | 987 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; |
| 987 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; | 988 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; |
| 988 Cryptographer other_cryptographer(&encryptor_); | 989 Cryptographer other_cryptographer(&encryptor_); |
| 989 other_cryptographer.AddKey(other_key_params); | 990 other_cryptographer.AddKey(other_key_params); |
| 990 ModelTypeSet encrypted_types(PASSWORDS, NIGORI); | 991 ModelTypeSet encrypted_types(PASSWORDS, NIGORI); |
| 991 sync_pb::EntitySpecifics initial_nigori_specifics; | 992 sync_pb::EntitySpecifics initial_nigori_specifics; |
| 992 initial_nigori_specifics.mutable_nigori(); | 993 initial_nigori_specifics.mutable_nigori(); |
| 993 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); | 994 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); |
| 994 | 995 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1007 { | 1008 { |
| 1008 // Local changes with different passphrase, different types. | 1009 // Local changes with different passphrase, different types. |
| 1009 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1010 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1010 sync_pb::EntitySpecifics specifics; | 1011 sync_pb::EntitySpecifics specifics; |
| 1011 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1012 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1012 GetCryptographer(&wtrans)->AddKey(local_key_params); | 1013 GetCryptographer(&wtrans)->AddKey(local_key_params); |
| 1013 GetCryptographer(&wtrans)->Encrypt( | 1014 GetCryptographer(&wtrans)->Encrypt( |
| 1014 our_encrypted_specifics, | 1015 our_encrypted_specifics, |
| 1015 our_encrypted_specifics.mutable_encrypted()); | 1016 our_encrypted_specifics.mutable_encrypted()); |
| 1016 GetCryptographer(&wtrans)->GetKeys( | 1017 GetCryptographer(&wtrans)->GetKeys( |
| 1017 nigori->mutable_encrypted()); | 1018 nigori->mutable_encryption_keybag()); |
| 1018 dir_maker_.encryption_handler()->EnableEncryptEverything(); | 1019 dir_maker_.encryption_handler()->EnableEncryptEverything(); |
| 1019 directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( | 1020 directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( |
| 1020 nigori, | 1021 nigori, |
| 1021 &wtrans); | 1022 &wtrans); |
| 1022 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1023 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1023 ModelTypeToRootTag(NIGORI)); | 1024 ModelTypeToRootTag(NIGORI)); |
| 1024 ASSERT_TRUE(nigori_entry.good()); | 1025 ASSERT_TRUE(nigori_entry.good()); |
| 1025 nigori_entry.Put(SPECIFICS, specifics); | 1026 nigori_entry.Put(SPECIFICS, specifics); |
| 1026 nigori_entry.Put(IS_UNSYNCED, true); | 1027 nigori_entry.Put(IS_UNSYNCED, true); |
| 1027 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); | 1028 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); |
| 1028 EXPECT_TRUE(encrypted_types.Equals( | 1029 EXPECT_TRUE(encrypted_types.Equals( |
| 1029 directory()->GetNigoriHandler()->GetEncryptedTypes(&wtrans))); | 1030 directory()->GetNigoriHandler()->GetEncryptedTypes(&wtrans))); |
| 1030 } | 1031 } |
| 1031 { | 1032 { |
| 1032 sync_pb::EntitySpecifics specifics; | 1033 sync_pb::EntitySpecifics specifics; |
| 1033 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1034 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1034 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 1035 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); |
| 1035 nigori->set_encrypt_bookmarks(true); | 1036 nigori->set_encrypt_bookmarks(true); |
| 1036 nigori->set_encrypt_preferences(true); | 1037 nigori->set_encrypt_preferences(true); |
| 1037 nigori->set_encrypt_everything(false); | 1038 nigori->set_encrypt_everything(false); |
| 1038 nigori->set_using_explicit_passphrase(true); | 1039 nigori->set_keybag_is_frozen(true); |
| 1039 mock_server_->SetNigori(1, 20, 20, specifics); | 1040 mock_server_->SetNigori(1, 20, 20, specifics); |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 // Will result in downloading the server nigori, which puts the local nigori | 1043 // Will result in downloading the server nigori, which puts the local nigori |
| 1043 // in a state of conflict. This is resolved by merging the local and server | 1044 // in a state of conflict. This is resolved by merging the local and server |
| 1044 // data (with priority given to the server's encryption keys if they are | 1045 // data (with priority given to the server's encryption keys if they are |
| 1045 // undecryptable), which we then commit. The cryptographer should have pending | 1046 // undecryptable), which we then commit. The cryptographer should have pending |
| 1046 // keys and merge the set of encrypted types. | 1047 // keys and merge the set of encrypted types. |
| 1047 SyncShareNudge(); // Resolve conflict in this cycle. | 1048 SyncShareNudge(); // Resolve conflict in this cycle. |
| 1048 SyncShareNudge(); // Commit local change in this cycle. | 1049 SyncShareNudge(); // Commit local change in this cycle. |
| 1049 { | 1050 { |
| 1050 // Ensure the nigori data merged (encrypted types). | 1051 // Ensure the nigori data merged (encrypted types). |
| 1051 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1052 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1052 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1053 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1053 ModelTypeToRootTag(NIGORI)); | 1054 ModelTypeToRootTag(NIGORI)); |
| 1054 ASSERT_TRUE(nigori_entry.good()); | 1055 ASSERT_TRUE(nigori_entry.good()); |
| 1055 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | 1056 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| 1056 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | 1057 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| 1057 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); | 1058 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); |
| 1058 ASSERT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); | 1059 ASSERT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); |
| 1059 EXPECT_TRUE(encrypted_types.Equals( | 1060 EXPECT_TRUE(encrypted_types.Equals( |
| 1060 directory()->GetNigoriHandler()->GetEncryptedTypes(&wtrans))); | 1061 directory()->GetNigoriHandler()->GetEncryptedTypes(&wtrans))); |
| 1061 EXPECT_TRUE(dir_maker_.encryption_handler()->EncryptEverythingEnabled()); | 1062 EXPECT_TRUE(dir_maker_.encryption_handler()->EncryptEverythingEnabled()); |
| 1062 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); | 1063 EXPECT_TRUE(specifics.nigori().keybag_is_frozen()); |
| 1063 // Supply the pending keys. Afterwards, we should be able to decrypt both | 1064 // Supply the pending keys. Afterwards, we should be able to decrypt both |
| 1064 // our own encrypted data and data encrypted by the other cryptographer, | 1065 // our own encrypted data and data encrypted by the other cryptographer, |
| 1065 // but the key provided by the other cryptographer should be the default. | 1066 // but the key provided by the other cryptographer should be the default. |
| 1066 EXPECT_TRUE( | 1067 EXPECT_TRUE( |
| 1067 GetCryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); | 1068 GetCryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); |
| 1068 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); | 1069 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); |
| 1069 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 1070 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1070 GetCryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted()); | 1071 GetCryptographer(&wtrans)->GetKeys(nigori->mutable_encryption_keybag()); |
| 1071 directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( | 1072 directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( |
| 1072 nigori, | 1073 nigori, |
| 1073 &wtrans); | 1074 &wtrans); |
| 1074 // Normally this would be written as part of SetPassphrase, but we do it | 1075 // Normally this would be written as part of SetPassphrase, but we do it |
| 1075 // manually for the test. | 1076 // manually for the test. |
| 1076 nigori_entry.Put(SPECIFICS, specifics); | 1077 nigori_entry.Put(SPECIFICS, specifics); |
| 1077 nigori_entry.Put(IS_UNSYNCED, true); | 1078 nigori_entry.Put(IS_UNSYNCED, true); |
| 1078 } | 1079 } |
| 1079 | 1080 |
| 1080 SyncShareNudge(); | 1081 SyncShareNudge(); |
| 1081 { | 1082 { |
| 1082 // Ensure everything is committed and stable now. The cryptographer | 1083 // Ensure everything is committed and stable now. The cryptographer |
| 1083 // should be able to decrypt both sets of keys, and the encrypted types | 1084 // should be able to decrypt both sets of keys, and the encrypted types |
| 1084 // should have been unioned. | 1085 // should have been unioned. |
| 1085 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1086 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1086 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1087 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1087 ModelTypeToRootTag(NIGORI)); | 1088 ModelTypeToRootTag(NIGORI)); |
| 1088 ASSERT_TRUE(nigori_entry.good()); | 1089 ASSERT_TRUE(nigori_entry.good()); |
| 1089 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | 1090 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| 1090 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | 1091 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| 1091 EXPECT_TRUE(GetCryptographer(&wtrans)->CanDecrypt( | 1092 EXPECT_TRUE(GetCryptographer(&wtrans)->CanDecrypt( |
| 1092 our_encrypted_specifics.encrypted())); | 1093 our_encrypted_specifics.encrypted())); |
| 1093 EXPECT_FALSE(GetCryptographer(&wtrans)-> | 1094 EXPECT_FALSE(GetCryptographer(&wtrans)-> |
| 1094 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); | 1095 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); |
| 1095 EXPECT_TRUE(GetCryptographer(&wtrans)->CanDecrypt( | 1096 EXPECT_TRUE(GetCryptographer(&wtrans)->CanDecrypt( |
| 1096 other_encrypted_specifics.encrypted())); | 1097 other_encrypted_specifics.encrypted())); |
| 1097 EXPECT_TRUE(GetCryptographer(&wtrans)-> | 1098 EXPECT_TRUE(GetCryptographer(&wtrans)-> |
| 1098 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); | 1099 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); |
| 1099 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).nigori(). | 1100 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).nigori(). |
| 1100 using_explicit_passphrase()); | 1101 keybag_is_frozen()); |
| 1101 } | 1102 } |
| 1102 } | 1103 } |
| 1103 | 1104 |
| 1104 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { | 1105 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { |
| 1105 { | 1106 { |
| 1106 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1107 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1107 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 1108 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), |
| 1108 "Pete"); | 1109 "Pete"); |
| 1109 ASSERT_TRUE(parent.good()); | 1110 ASSERT_TRUE(parent.good()); |
| 1110 parent.Put(syncable::IS_UNSYNCED, true); | 1111 parent.Put(syncable::IS_UNSYNCED, true); |
| (...skipping 3704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4815 | 4816 |
| 4816 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4817 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
| 4817 Add(mid_id_); | 4818 Add(mid_id_); |
| 4818 Add(low_id_); | 4819 Add(low_id_); |
| 4819 Add(high_id_); | 4820 Add(high_id_); |
| 4820 SyncShareNudge(); | 4821 SyncShareNudge(); |
| 4821 ExpectLocalOrderIsByServerId(); | 4822 ExpectLocalOrderIsByServerId(); |
| 4822 } | 4823 } |
| 4823 | 4824 |
| 4824 } // namespace syncer | 4825 } // namespace syncer |
| OLD | NEW |