Chromium Code Reviews| 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
| 6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
| 7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
| 8 | 8 |
| 9 #include "components/sync/core_impl/sync_manager_impl.h" | 9 #include "components/sync/core_impl/sync_manager_impl.h" |
| 10 | 10 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 return entry.GetMetahandle(); | 215 return entry.GetMetahandle(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 int GetTotalNodeCount(UserShare* share, int64_t root) { | 218 int GetTotalNodeCount(UserShare* share, int64_t root) { |
| 219 ReadTransaction trans(FROM_HERE, share); | 219 ReadTransaction trans(FROM_HERE, share); |
| 220 ReadNode node(&trans); | 220 ReadNode node(&trans); |
| 221 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(root)); | 221 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(root)); |
| 222 return node.GetTotalNodeCount(); | 222 return node.GetTotalNodeCount(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 const char kUrl[] = "example.com"; | |
| 226 const char kPasswordValue[] = "secret"; | |
| 227 const char kClientTag[] = "tag"; | |
| 228 | |
| 225 } // namespace | 229 } // namespace |
| 226 | 230 |
| 227 class SyncApiTest : public testing::Test { | 231 class SyncApiTest : public testing::Test { |
| 228 public: | 232 public: |
| 229 void SetUp() override { test_user_share_.SetUp(); } | 233 void SetUp() override { test_user_share_.SetUp(); } |
| 230 | 234 |
| 231 void TearDown() override { test_user_share_.TearDown(); } | 235 void TearDown() override { test_user_share_.TearDown(); } |
| 232 | 236 |
| 233 protected: | 237 protected: |
| 234 // Create an entry with the given |model_type|, |client_tag| and | 238 // Create an entry with the given |model_type|, |client_tag| and |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 ReadTransaction trans(FROM_HERE, user_share()); | 515 ReadTransaction trans(FROM_HERE, user_share()); |
| 512 trans.GetCryptographer()->AddKey(params); | 516 trans.GetCryptographer()->AddKey(params); |
| 513 } | 517 } |
| 514 { | 518 { |
| 515 WriteTransaction trans(FROM_HERE, user_share()); | 519 WriteTransaction trans(FROM_HERE, user_share()); |
| 516 ReadNode root_node(&trans); | 520 ReadNode root_node(&trans); |
| 517 root_node.InitByRootLookup(); | 521 root_node.InitByRootLookup(); |
| 518 | 522 |
| 519 WriteNode password_node(&trans); | 523 WriteNode password_node(&trans); |
| 520 WriteNode::InitUniqueByCreationResult result = | 524 WriteNode::InitUniqueByCreationResult result = |
| 521 password_node.InitUniqueByCreation(PASSWORDS, root_node, "foo"); | 525 password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag); |
| 522 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 526 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 523 sync_pb::PasswordSpecificsData data; | 527 sync_pb::PasswordSpecificsData data; |
| 524 data.set_password_value("secret"); | 528 data.set_password_value(kPasswordValue); |
| 525 password_node.SetPasswordSpecifics(data); | 529 password_node.SetPasswordSpecifics(data); |
| 526 } | 530 } |
| 527 { | 531 { |
| 528 ReadTransaction trans(FROM_HERE, user_share()); | 532 ReadTransaction trans(FROM_HERE, user_share()); |
| 529 | 533 |
| 530 ReadNode password_node(&trans); | 534 ReadNode password_node(&trans); |
| 531 EXPECT_EQ(BaseNode::INIT_OK, | 535 EXPECT_EQ(BaseNode::INIT_OK, |
| 532 password_node.InitByClientTagLookup(PASSWORDS, "foo")); | 536 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); |
| 533 const sync_pb::PasswordSpecificsData& data = | 537 const sync_pb::PasswordSpecificsData& data = |
| 534 password_node.GetPasswordSpecifics(); | 538 password_node.GetPasswordSpecifics(); |
| 535 EXPECT_EQ("secret", data.password_value()); | 539 EXPECT_EQ(kPasswordValue, data.password_value()); |
| 540 // Check that nothing has appeared in the unencrypted field. | |
| 541 EXPECT_FALSE(password_node.GetEntitySpecifics() | |
| 542 .password() | |
| 543 .has_unencrypted_metadata()); | |
| 536 } | 544 } |
| 537 } | 545 } |
| 538 | 546 |
| 547 TEST_F(SyncApiTest, WriteDoesntChangeUnencryptedPasswordMetadata) { | |
|
Nicolas Zea
2016/08/26 23:47:01
What's the purpose of this test? Just that the met
melandory
2016/08/26 23:59:47
Fixed. My idea was to have test for persisting of
| |
| 548 KeyParams params = {"localhost", "username", "passphrase"}; | |
| 549 { | |
| 550 ReadTransaction trans(FROM_HERE, user_share()); | |
| 551 trans.GetCryptographer()->AddKey(params); | |
| 552 } | |
| 553 { | |
| 554 WriteTransaction trans(FROM_HERE, user_share()); | |
| 555 ReadNode root_node(&trans); | |
| 556 root_node.InitByRootLookup(); | |
| 557 | |
| 558 WriteNode password_node(&trans); | |
| 559 WriteNode::InitUniqueByCreationResult result = | |
| 560 password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag); | |
| 561 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | |
| 562 sync_pb::EntitySpecifics entity_specifics; | |
| 563 sync_pb::PasswordSpecifics* password_specifics = | |
| 564 entity_specifics.mutable_password(); | |
| 565 password_specifics->mutable_unencrypted_metadata()->set_url(kUrl); | |
| 566 password_node.SetEntitySpecifics(entity_specifics); | |
| 567 sync_pb::PasswordSpecificsData data; | |
| 568 data.set_password_value(kPasswordValue); | |
| 569 password_node.SetPasswordSpecifics(data); | |
| 570 } | |
| 571 { | |
| 572 ReadTransaction trans(FROM_HERE, user_share()); | |
| 573 | |
| 574 ReadNode password_node(&trans); | |
| 575 EXPECT_EQ(BaseNode::INIT_OK, | |
| 576 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); | |
| 577 const sync_pb::PasswordSpecificsData& data = | |
| 578 password_node.GetPasswordSpecifics(); | |
| 579 EXPECT_EQ(kUrl, password_node.GetEntitySpecifics() | |
| 580 .password() | |
| 581 .unencrypted_metadata() | |
| 582 .url()); | |
| 583 EXPECT_EQ(kPasswordValue, data.password_value()); | |
| 584 } | |
| 585 } | |
| 586 | |
| 539 TEST_F(SyncApiTest, WriteEncryptedTitle) { | 587 TEST_F(SyncApiTest, WriteEncryptedTitle) { |
| 540 KeyParams params = {"localhost", "username", "passphrase"}; | 588 KeyParams params = {"localhost", "username", "passphrase"}; |
| 541 { | 589 { |
| 542 ReadTransaction trans(FROM_HERE, user_share()); | 590 ReadTransaction trans(FROM_HERE, user_share()); |
| 543 trans.GetCryptographer()->AddKey(params); | 591 trans.GetCryptographer()->AddKey(params); |
| 544 } | 592 } |
| 545 encryption_handler()->EnableEncryptEverything(); | 593 encryption_handler()->EnableEncryptEverything(); |
| 546 int bookmark_id; | 594 int bookmark_id; |
| 547 { | 595 { |
| 548 WriteTransaction trans(FROM_HERE, user_share()); | 596 WriteTransaction trans(FROM_HERE, user_share()); |
| (...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2055 data.set_password_value("secret2"); | 2103 data.set_password_value("secret2"); |
| 2056 cryptographer->Encrypt( | 2104 cryptographer->Encrypt( |
| 2057 data, entity_specifics.mutable_password()->mutable_encrypted()); | 2105 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2058 node.SetPasswordSpecifics(data); | 2106 node.SetPasswordSpecifics(data); |
| 2059 const syncable::Entry* node_entry = node.GetEntry(); | 2107 const syncable::Entry* node_entry = node.GetEntry(); |
| 2060 EXPECT_TRUE(node_entry->GetIsUnsynced()); | 2108 EXPECT_TRUE(node_entry->GetIsUnsynced()); |
| 2061 } | 2109 } |
| 2062 } | 2110 } |
| 2063 | 2111 |
| 2064 // Passwords have their own handling for encryption. Verify setting a new | 2112 // Passwords have their own handling for encryption. Verify setting a new |
| 2065 // passphrase updates the data. | 2113 // passphrase updates the data. |
|
Nicolas Zea
2016/08/26 23:47:01
nit: mention that it also clears the metadata
melandory
2016/08/26 23:59:47
Done.
| |
| 2066 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { | 2114 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { |
| 2067 std::string client_tag = "title"; | |
| 2068 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2115 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2069 sync_pb::EntitySpecifics entity_specifics; | 2116 sync_pb::EntitySpecifics entity_specifics; |
| 2070 { | 2117 { |
| 2071 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2118 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2072 Cryptographer* cryptographer = trans.GetCryptographer(); | 2119 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2073 sync_pb::PasswordSpecificsData data; | 2120 sync_pb::PasswordSpecificsData data; |
| 2074 data.set_password_value("secret"); | 2121 data.set_password_value(kPasswordValue); |
| 2122 entity_specifics.mutable_password() | |
| 2123 ->mutable_unencrypted_metadata() | |
| 2124 ->set_url(kUrl); | |
| 2075 cryptographer->Encrypt( | 2125 cryptographer->Encrypt( |
| 2076 data, entity_specifics.mutable_password()->mutable_encrypted()); | 2126 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2077 } | 2127 } |
| 2078 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2128 EXPECT_TRUE(entity_specifics.password().has_unencrypted_metadata()); |
| 2079 syncable::GenerateSyncableHash(PASSWORDS, client_tag), | 2129 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag, |
| 2130 syncable::GenerateSyncableHash(PASSWORDS, kClientTag), | |
| 2080 entity_specifics); | 2131 entity_specifics); |
| 2081 // New node shouldn't start off unsynced. | 2132 // New node shouldn't start off unsynced. |
| 2082 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2133 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2083 | 2134 |
| 2084 // Set a new passphrase. Should set is_unsynced. | 2135 // Set a new passphrase. Should set is_unsynced. |
| 2085 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2136 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2086 EXPECT_CALL(encryption_observer_, | 2137 EXPECT_CALL(encryption_observer_, |
| 2087 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 2138 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 2088 ExpectPassphraseAcceptance(); | 2139 ExpectPassphraseAcceptance(); |
| 2089 SetCustomPassphraseAndCheck("new_passphrase"); | 2140 SetCustomPassphraseAndCheck("new_passphrase"); |
| 2090 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2141 { |
| 2142 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | |
| 2143 Cryptographer* cryptographer = trans.GetCryptographer(); | |
| 2144 EXPECT_TRUE(cryptographer->is_ready()); | |
| 2145 ReadNode password_node(&trans); | |
| 2146 EXPECT_EQ(BaseNode::INIT_OK, | |
| 2147 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); | |
| 2148 const sync_pb::PasswordSpecificsData& data = | |
| 2149 password_node.GetPasswordSpecifics(); | |
| 2150 EXPECT_EQ(kPasswordValue, data.password_value()); | |
| 2151 EXPECT_FALSE(password_node.GetEntitySpecifics() | |
| 2152 .password() | |
| 2153 .has_unencrypted_metadata()); | |
| 2154 } | |
| 2155 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); | |
| 2091 } | 2156 } |
| 2092 | 2157 |
| 2093 // Passwords have their own handling for encryption. Verify it does not result | 2158 // Passwords have their own handling for encryption. Verify it does not result |
| 2094 // in unnecessary writes via ReencryptEverything. | 2159 // in unnecessary writes via ReencryptEverything. |
| 2095 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { | 2160 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { |
| 2096 std::string client_tag = "title"; | 2161 std::string client_tag = "title"; |
| 2097 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2162 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2098 sync_pb::EntitySpecifics entity_specifics; | 2163 sync_pb::EntitySpecifics entity_specifics; |
| 2099 { | 2164 { |
| 2100 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2165 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3353 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3418 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3354 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3419 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3355 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3420 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3356 // task is to ensure that SyncManagerImpl reported initialization failure in | 3421 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3357 // OnInitializationComplete callback. | 3422 // OnInitializationComplete callback. |
| 3358 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3423 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3359 EXPECT_FALSE(initialization_succeeded_); | 3424 EXPECT_FALSE(initialization_succeeded_); |
| 3360 } | 3425 } |
| 3361 | 3426 |
| 3362 } // namespace syncer | 3427 } // namespace syncer |
| OLD | NEW |