OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "sync/engine/apply_control_data_updates.h" | 5 #include "components/sync/engine_impl/apply_control_data_updates.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "sync/engine/syncer.h" | 18 #include "components/sync/base/cryptographer.h" |
19 #include "sync/engine/syncer_util.h" | 19 #include "components/sync/core/test/test_entry_factory.h" |
20 #include "sync/internal_api/public/test/test_entry_factory.h" | 20 #include "components/sync/engine_impl/syncer.h" |
21 #include "sync/protocol/nigori_specifics.pb.h" | 21 #include "components/sync/engine_impl/syncer_util.h" |
22 #include "sync/syncable/directory.h" | 22 #include "components/sync/protocol/nigori_specifics.pb.h" |
23 #include "sync/syncable/mutable_entry.h" | 23 #include "components/sync/syncable/directory.h" |
24 #include "sync/syncable/nigori_util.h" | 24 #include "components/sync/syncable/mutable_entry.h" |
25 #include "sync/syncable/syncable_read_transaction.h" | 25 #include "components/sync/syncable/nigori_util.h" |
26 #include "sync/syncable/syncable_util.h" | 26 #include "components/sync/syncable/syncable_read_transaction.h" |
27 #include "sync/syncable/syncable_write_transaction.h" | 27 #include "components/sync/syncable/syncable_util.h" |
28 #include "sync/test/engine/fake_model_worker.h" | 28 #include "components/sync/syncable/syncable_write_transaction.h" |
29 #include "sync/test/engine/test_directory_setter_upper.h" | 29 #include "components/sync/test/engine/fake_model_worker.h" |
30 #include "sync/test/engine/test_id_factory.h" | 30 #include "components/sync/test/engine/test_directory_setter_upper.h" |
31 #include "sync/test/fake_sync_encryption_handler.h" | 31 #include "components/sync/test/engine/test_id_factory.h" |
32 #include "sync/util/cryptographer.h" | 32 #include "components/sync/test/fake_sync_encryption_handler.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
34 | 34 |
35 namespace syncer { | 35 namespace syncer { |
36 | 36 |
37 using syncable::MutableEntry; | 37 using syncable::MutableEntry; |
38 using syncable::UNITTEST; | 38 using syncable::UNITTEST; |
39 using syncable::Id; | 39 using syncable::Id; |
40 | 40 |
41 class ApplyControlDataUpdatesTest : public ::testing::Test { | 41 class ApplyControlDataUpdatesTest : public ::testing::Test { |
42 public: | 42 public: |
43 protected: | 43 protected: |
44 ApplyControlDataUpdatesTest() {} | 44 ApplyControlDataUpdatesTest() {} |
45 ~ApplyControlDataUpdatesTest() override {} | 45 ~ApplyControlDataUpdatesTest() override {} |
46 | 46 |
47 void SetUp() override { | 47 void SetUp() override { |
48 dir_maker_.SetUp(); | 48 dir_maker_.SetUp(); |
49 entry_factory_.reset(new TestEntryFactory(directory())); | 49 entry_factory_.reset(new TestEntryFactory(directory())); |
50 } | 50 } |
51 | 51 |
52 void TearDown() override { dir_maker_.TearDown(); } | 52 void TearDown() override { dir_maker_.TearDown(); } |
53 | 53 |
54 syncable::Directory* directory() { | 54 syncable::Directory* directory() { return dir_maker_.directory(); } |
55 return dir_maker_.directory(); | |
56 } | |
57 | 55 |
58 TestIdFactory id_factory_; | 56 TestIdFactory id_factory_; |
59 std::unique_ptr<TestEntryFactory> entry_factory_; | 57 std::unique_ptr<TestEntryFactory> entry_factory_; |
60 | 58 |
61 private: | 59 private: |
62 base::MessageLoop loop_; // Needed for directory init. | 60 base::MessageLoop loop_; // Needed for directory init. |
63 TestDirectorySetterUpper dir_maker_; | 61 TestDirectorySetterUpper dir_maker_; |
64 | 62 |
65 DISALLOW_COPY_AND_ASSIGN(ApplyControlDataUpdatesTest); | 63 DISALLOW_COPY_AND_ASSIGN(ApplyControlDataUpdatesTest); |
66 }; | 64 }; |
(...skipping 16 matching lines...) Expand all Loading... |
83 | 81 |
84 // Nigori node updates should update the Cryptographer. | 82 // Nigori node updates should update the Cryptographer. |
85 Cryptographer other_cryptographer(cryptographer->encryptor()); | 83 Cryptographer other_cryptographer(cryptographer->encryptor()); |
86 KeyParams params = {"localhost", "dummy", "foobar"}; | 84 KeyParams params = {"localhost", "dummy", "foobar"}; |
87 other_cryptographer.AddKey(params); | 85 other_cryptographer.AddKey(params); |
88 | 86 |
89 sync_pb::EntitySpecifics specifics; | 87 sync_pb::EntitySpecifics specifics; |
90 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 88 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
91 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); | 89 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); |
92 nigori->set_encrypt_everything(true); | 90 nigori->set_encrypt_everything(true); |
93 entry_factory_->CreateUnappliedNewItem( | 91 entry_factory_->CreateUnappliedNewItem(ModelTypeToRootTag(NIGORI), specifics, |
94 ModelTypeToRootTag(NIGORI), specifics, true); | 92 true); |
95 EXPECT_FALSE(cryptographer->has_pending_keys()); | 93 EXPECT_FALSE(cryptographer->has_pending_keys()); |
96 | 94 |
97 ApplyControlDataUpdates(directory()); | 95 ApplyControlDataUpdates(directory()); |
98 | 96 |
99 EXPECT_FALSE(cryptographer->is_ready()); | 97 EXPECT_FALSE(cryptographer->is_ready()); |
100 EXPECT_TRUE(cryptographer->has_pending_keys()); | 98 EXPECT_TRUE(cryptographer->has_pending_keys()); |
101 { | 99 { |
102 syncable::ReadTransaction trans(FROM_HERE, directory()); | 100 syncable::ReadTransaction trans(FROM_HERE, directory()); |
103 EXPECT_EQ(ModelTypeSet::All(), | 101 EXPECT_EQ(ModelTypeSet::All(), |
104 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 102 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 true, BOOKMARKS, NULL); | 135 true, BOOKMARKS, NULL); |
138 // Next five items are children of the folder | 136 // Next five items are children of the folder |
139 size_t i; | 137 size_t i; |
140 size_t batch_s = 5; | 138 size_t batch_s = 5; |
141 for (i = 0; i < batch_s; ++i) { | 139 for (i = 0; i < batch_s; ++i) { |
142 entry_factory_->CreateUnsyncedItem(id_factory_.NewLocalId(), folder_id, | 140 entry_factory_->CreateUnsyncedItem(id_factory_.NewLocalId(), folder_id, |
143 base::StringPrintf("Item %" PRIuS "", i), | 141 base::StringPrintf("Item %" PRIuS "", i), |
144 false, BOOKMARKS, NULL); | 142 false, BOOKMARKS, NULL); |
145 } | 143 } |
146 // Next five items are children of the root. | 144 // Next five items are children of the root. |
147 for (; i < 2*batch_s; ++i) { | 145 for (; i < 2 * batch_s; ++i) { |
148 entry_factory_->CreateUnsyncedItem( | 146 entry_factory_->CreateUnsyncedItem( |
149 id_factory_.NewLocalId(), id_factory_.root(), | 147 id_factory_.NewLocalId(), id_factory_.root(), |
150 base::StringPrintf("Item %" PRIuS "", i), false, | 148 base::StringPrintf("Item %" PRIuS "", i), false, BOOKMARKS, NULL); |
151 BOOKMARKS, NULL); | |
152 } | 149 } |
153 | 150 |
154 KeyParams params = {"localhost", "dummy", "foobar"}; | 151 KeyParams params = {"localhost", "dummy", "foobar"}; |
155 cryptographer->AddKey(params); | 152 cryptographer->AddKey(params); |
156 sync_pb::EntitySpecifics specifics; | 153 sync_pb::EntitySpecifics specifics; |
157 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 154 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
158 cryptographer->GetKeys(nigori->mutable_encryption_keybag()); | 155 cryptographer->GetKeys(nigori->mutable_encryption_keybag()); |
159 nigori->set_encrypt_everything(true); | 156 nigori->set_encrypt_everything(true); |
160 encrypted_types.Put(BOOKMARKS); | 157 encrypted_types.Put(BOOKMARKS); |
161 entry_factory_->CreateUnappliedNewItem( | 158 entry_factory_->CreateUnappliedNewItem(ModelTypeToRootTag(NIGORI), specifics, |
162 ModelTypeToRootTag(NIGORI), specifics, true); | 159 true); |
163 EXPECT_FALSE(cryptographer->has_pending_keys()); | 160 EXPECT_FALSE(cryptographer->has_pending_keys()); |
164 EXPECT_TRUE(cryptographer->is_ready()); | 161 EXPECT_TRUE(cryptographer->is_ready()); |
165 | 162 |
166 { | 163 { |
167 // Ensure we have unsynced nodes that aren't properly encrypted. | 164 // Ensure we have unsynced nodes that aren't properly encrypted. |
168 syncable::ReadTransaction trans(FROM_HERE, directory()); | 165 syncable::ReadTransaction trans(FROM_HERE, directory()); |
169 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 166 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
170 | 167 |
171 Syncer::UnsyncedMetaHandles handles; | 168 Syncer::UnsyncedMetaHandles handles; |
172 GetUnsyncedEntries(&trans, &handles); | 169 GetUnsyncedEntries(&trans, &handles); |
173 EXPECT_EQ(2*batch_s+1, handles.size()); | 170 EXPECT_EQ(2 * batch_s + 1, handles.size()); |
174 } | 171 } |
175 | 172 |
176 ApplyControlDataUpdates(directory()); | 173 ApplyControlDataUpdates(directory()); |
177 | 174 |
178 EXPECT_FALSE(cryptographer->has_pending_keys()); | 175 EXPECT_FALSE(cryptographer->has_pending_keys()); |
179 EXPECT_TRUE(cryptographer->is_ready()); | 176 EXPECT_TRUE(cryptographer->is_ready()); |
180 { | 177 { |
181 syncable::ReadTransaction trans(FROM_HERE, directory()); | 178 syncable::ReadTransaction trans(FROM_HERE, directory()); |
182 | 179 |
183 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes | 180 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes |
184 // should be encrypted now. | 181 // should be encrypted now. |
185 EXPECT_EQ(ModelTypeSet::All(), | 182 EXPECT_EQ(ModelTypeSet::All(), |
186 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 183 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
187 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 184 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
188 | 185 |
189 Syncer::UnsyncedMetaHandles handles; | 186 Syncer::UnsyncedMetaHandles handles; |
190 GetUnsyncedEntries(&trans, &handles); | 187 GetUnsyncedEntries(&trans, &handles); |
191 EXPECT_EQ(2*batch_s+1, handles.size()); | 188 EXPECT_EQ(2 * batch_s + 1, handles.size()); |
192 } | 189 } |
193 | 190 |
194 // Simulate another nigori update that doesn't change anything. | 191 // Simulate another nigori update that doesn't change anything. |
195 { | 192 { |
196 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 193 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
197 MutableEntry entry(&trans, syncable::GET_TYPE_ROOT, NIGORI); | 194 MutableEntry entry(&trans, syncable::GET_TYPE_ROOT, NIGORI); |
198 ASSERT_TRUE(entry.good()); | 195 ASSERT_TRUE(entry.good()); |
199 entry.PutServerVersion(entry_factory_->GetNextRevision()); | 196 entry.PutServerVersion(entry_factory_->GetNextRevision()); |
200 entry.PutIsUnappliedUpdate(true); | 197 entry.PutIsUnappliedUpdate(true); |
201 } | 198 } |
202 | 199 |
203 ApplyControlDataUpdates(directory()); | 200 ApplyControlDataUpdates(directory()); |
204 | 201 |
205 EXPECT_FALSE(cryptographer->has_pending_keys()); | 202 EXPECT_FALSE(cryptographer->has_pending_keys()); |
206 EXPECT_TRUE(cryptographer->is_ready()); | 203 EXPECT_TRUE(cryptographer->is_ready()); |
207 { | 204 { |
208 syncable::ReadTransaction trans(FROM_HERE, directory()); | 205 syncable::ReadTransaction trans(FROM_HERE, directory()); |
209 | 206 |
210 // All our changes should still be encrypted. | 207 // All our changes should still be encrypted. |
211 EXPECT_EQ(ModelTypeSet::All(), | 208 EXPECT_EQ(ModelTypeSet::All(), |
212 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 209 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
213 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 210 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
214 | 211 |
215 Syncer::UnsyncedMetaHandles handles; | 212 Syncer::UnsyncedMetaHandles handles; |
216 GetUnsyncedEntries(&trans, &handles); | 213 GetUnsyncedEntries(&trans, &handles); |
217 EXPECT_EQ(2*batch_s+1, handles.size()); | 214 EXPECT_EQ(2 * batch_s + 1, handles.size()); |
218 } | 215 } |
219 } | 216 } |
220 | 217 |
221 // Create some local unsynced and unencrypted changes. Receive a new nigori | 218 // Create some local unsynced and unencrypted changes. Receive a new nigori |
222 // node enabling their encryption but also introducing pending keys. Ensure | 219 // node enabling their encryption but also introducing pending keys. Ensure |
223 // we apply the update properly without encrypting the unsynced changes or | 220 // we apply the update properly without encrypting the unsynced changes or |
224 // breaking. | 221 // breaking. |
225 TEST_F(ApplyControlDataUpdatesTest, CannotEncryptUnsyncedChanges) { | 222 TEST_F(ApplyControlDataUpdatesTest, CannotEncryptUnsyncedChanges) { |
226 // Storing the cryptographer separately is bad, but for this test we | 223 // Storing the cryptographer separately is bad, but for this test we |
227 // know it's safe. | 224 // know it's safe. |
(...skipping 10 matching lines...) Expand all Loading... |
238 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 235 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
239 | 236 |
240 Syncer::UnsyncedMetaHandles handles; | 237 Syncer::UnsyncedMetaHandles handles; |
241 GetUnsyncedEntries(&trans, &handles); | 238 GetUnsyncedEntries(&trans, &handles); |
242 EXPECT_TRUE(handles.empty()); | 239 EXPECT_TRUE(handles.empty()); |
243 } | 240 } |
244 | 241 |
245 // Create unsynced bookmarks without encryption. | 242 // Create unsynced bookmarks without encryption. |
246 // First item is a folder | 243 // First item is a folder |
247 Id folder_id = id_factory_.NewLocalId(); | 244 Id folder_id = id_factory_.NewLocalId(); |
248 entry_factory_->CreateUnsyncedItem( | 245 entry_factory_->CreateUnsyncedItem(folder_id, id_factory_.root(), "folder", |
249 folder_id, id_factory_.root(), "folder", true, | 246 true, BOOKMARKS, NULL); |
250 BOOKMARKS, NULL); | |
251 // Next five items are children of the folder | 247 // Next five items are children of the folder |
252 size_t i; | 248 size_t i; |
253 size_t batch_s = 5; | 249 size_t batch_s = 5; |
254 for (i = 0; i < batch_s; ++i) { | 250 for (i = 0; i < batch_s; ++i) { |
255 entry_factory_->CreateUnsyncedItem(id_factory_.NewLocalId(), folder_id, | 251 entry_factory_->CreateUnsyncedItem(id_factory_.NewLocalId(), folder_id, |
256 base::StringPrintf("Item %" PRIuS "", i), | 252 base::StringPrintf("Item %" PRIuS "", i), |
257 false, BOOKMARKS, NULL); | 253 false, BOOKMARKS, NULL); |
258 } | 254 } |
259 // Next five items are children of the root. | 255 // Next five items are children of the root. |
260 for (; i < 2*batch_s; ++i) { | 256 for (; i < 2 * batch_s; ++i) { |
261 entry_factory_->CreateUnsyncedItem( | 257 entry_factory_->CreateUnsyncedItem( |
262 id_factory_.NewLocalId(), id_factory_.root(), | 258 id_factory_.NewLocalId(), id_factory_.root(), |
263 base::StringPrintf("Item %" PRIuS "", i), false, | 259 base::StringPrintf("Item %" PRIuS "", i), false, BOOKMARKS, NULL); |
264 BOOKMARKS, NULL); | |
265 } | 260 } |
266 | 261 |
267 // We encrypt with new keys, triggering the local cryptographer to be unready | 262 // We encrypt with new keys, triggering the local cryptographer to be unready |
268 // and unable to decrypt data (once updated). | 263 // and unable to decrypt data (once updated). |
269 Cryptographer other_cryptographer(cryptographer->encryptor()); | 264 Cryptographer other_cryptographer(cryptographer->encryptor()); |
270 KeyParams params = {"localhost", "dummy", "foobar"}; | 265 KeyParams params = {"localhost", "dummy", "foobar"}; |
271 other_cryptographer.AddKey(params); | 266 other_cryptographer.AddKey(params); |
272 sync_pb::EntitySpecifics specifics; | 267 sync_pb::EntitySpecifics specifics; |
273 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 268 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
274 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); | 269 other_cryptographer.GetKeys(nigori->mutable_encryption_keybag()); |
275 nigori->set_encrypt_everything(true); | 270 nigori->set_encrypt_everything(true); |
276 encrypted_types.Put(BOOKMARKS); | 271 encrypted_types.Put(BOOKMARKS); |
277 entry_factory_->CreateUnappliedNewItem( | 272 entry_factory_->CreateUnappliedNewItem(ModelTypeToRootTag(NIGORI), specifics, |
278 ModelTypeToRootTag(NIGORI), specifics, true); | 273 true); |
279 EXPECT_FALSE(cryptographer->has_pending_keys()); | 274 EXPECT_FALSE(cryptographer->has_pending_keys()); |
280 | 275 |
281 { | 276 { |
282 // Ensure we have unsynced nodes that aren't properly encrypted. | 277 // Ensure we have unsynced nodes that aren't properly encrypted. |
283 syncable::ReadTransaction trans(FROM_HERE, directory()); | 278 syncable::ReadTransaction trans(FROM_HERE, directory()); |
284 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 279 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
285 Syncer::UnsyncedMetaHandles handles; | 280 Syncer::UnsyncedMetaHandles handles; |
286 GetUnsyncedEntries(&trans, &handles); | 281 GetUnsyncedEntries(&trans, &handles); |
287 EXPECT_EQ(2*batch_s+1, handles.size()); | 282 EXPECT_EQ(2 * batch_s + 1, handles.size()); |
288 } | 283 } |
289 | 284 |
290 ApplyControlDataUpdates(directory()); | 285 ApplyControlDataUpdates(directory()); |
291 | 286 |
292 EXPECT_FALSE(cryptographer->is_ready()); | 287 EXPECT_FALSE(cryptographer->is_ready()); |
293 EXPECT_TRUE(cryptographer->has_pending_keys()); | 288 EXPECT_TRUE(cryptographer->has_pending_keys()); |
294 { | 289 { |
295 syncable::ReadTransaction trans(FROM_HERE, directory()); | 290 syncable::ReadTransaction trans(FROM_HERE, directory()); |
296 | 291 |
297 // Since we have pending keys, we would have failed to encrypt, but the | 292 // Since we have pending keys, we would have failed to encrypt, but the |
298 // cryptographer should be updated. | 293 // cryptographer should be updated. |
299 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 294 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
300 EXPECT_EQ(ModelTypeSet::All(), | 295 EXPECT_EQ(ModelTypeSet::All(), |
301 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 296 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
302 EXPECT_FALSE(cryptographer->is_ready()); | 297 EXPECT_FALSE(cryptographer->is_ready()); |
303 EXPECT_TRUE(cryptographer->has_pending_keys()); | 298 EXPECT_TRUE(cryptographer->has_pending_keys()); |
304 | 299 |
305 Syncer::UnsyncedMetaHandles handles; | 300 Syncer::UnsyncedMetaHandles handles; |
306 GetUnsyncedEntries(&trans, &handles); | 301 GetUnsyncedEntries(&trans, &handles); |
307 EXPECT_EQ(2*batch_s+1, handles.size()); | 302 EXPECT_EQ(2 * batch_s + 1, handles.size()); |
308 } | 303 } |
309 } | 304 } |
310 | 305 |
311 // Verify we handle a nigori node conflict by merging encryption keys and | 306 // Verify we handle a nigori node conflict by merging encryption keys and |
312 // types, but preserve the custom passphrase state of the server. | 307 // types, but preserve the custom passphrase state of the server. |
313 // Initial sync ended should be set. | 308 // Initial sync ended should be set. |
314 TEST_F(ApplyControlDataUpdatesTest, | 309 TEST_F(ApplyControlDataUpdatesTest, |
315 NigoriConflictPendingKeysServerEncryptEverythingCustom) { | 310 NigoriConflictPendingKeysServerEncryptEverythingCustom) { |
316 Cryptographer* cryptographer; | 311 Cryptographer* cryptographer; |
317 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); | 312 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); |
(...skipping 24 matching lines...) Expand all Loading... |
342 cryptographer->AddKey(local_params); | 337 cryptographer->AddKey(local_params); |
343 EXPECT_TRUE(cryptographer->is_ready()); | 338 EXPECT_TRUE(cryptographer->is_ready()); |
344 | 339 |
345 // Set up a local nigori with the local encryption keys and default encrypted | 340 // Set up a local nigori with the local encryption keys and default encrypted |
346 // types. | 341 // types. |
347 sync_pb::EntitySpecifics local_specifics; | 342 sync_pb::EntitySpecifics local_specifics; |
348 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); | 343 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); |
349 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); | 344 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); |
350 local_nigori->set_encrypt_everything(false); | 345 local_nigori->set_encrypt_everything(false); |
351 local_nigori->set_keybag_is_frozen(true); | 346 local_nigori->set_keybag_is_frozen(true); |
352 ASSERT_TRUE(entry_factory_->SetLocalSpecificsForItem( | 347 ASSERT_TRUE( |
353 nigori_handle, local_specifics)); | 348 entry_factory_->SetLocalSpecificsForItem(nigori_handle, local_specifics)); |
354 // Apply the update locally so that UpdateFromEncryptedTypes knows what state | 349 // Apply the update locally so that UpdateFromEncryptedTypes knows what state |
355 // to use. | 350 // to use. |
356 { | 351 { |
357 syncable::ReadTransaction trans(FROM_HERE, directory()); | 352 syncable::ReadTransaction trans(FROM_HERE, directory()); |
358 cryptographer = directory()->GetCryptographer(&trans); | 353 cryptographer = directory()->GetCryptographer(&trans); |
359 directory()->GetNigoriHandler()->ApplyNigoriUpdate( | 354 directory()->GetNigoriHandler()->ApplyNigoriUpdate(*local_nigori, &trans); |
360 *local_nigori, | |
361 &trans); | |
362 } | 355 } |
363 | 356 |
364 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 357 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
365 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 358 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
366 ApplyControlDataUpdates(directory()); | 359 ApplyControlDataUpdates(directory()); |
367 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 360 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
368 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 361 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
369 | 362 |
370 EXPECT_FALSE(cryptographer->is_ready()); | 363 EXPECT_FALSE(cryptographer->is_ready()); |
371 EXPECT_TRUE(cryptographer->is_initialized()); | 364 EXPECT_TRUE(cryptographer->is_initialized()); |
372 EXPECT_TRUE(cryptographer->has_pending_keys()); | 365 EXPECT_TRUE(cryptographer->has_pending_keys()); |
373 EXPECT_TRUE(other_cryptographer.CanDecryptUsingDefaultKey( | 366 EXPECT_TRUE(other_cryptographer.CanDecryptUsingDefaultKey( |
374 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 367 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
375 nigori().encryption_keybag())); | 368 .nigori() |
376 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 369 .encryption_keybag())); |
377 nigori().keybag_is_frozen()); | 370 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
378 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 371 .nigori() |
379 nigori().encrypt_everything()); | 372 .keybag_is_frozen()); |
| 373 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
| 374 .nigori() |
| 375 .encrypt_everything()); |
380 { | 376 { |
381 syncable::ReadTransaction trans(FROM_HERE, directory()); | 377 syncable::ReadTransaction trans(FROM_HERE, directory()); |
382 EXPECT_EQ(ModelTypeSet::All(), | 378 EXPECT_EQ(ModelTypeSet::All(), |
383 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 379 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
384 } | 380 } |
385 } | 381 } |
386 | 382 |
387 // Verify we handle a nigori node conflict by merging encryption keys and | 383 // Verify we handle a nigori node conflict by merging encryption keys and |
388 // types, but preserve the custom passphrase state of the server. | 384 // types, but preserve the custom passphrase state of the server. |
389 // Initial sync ended should be set. | 385 // Initial sync ended should be set. |
(...skipping 28 matching lines...) Expand all Loading... |
418 cryptographer->AddKey(local_params); | 414 cryptographer->AddKey(local_params); |
419 EXPECT_TRUE(cryptographer->is_ready()); | 415 EXPECT_TRUE(cryptographer->is_ready()); |
420 | 416 |
421 // Set up a local nigori with the local encryption keys and default encrypted | 417 // Set up a local nigori with the local encryption keys and default encrypted |
422 // types. | 418 // types. |
423 sync_pb::EntitySpecifics local_specifics; | 419 sync_pb::EntitySpecifics local_specifics; |
424 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); | 420 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); |
425 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); | 421 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); |
426 local_nigori->set_encrypt_everything(true); | 422 local_nigori->set_encrypt_everything(true); |
427 local_nigori->set_keybag_is_frozen(true); | 423 local_nigori->set_keybag_is_frozen(true); |
428 ASSERT_TRUE(entry_factory_->SetLocalSpecificsForItem( | 424 ASSERT_TRUE( |
429 nigori_handle, local_specifics)); | 425 entry_factory_->SetLocalSpecificsForItem(nigori_handle, local_specifics)); |
430 // Apply the update locally so that UpdateFromEncryptedTypes knows what state | 426 // Apply the update locally so that UpdateFromEncryptedTypes knows what state |
431 // to use. | 427 // to use. |
432 { | 428 { |
433 syncable::ReadTransaction trans(FROM_HERE, directory()); | 429 syncable::ReadTransaction trans(FROM_HERE, directory()); |
434 cryptographer = directory()->GetCryptographer(&trans); | 430 cryptographer = directory()->GetCryptographer(&trans); |
435 directory()->GetNigoriHandler()->ApplyNigoriUpdate( | 431 directory()->GetNigoriHandler()->ApplyNigoriUpdate(*local_nigori, &trans); |
436 *local_nigori, | |
437 &trans); | |
438 } | 432 } |
439 | 433 |
440 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 434 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
441 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 435 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
442 ApplyControlDataUpdates(directory()); | 436 ApplyControlDataUpdates(directory()); |
443 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 437 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
444 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 438 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
445 | 439 |
446 EXPECT_FALSE(cryptographer->is_ready()); | 440 EXPECT_FALSE(cryptographer->is_ready()); |
447 EXPECT_TRUE(cryptographer->is_initialized()); | 441 EXPECT_TRUE(cryptographer->is_initialized()); |
448 EXPECT_TRUE(cryptographer->has_pending_keys()); | 442 EXPECT_TRUE(cryptographer->has_pending_keys()); |
449 EXPECT_TRUE(other_cryptographer.CanDecryptUsingDefaultKey( | 443 EXPECT_TRUE(other_cryptographer.CanDecryptUsingDefaultKey( |
450 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 444 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
451 nigori().encryption_keybag())); | 445 .nigori() |
452 EXPECT_FALSE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 446 .encryption_keybag())); |
453 nigori().keybag_is_frozen()); | 447 EXPECT_FALSE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
454 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 448 .nigori() |
455 nigori().encrypt_everything()); | 449 .keybag_is_frozen()); |
| 450 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
| 451 .nigori() |
| 452 .encrypt_everything()); |
456 { | 453 { |
457 syncable::ReadTransaction trans(FROM_HERE, directory()); | 454 syncable::ReadTransaction trans(FROM_HERE, directory()); |
458 EXPECT_EQ(ModelTypeSet::All(), | 455 EXPECT_EQ(ModelTypeSet::All(), |
459 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 456 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
460 } | 457 } |
461 } | 458 } |
462 | 459 |
463 // If the conflicting nigori has a subset of the local keys, the conflict | 460 // If the conflicting nigori has a subset of the local keys, the conflict |
464 // resolution should preserve the full local keys. Initial sync ended should be | 461 // resolution should preserve the full local keys. Initial sync ended should be |
465 // set. | 462 // set. |
466 TEST_F(ApplyControlDataUpdatesTest, | 463 TEST_F(ApplyControlDataUpdatesTest, NigoriConflictOldKeys) { |
467 NigoriConflictOldKeys) { | |
468 Cryptographer* cryptographer; | 464 Cryptographer* cryptographer; |
469 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); | 465 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); |
470 KeyParams old_params = {"localhost", "dummy", "old"}; | 466 KeyParams old_params = {"localhost", "dummy", "old"}; |
471 KeyParams new_params = {"localhost", "dummy", "new"}; | 467 KeyParams new_params = {"localhost", "dummy", "new"}; |
472 { | 468 { |
473 syncable::ReadTransaction trans(FROM_HERE, directory()); | 469 syncable::ReadTransaction trans(FROM_HERE, directory()); |
474 cryptographer = directory()->GetCryptographer(&trans); | 470 cryptographer = directory()->GetCryptographer(&trans); |
475 EXPECT_EQ(encrypted_types, | 471 EXPECT_EQ(encrypted_types, |
476 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 472 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
477 } | 473 } |
(...skipping 11 matching lines...) Expand all Loading... |
489 | 485 |
490 // Add the new keys to the cryptogrpaher | 486 // Add the new keys to the cryptogrpaher |
491 cryptographer->AddKey(new_params); | 487 cryptographer->AddKey(new_params); |
492 EXPECT_TRUE(cryptographer->is_ready()); | 488 EXPECT_TRUE(cryptographer->is_ready()); |
493 | 489 |
494 // Set up a local nigori with the superset of keys. | 490 // Set up a local nigori with the superset of keys. |
495 sync_pb::EntitySpecifics local_specifics; | 491 sync_pb::EntitySpecifics local_specifics; |
496 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); | 492 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); |
497 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); | 493 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); |
498 local_nigori->set_encrypt_everything(false); | 494 local_nigori->set_encrypt_everything(false); |
499 ASSERT_TRUE(entry_factory_->SetLocalSpecificsForItem( | 495 ASSERT_TRUE( |
500 nigori_handle, local_specifics)); | 496 entry_factory_->SetLocalSpecificsForItem(nigori_handle, local_specifics)); |
501 // Apply the update locally so that UpdateFromEncryptedTypes knows what state | 497 // Apply the update locally so that UpdateFromEncryptedTypes knows what state |
502 // to use. | 498 // to use. |
503 { | 499 { |
504 syncable::ReadTransaction trans(FROM_HERE, directory()); | 500 syncable::ReadTransaction trans(FROM_HERE, directory()); |
505 cryptographer = directory()->GetCryptographer(&trans); | 501 cryptographer = directory()->GetCryptographer(&trans); |
506 directory()->GetNigoriHandler()->ApplyNigoriUpdate( | 502 directory()->GetNigoriHandler()->ApplyNigoriUpdate(*local_nigori, &trans); |
507 *local_nigori, | |
508 &trans); | |
509 } | 503 } |
510 | 504 |
511 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 505 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
512 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 506 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
513 ApplyControlDataUpdates(directory()); | 507 ApplyControlDataUpdates(directory()); |
514 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 508 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
515 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 509 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
516 | 510 |
517 EXPECT_TRUE(cryptographer->is_ready()); | 511 EXPECT_TRUE(cryptographer->is_ready()); |
518 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 512 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
519 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 513 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
520 nigori().encryption_keybag())); | 514 .nigori() |
521 EXPECT_FALSE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 515 .encryption_keybag())); |
522 nigori().keybag_is_frozen()); | 516 EXPECT_FALSE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
523 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 517 .nigori() |
524 nigori().encrypt_everything()); | 518 .keybag_is_frozen()); |
| 519 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
| 520 .nigori() |
| 521 .encrypt_everything()); |
525 { | 522 { |
526 syncable::ReadTransaction trans(FROM_HERE, directory()); | 523 syncable::ReadTransaction trans(FROM_HERE, directory()); |
527 EXPECT_EQ(ModelTypeSet::All(), | 524 EXPECT_EQ(ModelTypeSet::All(), |
528 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 525 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
529 } | 526 } |
530 } | 527 } |
531 | 528 |
532 // If both nigoris are migrated, but we also set a custom passphrase locally, | 529 // If both nigoris are migrated, but we also set a custom passphrase locally, |
533 // the local nigori should be preserved. | 530 // the local nigori should be preserved. |
534 TEST_F(ApplyControlDataUpdatesTest, | 531 TEST_F(ApplyControlDataUpdatesTest, NigoriConflictBothMigratedLocalCustom) { |
535 NigoriConflictBothMigratedLocalCustom) { | |
536 Cryptographer* cryptographer; | 532 Cryptographer* cryptographer; |
537 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); | 533 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); |
538 KeyParams old_params = {"localhost", "dummy", "old"}; | 534 KeyParams old_params = {"localhost", "dummy", "old"}; |
539 KeyParams new_params = {"localhost", "dummy", "new"}; | 535 KeyParams new_params = {"localhost", "dummy", "new"}; |
540 { | 536 { |
541 syncable::ReadTransaction trans(FROM_HERE, directory()); | 537 syncable::ReadTransaction trans(FROM_HERE, directory()); |
542 cryptographer = directory()->GetCryptographer(&trans); | 538 cryptographer = directory()->GetCryptographer(&trans); |
543 EXPECT_EQ(encrypted_types, | 539 EXPECT_EQ(encrypted_types, |
544 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 540 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
545 } | 541 } |
(...skipping 20 matching lines...) Expand all Loading... |
566 EXPECT_TRUE(cryptographer->is_ready()); | 562 EXPECT_TRUE(cryptographer->is_ready()); |
567 | 563 |
568 // Set up a local nigori with a migrated custom passphrase type | 564 // Set up a local nigori with a migrated custom passphrase type |
569 sync_pb::EntitySpecifics local_specifics; | 565 sync_pb::EntitySpecifics local_specifics; |
570 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); | 566 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); |
571 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); | 567 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); |
572 local_nigori->set_encrypt_everything(true); | 568 local_nigori->set_encrypt_everything(true); |
573 local_nigori->set_keybag_is_frozen(true); | 569 local_nigori->set_keybag_is_frozen(true); |
574 local_nigori->set_passphrase_type( | 570 local_nigori->set_passphrase_type( |
575 sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); | 571 sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); |
576 ASSERT_TRUE(entry_factory_->SetLocalSpecificsForItem( | 572 ASSERT_TRUE( |
577 nigori_handle, local_specifics)); | 573 entry_factory_->SetLocalSpecificsForItem(nigori_handle, local_specifics)); |
578 // Apply the update locally so that UpdateFromEncryptedTypes knows what state | 574 // Apply the update locally so that UpdateFromEncryptedTypes knows what state |
579 // to use. | 575 // to use. |
580 { | 576 { |
581 syncable::ReadTransaction trans(FROM_HERE, directory()); | 577 syncable::ReadTransaction trans(FROM_HERE, directory()); |
582 cryptographer = directory()->GetCryptographer(&trans); | 578 cryptographer = directory()->GetCryptographer(&trans); |
583 directory()->GetNigoriHandler()->ApplyNigoriUpdate( | 579 directory()->GetNigoriHandler()->ApplyNigoriUpdate(*local_nigori, &trans); |
584 *local_nigori, | |
585 &trans); | |
586 } | 580 } |
587 | 581 |
588 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 582 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
589 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 583 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
590 ApplyControlDataUpdates(directory()); | 584 ApplyControlDataUpdates(directory()); |
591 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 585 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
592 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 586 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
593 | 587 |
594 EXPECT_TRUE(cryptographer->is_ready()); | 588 EXPECT_TRUE(cryptographer->is_ready()); |
595 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 589 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
596 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 590 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
597 nigori().encryption_keybag())); | 591 .nigori() |
598 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 592 .encryption_keybag())); |
599 nigori().keybag_is_frozen()); | 593 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
600 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 594 .nigori() |
601 nigori().encrypt_everything()); | 595 .keybag_is_frozen()); |
| 596 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
| 597 .nigori() |
| 598 .encrypt_everything()); |
602 EXPECT_EQ(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE, | 599 EXPECT_EQ(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE, |
603 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 600 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
604 nigori().passphrase_type()); | 601 .nigori() |
| 602 .passphrase_type()); |
605 { | 603 { |
606 syncable::ReadTransaction trans(FROM_HERE, directory()); | 604 syncable::ReadTransaction trans(FROM_HERE, directory()); |
607 EXPECT_EQ(ModelTypeSet::All(), | 605 EXPECT_EQ(ModelTypeSet::All(), |
608 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 606 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
609 } | 607 } |
610 } | 608 } |
611 | 609 |
612 // If both nigoris are migrated, but a custom passphrase with a new key was | 610 // If both nigoris are migrated, but a custom passphrase with a new key was |
613 // set remotely, the remote nigori should be preserved. | 611 // set remotely, the remote nigori should be preserved. |
614 TEST_F(ApplyControlDataUpdatesTest, | 612 TEST_F(ApplyControlDataUpdatesTest, NigoriConflictBothMigratedServerCustom) { |
615 NigoriConflictBothMigratedServerCustom) { | |
616 Cryptographer* cryptographer; | 613 Cryptographer* cryptographer; |
617 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); | 614 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); |
618 KeyParams old_params = {"localhost", "dummy", "old"}; | 615 KeyParams old_params = {"localhost", "dummy", "old"}; |
619 KeyParams new_params = {"localhost", "dummy", "new"}; | 616 KeyParams new_params = {"localhost", "dummy", "new"}; |
620 { | 617 { |
621 syncable::ReadTransaction trans(FROM_HERE, directory()); | 618 syncable::ReadTransaction trans(FROM_HERE, directory()); |
622 cryptographer = directory()->GetCryptographer(&trans); | 619 cryptographer = directory()->GetCryptographer(&trans); |
623 EXPECT_EQ(encrypted_types, | 620 EXPECT_EQ(encrypted_types, |
624 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 621 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
625 } | 622 } |
(...skipping 20 matching lines...) Expand all Loading... |
646 | 643 |
647 // Set up a local nigori with a migrated keystore passphrase type | 644 // Set up a local nigori with a migrated keystore passphrase type |
648 sync_pb::EntitySpecifics local_specifics; | 645 sync_pb::EntitySpecifics local_specifics; |
649 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); | 646 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); |
650 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); | 647 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); |
651 local_nigori->set_encrypt_everything(false); | 648 local_nigori->set_encrypt_everything(false); |
652 local_nigori->set_keybag_is_frozen(true); | 649 local_nigori->set_keybag_is_frozen(true); |
653 local_nigori->set_passphrase_type( | 650 local_nigori->set_passphrase_type( |
654 sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); | 651 sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); |
655 server_nigori->mutable_keystore_decryptor_token(); | 652 server_nigori->mutable_keystore_decryptor_token(); |
656 ASSERT_TRUE(entry_factory_->SetLocalSpecificsForItem( | 653 ASSERT_TRUE( |
657 nigori_handle, local_specifics)); | 654 entry_factory_->SetLocalSpecificsForItem(nigori_handle, local_specifics)); |
658 // Apply the update locally so that UpdateFromEncryptedTypes knows what state | 655 // Apply the update locally so that UpdateFromEncryptedTypes knows what state |
659 // to use. | 656 // to use. |
660 { | 657 { |
661 syncable::ReadTransaction trans(FROM_HERE, directory()); | 658 syncable::ReadTransaction trans(FROM_HERE, directory()); |
662 cryptographer = directory()->GetCryptographer(&trans); | 659 cryptographer = directory()->GetCryptographer(&trans); |
663 directory()->GetNigoriHandler()->ApplyNigoriUpdate( | 660 directory()->GetNigoriHandler()->ApplyNigoriUpdate(*local_nigori, &trans); |
664 *local_nigori, | |
665 &trans); | |
666 } | 661 } |
667 | 662 |
668 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 663 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
669 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 664 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
670 ApplyControlDataUpdates(directory()); | 665 ApplyControlDataUpdates(directory()); |
671 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 666 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
672 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 667 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
673 | 668 |
674 EXPECT_TRUE(cryptographer->is_initialized()); | 669 EXPECT_TRUE(cryptographer->is_initialized()); |
675 EXPECT_TRUE(cryptographer->has_pending_keys()); | 670 EXPECT_TRUE(cryptographer->has_pending_keys()); |
676 EXPECT_TRUE(other_cryptographer.CanDecryptUsingDefaultKey( | 671 EXPECT_TRUE(other_cryptographer.CanDecryptUsingDefaultKey( |
677 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 672 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
678 nigori().encryption_keybag())); | 673 .nigori() |
679 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 674 .encryption_keybag())); |
680 nigori().keybag_is_frozen()); | 675 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
681 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 676 .nigori() |
682 nigori().encrypt_everything()); | 677 .keybag_is_frozen()); |
| 678 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
| 679 .nigori() |
| 680 .encrypt_everything()); |
683 EXPECT_EQ(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE, | 681 EXPECT_EQ(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE, |
684 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 682 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
685 nigori().passphrase_type()); | 683 .nigori() |
| 684 .passphrase_type()); |
686 { | 685 { |
687 syncable::ReadTransaction trans(FROM_HERE, directory()); | 686 syncable::ReadTransaction trans(FROM_HERE, directory()); |
688 EXPECT_EQ(ModelTypeSet::All(), | 687 EXPECT_EQ(ModelTypeSet::All(), |
689 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 688 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
690 } | 689 } |
691 } | 690 } |
692 | 691 |
693 // If the local nigori is migrated but the server is not, preserve the local | 692 // If the local nigori is migrated but the server is not, preserve the local |
694 // nigori. | 693 // nigori. |
695 TEST_F(ApplyControlDataUpdatesTest, | 694 TEST_F(ApplyControlDataUpdatesTest, NigoriConflictLocalMigrated) { |
696 NigoriConflictLocalMigrated) { | |
697 Cryptographer* cryptographer; | 695 Cryptographer* cryptographer; |
698 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); | 696 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); |
699 KeyParams old_params = {"localhost", "dummy", "old"}; | 697 KeyParams old_params = {"localhost", "dummy", "old"}; |
700 KeyParams new_params = {"localhost", "dummy", "new"}; | 698 KeyParams new_params = {"localhost", "dummy", "new"}; |
701 { | 699 { |
702 syncable::ReadTransaction trans(FROM_HERE, directory()); | 700 syncable::ReadTransaction trans(FROM_HERE, directory()); |
703 cryptographer = directory()->GetCryptographer(&trans); | 701 cryptographer = directory()->GetCryptographer(&trans); |
704 EXPECT_EQ(encrypted_types, | 702 EXPECT_EQ(encrypted_types, |
705 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 703 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
706 } | 704 } |
(...skipping 17 matching lines...) Expand all Loading... |
724 EXPECT_TRUE(cryptographer->is_ready()); | 722 EXPECT_TRUE(cryptographer->is_ready()); |
725 | 723 |
726 // Set up a local nigori with a migrated custom passphrase type | 724 // Set up a local nigori with a migrated custom passphrase type |
727 sync_pb::EntitySpecifics local_specifics; | 725 sync_pb::EntitySpecifics local_specifics; |
728 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); | 726 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); |
729 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); | 727 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); |
730 local_nigori->set_encrypt_everything(true); | 728 local_nigori->set_encrypt_everything(true); |
731 local_nigori->set_keybag_is_frozen(true); | 729 local_nigori->set_keybag_is_frozen(true); |
732 local_nigori->set_passphrase_type( | 730 local_nigori->set_passphrase_type( |
733 sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); | 731 sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); |
734 ASSERT_TRUE(entry_factory_->SetLocalSpecificsForItem( | 732 ASSERT_TRUE( |
735 nigori_handle, local_specifics)); | 733 entry_factory_->SetLocalSpecificsForItem(nigori_handle, local_specifics)); |
736 // Apply the update locally so that UpdateFromEncryptedTypes knows what state | 734 // Apply the update locally so that UpdateFromEncryptedTypes knows what state |
737 // to use. | 735 // to use. |
738 { | 736 { |
739 syncable::ReadTransaction trans(FROM_HERE, directory()); | 737 syncable::ReadTransaction trans(FROM_HERE, directory()); |
740 cryptographer = directory()->GetCryptographer(&trans); | 738 cryptographer = directory()->GetCryptographer(&trans); |
741 directory()->GetNigoriHandler()->ApplyNigoriUpdate( | 739 directory()->GetNigoriHandler()->ApplyNigoriUpdate(*local_nigori, &trans); |
742 *local_nigori, | |
743 &trans); | |
744 } | 740 } |
745 | 741 |
746 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 742 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
747 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 743 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
748 ApplyControlDataUpdates(directory()); | 744 ApplyControlDataUpdates(directory()); |
749 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 745 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
750 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 746 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
751 | 747 |
752 EXPECT_TRUE(cryptographer->is_ready()); | 748 EXPECT_TRUE(cryptographer->is_ready()); |
753 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 749 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
754 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 750 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
755 nigori().encryption_keybag())); | 751 .nigori() |
756 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 752 .encryption_keybag())); |
757 nigori().keybag_is_frozen()); | 753 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
758 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 754 .nigori() |
759 nigori().encrypt_everything()); | 755 .keybag_is_frozen()); |
| 756 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
| 757 .nigori() |
| 758 .encrypt_everything()); |
760 EXPECT_EQ(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE, | 759 EXPECT_EQ(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE, |
761 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 760 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
762 nigori().passphrase_type()); | 761 .nigori() |
| 762 .passphrase_type()); |
763 { | 763 { |
764 syncable::ReadTransaction trans(FROM_HERE, directory()); | 764 syncable::ReadTransaction trans(FROM_HERE, directory()); |
765 EXPECT_EQ(ModelTypeSet::All(), | 765 EXPECT_EQ(ModelTypeSet::All(), |
766 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 766 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
767 } | 767 } |
768 } | 768 } |
769 | 769 |
770 // If the server nigori is migrated but the local is not, preserve the server | 770 // If the server nigori is migrated but the local is not, preserve the server |
771 // nigori. | 771 // nigori. |
772 TEST_F(ApplyControlDataUpdatesTest, | 772 TEST_F(ApplyControlDataUpdatesTest, NigoriConflictServerMigrated) { |
773 NigoriConflictServerMigrated) { | |
774 Cryptographer* cryptographer; | 773 Cryptographer* cryptographer; |
775 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); | 774 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); |
776 KeyParams old_params = {"localhost", "dummy", "old"}; | 775 KeyParams old_params = {"localhost", "dummy", "old"}; |
777 KeyParams new_params = {"localhost", "dummy", "new"}; | 776 KeyParams new_params = {"localhost", "dummy", "new"}; |
778 { | 777 { |
779 syncable::ReadTransaction trans(FROM_HERE, directory()); | 778 syncable::ReadTransaction trans(FROM_HERE, directory()); |
780 cryptographer = directory()->GetCryptographer(&trans); | 779 cryptographer = directory()->GetCryptographer(&trans); |
781 EXPECT_EQ(encrypted_types, | 780 EXPECT_EQ(encrypted_types, |
782 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); | 781 directory()->GetNigoriHandler()->GetEncryptedTypes(&trans)); |
783 } | 782 } |
(...skipping 18 matching lines...) Expand all Loading... |
802 cryptographer->AddKey(old_params); | 801 cryptographer->AddKey(old_params); |
803 cryptographer->AddKey(new_params); | 802 cryptographer->AddKey(new_params); |
804 EXPECT_TRUE(cryptographer->is_ready()); | 803 EXPECT_TRUE(cryptographer->is_ready()); |
805 | 804 |
806 // Set up a local nigori with a migrated custom passphrase type | 805 // Set up a local nigori with a migrated custom passphrase type |
807 sync_pb::EntitySpecifics local_specifics; | 806 sync_pb::EntitySpecifics local_specifics; |
808 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); | 807 sync_pb::NigoriSpecifics* local_nigori = local_specifics.mutable_nigori(); |
809 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); | 808 cryptographer->GetKeys(local_nigori->mutable_encryption_keybag()); |
810 local_nigori->set_encrypt_everything(false); | 809 local_nigori->set_encrypt_everything(false); |
811 local_nigori->set_keybag_is_frozen(false); | 810 local_nigori->set_keybag_is_frozen(false); |
812 ASSERT_TRUE(entry_factory_->SetLocalSpecificsForItem( | 811 ASSERT_TRUE( |
813 nigori_handle, local_specifics)); | 812 entry_factory_->SetLocalSpecificsForItem(nigori_handle, local_specifics)); |
814 // Apply the update locally so that UpdateFromEncryptedTypes knows what state | 813 // Apply the update locally so that UpdateFromEncryptedTypes knows what state |
815 // to use. | 814 // to use. |
816 { | 815 { |
817 syncable::ReadTransaction trans(FROM_HERE, directory()); | 816 syncable::ReadTransaction trans(FROM_HERE, directory()); |
818 cryptographer = directory()->GetCryptographer(&trans); | 817 cryptographer = directory()->GetCryptographer(&trans); |
819 directory()->GetNigoriHandler()->ApplyNigoriUpdate( | 818 directory()->GetNigoriHandler()->ApplyNigoriUpdate(*local_nigori, &trans); |
820 *local_nigori, | |
821 &trans); | |
822 } | 819 } |
823 | 820 |
824 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 821 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
825 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 822 EXPECT_TRUE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
826 ApplyControlDataUpdates(directory()); | 823 ApplyControlDataUpdates(directory()); |
827 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); | 824 EXPECT_TRUE(entry_factory_->GetIsUnsyncedForItem(nigori_handle)); |
828 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); | 825 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(nigori_handle)); |
829 | 826 |
830 EXPECT_TRUE(cryptographer->is_ready()); | 827 EXPECT_TRUE(cryptographer->is_ready()); |
831 // Note: we didn't overwrite the encryption keybag with the local keys. The | 828 // Note: we didn't overwrite the encryption keybag with the local keys. The |
832 // sync encryption handler will do that when it detects that the new | 829 // sync encryption handler will do that when it detects that the new |
833 // keybag is out of date (and update the keystore bootstrap if necessary). | 830 // keybag is out of date (and update the keystore bootstrap if necessary). |
834 EXPECT_FALSE(cryptographer->CanDecryptUsingDefaultKey( | 831 EXPECT_FALSE(cryptographer->CanDecryptUsingDefaultKey( |
835 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 832 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
836 nigori().encryption_keybag())); | 833 .nigori() |
| 834 .encryption_keybag())); |
837 EXPECT_TRUE(cryptographer->CanDecrypt( | 835 EXPECT_TRUE(cryptographer->CanDecrypt( |
838 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 836 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
839 nigori().encryption_keybag())); | 837 .nigori() |
840 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 838 .encryption_keybag())); |
841 nigori().keybag_is_frozen()); | 839 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
842 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 840 .nigori() |
843 nigori().has_keystore_decryptor_token()); | 841 .keybag_is_frozen()); |
| 842 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
| 843 .nigori() |
| 844 .has_keystore_decryptor_token()); |
844 EXPECT_EQ(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE, | 845 EXPECT_EQ(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE, |
845 entry_factory_->GetLocalSpecificsForItem(nigori_handle). | 846 entry_factory_->GetLocalSpecificsForItem(nigori_handle) |
846 nigori().passphrase_type()); | 847 .nigori() |
847 { | 848 .passphrase_type()); |
848 syncable::ReadTransaction trans(FROM_HERE, directory()); | 849 { syncable::ReadTransaction trans(FROM_HERE, directory()); } |
849 } | |
850 } | 850 } |
851 | 851 |
852 // Check that we can apply a simple control datatype node successfully. | 852 // Check that we can apply a simple control datatype node successfully. |
853 TEST_F(ApplyControlDataUpdatesTest, ControlApply) { | 853 TEST_F(ApplyControlDataUpdatesTest, ControlApply) { |
854 std::string experiment_id = "experiment"; | 854 std::string experiment_id = "experiment"; |
855 sync_pb::EntitySpecifics specifics; | 855 sync_pb::EntitySpecifics specifics; |
856 specifics.mutable_experiments()->mutable_keystore_encryption()-> | 856 specifics.mutable_experiments()->mutable_keystore_encryption()->set_enabled( |
857 set_enabled(true); | 857 true); |
858 int64_t experiment_handle = | 858 int64_t experiment_handle = |
859 entry_factory_->CreateUnappliedNewItem(experiment_id, specifics, false); | 859 entry_factory_->CreateUnappliedNewItem(experiment_id, specifics, false); |
860 ApplyControlDataUpdates(directory()); | 860 ApplyControlDataUpdates(directory()); |
861 | 861 |
862 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(experiment_handle)); | 862 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(experiment_handle)); |
863 EXPECT_TRUE( | 863 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(experiment_handle) |
864 entry_factory_->GetLocalSpecificsForItem(experiment_handle). | 864 .experiments() |
865 experiments().keystore_encryption().enabled()); | 865 .keystore_encryption() |
| 866 .enabled()); |
866 } | 867 } |
867 | 868 |
868 // Verify that we apply top level folders before their children. | 869 // Verify that we apply top level folders before their children. |
869 TEST_F(ApplyControlDataUpdatesTest, ControlApplyParentBeforeChild) { | 870 TEST_F(ApplyControlDataUpdatesTest, ControlApplyParentBeforeChild) { |
870 std::string parent_id = "parent"; | 871 std::string parent_id = "parent"; |
871 std::string experiment_id = "experiment"; | 872 std::string experiment_id = "experiment"; |
872 sync_pb::EntitySpecifics specifics; | 873 sync_pb::EntitySpecifics specifics; |
873 specifics.mutable_experiments()->mutable_keystore_encryption()-> | 874 specifics.mutable_experiments()->mutable_keystore_encryption()->set_enabled( |
874 set_enabled(true); | 875 true); |
875 int64_t experiment_handle = entry_factory_->CreateUnappliedNewItemWithParent( | 876 int64_t experiment_handle = entry_factory_->CreateUnappliedNewItemWithParent( |
876 experiment_id, specifics, parent_id); | 877 experiment_id, specifics, parent_id); |
877 int64_t parent_handle = | 878 int64_t parent_handle = |
878 entry_factory_->CreateUnappliedNewItem(parent_id, specifics, true); | 879 entry_factory_->CreateUnappliedNewItem(parent_id, specifics, true); |
879 ApplyControlDataUpdates(directory()); | 880 ApplyControlDataUpdates(directory()); |
880 | 881 |
881 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(parent_handle)); | 882 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(parent_handle)); |
882 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(experiment_handle)); | 883 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(experiment_handle)); |
883 EXPECT_TRUE( | 884 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(experiment_handle) |
884 entry_factory_->GetLocalSpecificsForItem(experiment_handle). | 885 .experiments() |
885 experiments().keystore_encryption().enabled()); | 886 .keystore_encryption() |
| 887 .enabled()); |
886 } | 888 } |
887 | 889 |
888 // Verify that we handle control datatype conflicts by preserving the server | 890 // Verify that we handle control datatype conflicts by preserving the server |
889 // data. | 891 // data. |
890 TEST_F(ApplyControlDataUpdatesTest, ControlConflict) { | 892 TEST_F(ApplyControlDataUpdatesTest, ControlConflict) { |
891 std::string experiment_id = "experiment"; | 893 std::string experiment_id = "experiment"; |
892 sync_pb::EntitySpecifics local_specifics, server_specifics; | 894 sync_pb::EntitySpecifics local_specifics, server_specifics; |
893 server_specifics.mutable_experiments()->mutable_keystore_encryption()-> | 895 server_specifics.mutable_experiments() |
894 set_enabled(true); | 896 ->mutable_keystore_encryption() |
895 local_specifics.mutable_experiments()->mutable_keystore_encryption()-> | 897 ->set_enabled(true); |
896 set_enabled(false); | 898 local_specifics.mutable_experiments() |
| 899 ->mutable_keystore_encryption() |
| 900 ->set_enabled(false); |
897 int64_t experiment_handle = | 901 int64_t experiment_handle = |
898 entry_factory_->CreateSyncedItem(experiment_id, EXPERIMENTS, false); | 902 entry_factory_->CreateSyncedItem(experiment_id, EXPERIMENTS, false); |
899 entry_factory_->SetServerSpecificsForItem(experiment_handle, | 903 entry_factory_->SetServerSpecificsForItem(experiment_handle, |
900 server_specifics); | 904 server_specifics); |
901 entry_factory_->SetLocalSpecificsForItem(experiment_handle, | 905 entry_factory_->SetLocalSpecificsForItem(experiment_handle, local_specifics); |
902 local_specifics); | |
903 ApplyControlDataUpdates(directory()); | 906 ApplyControlDataUpdates(directory()); |
904 | 907 |
905 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(experiment_handle)); | 908 EXPECT_FALSE(entry_factory_->GetIsUnappliedForItem(experiment_handle)); |
906 EXPECT_TRUE( | 909 EXPECT_TRUE(entry_factory_->GetLocalSpecificsForItem(experiment_handle) |
907 entry_factory_->GetLocalSpecificsForItem(experiment_handle). | 910 .experiments() |
908 experiments().keystore_encryption().enabled()); | 911 .keystore_encryption() |
| 912 .enabled()); |
909 } | 913 } |
910 | 914 |
911 // Check that applying a EXPERIMENTS update marks the datatype as downloaded. | 915 // Check that applying a EXPERIMENTS update marks the datatype as downloaded. |
912 TEST_F(ApplyControlDataUpdatesTest, ExperimentsApplyMarksDownloadCompleted) { | 916 TEST_F(ApplyControlDataUpdatesTest, ExperimentsApplyMarksDownloadCompleted) { |
913 EXPECT_FALSE(directory()->InitialSyncEndedForType(EXPERIMENTS)); | 917 EXPECT_FALSE(directory()->InitialSyncEndedForType(EXPERIMENTS)); |
914 | 918 |
915 // Create root node for EXPERIMENTS datatype | 919 // Create root node for EXPERIMENTS datatype |
916 { | 920 { |
917 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 921 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
918 syncable::ModelNeutralMutableEntry entry( | 922 syncable::ModelNeutralMutableEntry entry( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 ApplyControlDataUpdates(directory()); | 969 ApplyControlDataUpdates(directory()); |
966 | 970 |
967 // After applying the updates NIGORI should be marked as having its | 971 // After applying the updates NIGORI should be marked as having its |
968 // initial sync completed. | 972 // initial sync completed. |
969 EXPECT_TRUE(directory()->InitialSyncEndedForType(NIGORI)); | 973 EXPECT_TRUE(directory()->InitialSyncEndedForType(NIGORI)); |
970 // Verify that there is no side effect on another control type. | 974 // Verify that there is no side effect on another control type. |
971 EXPECT_FALSE(directory()->InitialSyncEndedForType(EXPERIMENTS)); | 975 EXPECT_FALSE(directory()->InitialSyncEndedForType(EXPERIMENTS)); |
972 } | 976 } |
973 | 977 |
974 } // namespace syncer | 978 } // namespace syncer |
OLD | NEW |