| 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 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK); | 971 EXPECT_EQ(status().model_neutral_state().commit_result, SYNCER_OK); |
| 972 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 972 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 973 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); | 973 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); |
| 974 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); | 974 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); |
| 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, | |
| 982 // and encryption keys (remote is explicit). Afterwards, the encrypted types | |
| 983 // should be unioned and the cryptographer should have both keys and be | |
| 984 // encrypting with the remote encryption key by default. | |
| 985 // TODO(zea): Test conflicts with keystore migration. | |
| 986 TEST_F(SyncerTest, NigoriConflicts) { | |
| 987 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; | |
| 988 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; | |
| 989 Cryptographer other_cryptographer(&encryptor_); | |
| 990 other_cryptographer.AddKey(other_key_params); | |
| 991 ModelTypeSet encrypted_types(PASSWORDS, NIGORI); | |
| 992 sync_pb::EntitySpecifics initial_nigori_specifics; | |
| 993 initial_nigori_specifics.mutable_nigori(); | |
| 994 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); | |
| 995 | |
| 996 // Data for testing encryption/decryption. | |
| 997 sync_pb::EntitySpecifics other_encrypted_specifics; | |
| 998 other_encrypted_specifics.mutable_bookmark()->set_title("title"); | |
| 999 other_cryptographer.Encrypt( | |
| 1000 other_encrypted_specifics, | |
| 1001 other_encrypted_specifics.mutable_encrypted()); | |
| 1002 sync_pb::EntitySpecifics our_encrypted_specifics; | |
| 1003 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); | |
| 1004 | |
| 1005 // Receive the initial nigori node. | |
| 1006 SyncShareNudge(); | |
| 1007 encrypted_types = ModelTypeSet::All(); | |
| 1008 { | |
| 1009 // Local changes with different passphrase, different types. | |
| 1010 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | |
| 1011 sync_pb::EntitySpecifics specifics; | |
| 1012 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | |
| 1013 GetCryptographer(&wtrans)->AddKey(local_key_params); | |
| 1014 GetCryptographer(&wtrans)->Encrypt( | |
| 1015 our_encrypted_specifics, | |
| 1016 our_encrypted_specifics.mutable_encrypted()); | |
| 1017 GetCryptographer(&wtrans)->GetKeys( | |
| 1018 nigori->mutable_encryption_keybag()); | |
| 1019 dir_maker_.encryption_handler()->EnableEncryptEverything(); | |
| 1020 directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( | |
| 1021 nigori, | |
| 1022 &wtrans); | |
| 1023 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | |
| 1024 ModelTypeToRootTag(NIGORI)); | |
| 1025 ASSERT_TRUE(nigori_entry.good()); | |
| 1026 nigori_entry.Put(SPECIFICS, specifics); | |
| 1027 nigori_entry.Put(IS_UNSYNCED, true); | |
| 1028 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); | |
| 1029 EXPECT_TRUE(encrypted_types.Equals( | |
| 1030 directory()->GetNigoriHandler()->GetEncryptedTypes(&wtrans))); | |
| 1031 } | |
| 1032 { | |
| 1033 sync_pb::EntitySpecifics specifics; | |
| 1034 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | |
| 1035 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); | |
| 1036 nigori->set_encrypt_bookmarks(true); | |
| 1037 nigori->set_encrypt_preferences(true); | |
| 1038 nigori->set_encrypt_everything(false); | |
| 1039 nigori->set_keybag_is_frozen(true); | |
| 1040 mock_server_->SetNigori(1, 20, 20, specifics); | |
| 1041 } | |
| 1042 | |
| 1043 // Will result in downloading the server nigori, which puts the local nigori | |
| 1044 // in a state of conflict. This is resolved by merging the local and server | |
| 1045 // data (with priority given to the server's encryption keys if they are | |
| 1046 // undecryptable), which we then commit. The cryptographer should have pending | |
| 1047 // keys and merge the set of encrypted types. | |
| 1048 SyncShareNudge(); // Resolve conflict in this cycle. | |
| 1049 SyncShareNudge(); // Commit local change in this cycle. | |
| 1050 { | |
| 1051 // Ensure the nigori data merged (encrypted types). | |
| 1052 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | |
| 1053 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | |
| 1054 ModelTypeToRootTag(NIGORI)); | |
| 1055 ASSERT_TRUE(nigori_entry.good()); | |
| 1056 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | |
| 1057 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | |
| 1058 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); | |
| 1059 ASSERT_TRUE(GetCryptographer(&wtrans)->has_pending_keys()); | |
| 1060 EXPECT_TRUE(encrypted_types.Equals( | |
| 1061 directory()->GetNigoriHandler()->GetEncryptedTypes(&wtrans))); | |
| 1062 EXPECT_TRUE(dir_maker_.encryption_handler()->EncryptEverythingEnabled()); | |
| 1063 EXPECT_TRUE(specifics.nigori().keybag_is_frozen()); | |
| 1064 // Supply the pending keys. Afterwards, we should be able to decrypt both | |
| 1065 // our own encrypted data and data encrypted by the other cryptographer, | |
| 1066 // but the key provided by the other cryptographer should be the default. | |
| 1067 EXPECT_TRUE( | |
| 1068 GetCryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); | |
| 1069 EXPECT_FALSE(GetCryptographer(&wtrans)->has_pending_keys()); | |
| 1070 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | |
| 1071 GetCryptographer(&wtrans)->GetKeys(nigori->mutable_encryption_keybag()); | |
| 1072 directory()->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( | |
| 1073 nigori, | |
| 1074 &wtrans); | |
| 1075 // Normally this would be written as part of SetPassphrase, but we do it | |
| 1076 // manually for the test. | |
| 1077 nigori_entry.Put(SPECIFICS, specifics); | |
| 1078 nigori_entry.Put(IS_UNSYNCED, true); | |
| 1079 } | |
| 1080 | |
| 1081 SyncShareNudge(); | |
| 1082 { | |
| 1083 // Ensure everything is committed and stable now. The cryptographer | |
| 1084 // should be able to decrypt both sets of keys, and the encrypted types | |
| 1085 // should have been unioned. | |
| 1086 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | |
| 1087 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | |
| 1088 ModelTypeToRootTag(NIGORI)); | |
| 1089 ASSERT_TRUE(nigori_entry.good()); | |
| 1090 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | |
| 1091 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | |
| 1092 EXPECT_TRUE(GetCryptographer(&wtrans)->CanDecrypt( | |
| 1093 our_encrypted_specifics.encrypted())); | |
| 1094 EXPECT_FALSE(GetCryptographer(&wtrans)-> | |
| 1095 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); | |
| 1096 EXPECT_TRUE(GetCryptographer(&wtrans)->CanDecrypt( | |
| 1097 other_encrypted_specifics.encrypted())); | |
| 1098 EXPECT_TRUE(GetCryptographer(&wtrans)-> | |
| 1099 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); | |
| 1100 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).nigori(). | |
| 1101 keybag_is_frozen()); | |
| 1102 } | |
| 1103 } | |
| 1104 | |
| 1105 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { | 981 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { |
| 1106 { | 982 { |
| 1107 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 983 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 1108 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 984 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), |
| 1109 "Pete"); | 985 "Pete"); |
| 1110 ASSERT_TRUE(parent.good()); | 986 ASSERT_TRUE(parent.good()); |
| 1111 parent.Put(syncable::IS_UNSYNCED, true); | 987 parent.Put(syncable::IS_UNSYNCED, true); |
| 1112 parent.Put(syncable::IS_DIR, true); | 988 parent.Put(syncable::IS_DIR, true); |
| 1113 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); | 989 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); |
| 1114 parent.Put(syncable::BASE_VERSION, 1); | 990 parent.Put(syncable::BASE_VERSION, 1); |
| (...skipping 3701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4816 | 4692 |
| 4817 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4693 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
| 4818 Add(mid_id_); | 4694 Add(mid_id_); |
| 4819 Add(low_id_); | 4695 Add(low_id_); |
| 4820 Add(high_id_); | 4696 Add(high_id_); |
| 4821 SyncShareNudge(); | 4697 SyncShareNudge(); |
| 4822 ExpectLocalOrderIsByServerId(); | 4698 ExpectLocalOrderIsByServerId(); |
| 4823 } | 4699 } |
| 4824 | 4700 |
| 4825 } // namespace syncer | 4701 } // namespace syncer |
| OLD | NEW |