Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/browser/sync/engine/apply_updates_command_unittest.cc

Issue 2828021: Take 2: sync changes to support encryption (Closed)
Patch Set: fix flaky password test under valgrind Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "chrome/browser/sync/engine/apply_updates_command.h" 5 #include "chrome/browser/sync/engine/apply_updates_command.h"
6 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" 6 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
7 #include "chrome/browser/sync/sessions/sync_session.h" 7 #include "chrome/browser/sync/sessions/sync_session.h"
8 #include "chrome/browser/sync/syncable/directory_manager.h" 8 #include "chrome/browser/sync/syncable/directory_manager.h"
9 #include "chrome/browser/sync/syncable/syncable.h" 9 #include "chrome/browser/sync/syncable/syncable.h"
10 #include "chrome/browser/sync/syncable/syncable_id.h" 10 #include "chrome/browser/sync/syncable/syncable_id.h"
(...skipping 17 matching lines...) Expand all
28 public: 28 public:
29 protected: 29 protected:
30 ApplyUpdatesCommandTest() : next_revision_(1) {} 30 ApplyUpdatesCommandTest() : next_revision_(1) {}
31 virtual ~ApplyUpdatesCommandTest() {} 31 virtual ~ApplyUpdatesCommandTest() {}
32 32
33 virtual void SetUp() { 33 virtual void SetUp() {
34 workers()->clear(); 34 workers()->clear();
35 mutable_routing_info()->clear(); 35 mutable_routing_info()->clear();
36 workers()->push_back(new ModelSafeWorker()); // GROUP_PASSIVE worker. 36 workers()->push_back(new ModelSafeWorker()); // GROUP_PASSIVE worker.
37 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_PASSIVE; 37 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_PASSIVE;
38 (*mutable_routing_info())[syncable::PASSWORDS] = GROUP_PASSIVE;
39 (*mutable_routing_info())[syncable::NIGORI] = GROUP_PASSIVE;
38 SyncerCommandTest::SetUp(); 40 SyncerCommandTest::SetUp();
39 } 41 }
40 42
41 // Create a new unapplied update. 43 // Create a new unapplied update.
42 void CreateUnappliedNewItemWithParent(const string& item_id, 44 void CreateUnappliedNewItemWithParent(const string& item_id,
43 const string& parent_id) { 45 const string& parent_id) {
44 ScopedDirLookup dir(syncdb().manager(), syncdb().name()); 46 ScopedDirLookup dir(syncdb().manager(), syncdb().name());
45 ASSERT_TRUE(dir.good()); 47 ASSERT_TRUE(dir.good());
46 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); 48 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__);
47 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, 49 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
48 Id::CreateFromServerId(item_id)); 50 Id::CreateFromServerId(item_id));
49 ASSERT_TRUE(entry.good()); 51 ASSERT_TRUE(entry.good());
50 entry.Put(syncable::SERVER_VERSION, next_revision_++); 52 entry.Put(syncable::SERVER_VERSION, next_revision_++);
51 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); 53 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
52 54
53 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); 55 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
54 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id)); 56 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id));
55 entry.Put(syncable::SERVER_IS_DIR, true); 57 entry.Put(syncable::SERVER_IS_DIR, true);
56 sync_pb::EntitySpecifics default_bookmark_specifics; 58 sync_pb::EntitySpecifics default_bookmark_specifics;
57 default_bookmark_specifics.MutableExtension(sync_pb::bookmark); 59 default_bookmark_specifics.MutableExtension(sync_pb::bookmark);
58 entry.Put(syncable::SERVER_SPECIFICS, default_bookmark_specifics); 60 entry.Put(syncable::SERVER_SPECIFICS, default_bookmark_specifics);
59 } 61 }
60 62
63 void CreateUnappliedNewItem(const string& item_id,
64 const sync_pb::EntitySpecifics& specifics) {
65 ScopedDirLookup dir(syncdb().manager(), syncdb().name());
66 ASSERT_TRUE(dir.good());
67 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__);
68 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
69 Id::CreateFromServerId(item_id));
70 ASSERT_TRUE(entry.good());
71 entry.Put(syncable::SERVER_VERSION, next_revision_++);
72 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
73
74 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
75 entry.Put(syncable::SERVER_PARENT_ID, syncable::kNullId);
76 entry.Put(syncable::SERVER_IS_DIR, false);
77 entry.Put(syncable::SERVER_SPECIFICS, specifics);
78 }
79
61 ApplyUpdatesCommand apply_updates_command_; 80 ApplyUpdatesCommand apply_updates_command_;
62 81
63 private: 82 private:
64 int64 next_revision_; 83 int64 next_revision_;
65 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest); 84 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest);
66 }; 85 };
67 86
68 TEST_F(ApplyUpdatesCommandTest, Simple) { 87 TEST_F(ApplyUpdatesCommandTest, Simple) {
69 string root_server_id = syncable::kNullId.GetServerId(); 88 string root_server_id = syncable::kNullId.GetServerId();
70 CreateUnappliedNewItemWithParent("parent", root_server_id); 89 CreateUnappliedNewItemWithParent("parent", root_server_id);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 sessions::StatusController* status = session()->status_controller(); 156 sessions::StatusController* status = session()->status_controller();
138 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); 157 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
139 EXPECT_EQ(6, status->update_progress().AppliedUpdatesSize()) 158 EXPECT_EQ(6, status->update_progress().AppliedUpdatesSize())
140 << "All updates should have been attempted"; 159 << "All updates should have been attempted";
141 EXPECT_EQ(2, status->conflict_progress().ConflictingItemsSize()) 160 EXPECT_EQ(2, status->conflict_progress().ConflictingItemsSize())
142 << "The updates with unknown ancestors should be in conflict"; 161 << "The updates with unknown ancestors should be in conflict";
143 EXPECT_EQ(4, status->update_progress().SuccessfullyAppliedUpdateCount()) 162 EXPECT_EQ(4, status->update_progress().SuccessfullyAppliedUpdateCount())
144 << "The updates with known ancestors should be successfully applied"; 163 << "The updates with known ancestors should be successfully applied";
145 } 164 }
146 165
166 TEST_F(ApplyUpdatesCommandTest, DecryptablePassword) {
167 // Decryptable password updates should be applied.
168 Cryptographer* cryptographer =
169 session()->context()->directory_manager()->cryptographer();
170
171 browser_sync::KeyParams params = {"localhost", "dummy", "foobar"};
172 cryptographer->AddKey(params);
173
174 sync_pb::EntitySpecifics specifics;
175 sync_pb::PasswordSpecificsData data;
176 data.set_origin("http://example.com");
177
178 cryptographer->Encrypt(data,
179 specifics.MutableExtension(sync_pb::password)->mutable_encrypted());
180 CreateUnappliedNewItem("item", specifics);
181
182 apply_updates_command_.ExecuteImpl(session());
183
184 sessions::StatusController* status = session()->status_controller();
185 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
186 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize())
187 << "All updates should have been attempted";
188 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize())
189 << "No update should be in conflict because they're all decryptable";
190 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount())
191 << "The updates that can be decrypted should be applied";
192 }
193
194 TEST_F(ApplyUpdatesCommandTest, UndecryptablePassword) {
195 // Undecryptable password updates should not be applied.
196 sync_pb::EntitySpecifics specifics;
197 specifics.MutableExtension(sync_pb::password);
198 CreateUnappliedNewItem("item", specifics);
199
200 apply_updates_command_.ExecuteImpl(session());
201
202 sessions::StatusController* status = session()->status_controller();
203 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
204 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize())
205 << "All updates should have been attempted";
206 EXPECT_EQ(1, status->conflict_progress().ConflictingItemsSize())
207 << "The updates that can't be decrypted should be in conflict";
208 EXPECT_EQ(0, status->update_progress().SuccessfullyAppliedUpdateCount())
209 << "No update that can't be decrypted should be applied";
210 }
211
212 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) {
213 // Only decryptable password updates should be applied.
214 {
215 Cryptographer* cryptographer =
216 session()->context()->directory_manager()->cryptographer();
217
218 KeyParams params = {"localhost", "dummy", "foobar"};
219 cryptographer->AddKey(params);
220
221 sync_pb::EntitySpecifics specifics;
222 sync_pb::PasswordSpecificsData data;
223 data.set_origin("http://example.com/1");
224
225 cryptographer->Encrypt(data,
226 specifics.MutableExtension(sync_pb::password)->mutable_encrypted());
227 CreateUnappliedNewItem("item1", specifics);
228 }
229 {
230 // Create a new cryptographer, independent of the one in the session.
231 Cryptographer cryptographer;
232 KeyParams params = {"localhost", "dummy", "bazqux"};
233 cryptographer.AddKey(params);
234
235 sync_pb::EntitySpecifics specifics;
236 sync_pb::PasswordSpecificsData data;
237 data.set_origin("http://example.com/2");
238
239 cryptographer.Encrypt(data,
240 specifics.MutableExtension(sync_pb::password)->mutable_encrypted());
241 CreateUnappliedNewItem("item2", specifics);
242 }
243
244 apply_updates_command_.ExecuteImpl(session());
245
246 sessions::StatusController* status = session()->status_controller();
247 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
248 EXPECT_EQ(2, status->update_progress().AppliedUpdatesSize())
249 << "All updates should have been attempted";
250 EXPECT_EQ(1, status->conflict_progress().ConflictingItemsSize())
251 << "The decryptable password update should be applied";
252 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount())
253 << "The undecryptable password update shouldn't be applied";
254 }
255
256 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) {
257 // Nigori node updates should update the Cryptographer.
258 Cryptographer other_cryptographer;
259 KeyParams params = {"localhost", "dummy", "foobar"};
260 other_cryptographer.AddKey(params);
261
262 sync_pb::EntitySpecifics specifics;
263 other_cryptographer.GetKeys(
264 specifics.MutableExtension(sync_pb::nigori)->mutable_encrypted());
265
266 CreateUnappliedNewItem("item", specifics);
267
268 Cryptographer* cryptographer =
269 session()->context()->directory_manager()->cryptographer();
270 EXPECT_FALSE(cryptographer->has_pending_keys());
271
272 apply_updates_command_.ExecuteImpl(session());
273
274 sessions::StatusController* status = session()->status_controller();
275 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE);
276 EXPECT_EQ(1, status->update_progress().AppliedUpdatesSize())
277 << "All updates should have been attempted";
278 EXPECT_EQ(0, status->conflict_progress().ConflictingItemsSize())
279 << "The nigori update shouldn't be in conflict";
280 EXPECT_EQ(1, status->update_progress().SuccessfullyAppliedUpdateCount())
281 << "The nigori update should be applied";
282
283 EXPECT_FALSE(cryptographer->is_ready());
284 EXPECT_TRUE(cryptographer->has_pending_keys());
285 }
286
147 } // namespace browser_sync 287 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698