| 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 "components/sync/engine_impl/sync_manager_impl.h" | 5 #include "components/sync/engine_impl/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/metrics/field_trial.h" |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/test/values_test_util.h" | 21 #include "base/test/values_test_util.h" |
| 21 #include "base/values.h" | 22 #include "base/values.h" |
| 22 #include "components/sync/base/attachment_id_proto.h" | 23 #include "components/sync/base/attachment_id_proto.h" |
| 23 #include "components/sync/base/cancelation_signal.h" | 24 #include "components/sync/base/cancelation_signal.h" |
| 24 #include "components/sync/base/extensions_activity.h" | 25 #include "components/sync/base/extensions_activity.h" |
| 25 #include "components/sync/base/fake_encryptor.h" | 26 #include "components/sync/base/fake_encryptor.h" |
| 26 #include "components/sync/base/mock_unrecoverable_error_handler.h" | 27 #include "components/sync/base/mock_unrecoverable_error_handler.h" |
| 27 #include "components/sync/base/model_type_test_util.h" | 28 #include "components/sync/base/model_type_test_util.h" |
| 29 #include "components/sync/base/sync_features.h" |
| 28 #include "components/sync/engine/engine_util.h" | 30 #include "components/sync/engine/engine_util.h" |
| 29 #include "components/sync/engine/events/protocol_event.h" | 31 #include "components/sync/engine/events/protocol_event.h" |
| 30 #include "components/sync/engine/model_safe_worker.h" | 32 #include "components/sync/engine/model_safe_worker.h" |
| 31 #include "components/sync/engine/net/http_post_provider_factory.h" | 33 #include "components/sync/engine/net/http_post_provider_factory.h" |
| 32 #include "components/sync/engine/net/http_post_provider_interface.h" | 34 #include "components/sync/engine/net/http_post_provider_interface.h" |
| 33 #include "components/sync/engine/polling_constants.h" | 35 #include "components/sync/engine/polling_constants.h" |
| 34 #include "components/sync/engine/test_engine_components_factory.h" | 36 #include "components/sync/engine/test_engine_components_factory.h" |
| 35 #include "components/sync/engine_impl/cycle/sync_cycle.h" | 37 #include "components/sync/engine_impl/cycle/sync_cycle.h" |
| 36 #include "components/sync/engine_impl/sync_scheduler.h" | 38 #include "components/sync/engine_impl/sync_scheduler.h" |
| 37 #include "components/sync/engine_impl/test_entry_factory.h" | 39 #include "components/sync/engine_impl/test_entry_factory.h" |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 ReadNode node(&trans); | 497 ReadNode node(&trans); |
| 496 EXPECT_EQ(BaseNode::INIT_OK, | 498 EXPECT_EQ(BaseNode::INIT_OK, |
| 497 node.InitByClientTagLookup(BOOKMARKS, "testtag")); | 499 node.InitByClientTagLookup(BOOKMARKS, "testtag")); |
| 498 EXPECT_EQ(node.GetTitle(), test_title); | 500 EXPECT_EQ(node.GetTitle(), test_title); |
| 499 EXPECT_EQ(node.GetModelType(), BOOKMARKS); | 501 EXPECT_EQ(node.GetModelType(), BOOKMARKS); |
| 500 } | 502 } |
| 501 } | 503 } |
| 502 | 504 |
| 503 TEST_F(SyncApiTest, WriteAndReadPassword) { | 505 TEST_F(SyncApiTest, WriteAndReadPassword) { |
| 504 KeyParams params = {"localhost", "username", "passphrase"}; | 506 KeyParams params = {"localhost", "username", "passphrase"}; |
| 507 base::FeatureList::ClearInstanceForTesting(); |
| 508 EXPECT_FALSE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
| 509 |
| 505 { | 510 { |
| 506 ReadTransaction trans(FROM_HERE, user_share()); | 511 ReadTransaction trans(FROM_HERE, user_share()); |
| 507 trans.GetCryptographer()->AddKey(params); | 512 trans.GetCryptographer()->AddKey(params); |
| 508 } | 513 } |
| 514 |
| 509 { | 515 { |
| 510 WriteTransaction trans(FROM_HERE, user_share()); | 516 WriteTransaction trans(FROM_HERE, user_share()); |
| 511 ReadNode root_node(&trans); | 517 ReadNode root_node(&trans); |
| 512 root_node.InitByRootLookup(); | 518 root_node.InitByRootLookup(); |
| 513 | 519 |
| 514 WriteNode password_node(&trans); | 520 WriteNode password_node(&trans); |
| 515 WriteNode::InitUniqueByCreationResult result = | 521 WriteNode::InitUniqueByCreationResult result = |
| 516 password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag); | 522 password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag); |
| 517 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 523 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 518 sync_pb::PasswordSpecificsData data; | 524 sync_pb::PasswordSpecificsData data; |
| 519 data.set_password_value(kPasswordValue); | 525 data.set_password_value(kPasswordValue); |
| 520 password_node.SetPasswordSpecifics(data); | 526 password_node.SetPasswordSpecifics(data); |
| 521 } | 527 } |
| 522 { | 528 { |
| 523 ReadTransaction trans(FROM_HERE, user_share()); | 529 ReadTransaction trans(FROM_HERE, user_share()); |
| 524 | 530 |
| 525 ReadNode password_node(&trans); | 531 ReadNode password_node(&trans); |
| 526 EXPECT_EQ(BaseNode::INIT_OK, | 532 EXPECT_EQ(BaseNode::INIT_OK, |
| 527 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); | 533 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); |
| 528 const sync_pb::PasswordSpecificsData& data = | 534 const sync_pb::PasswordSpecificsData& data = |
| 529 password_node.GetPasswordSpecifics(); | 535 password_node.GetPasswordSpecifics(); |
| 530 EXPECT_EQ(kPasswordValue, data.password_value()); | 536 EXPECT_EQ(kPasswordValue, data.password_value()); |
| 531 // Check that nothing has appeared in the unencrypted field. | 537 // Check that when feature is disabled nothing appears in the unencrypted |
| 538 // field. |
| 532 EXPECT_FALSE(password_node.GetEntitySpecifics() | 539 EXPECT_FALSE(password_node.GetEntitySpecifics() |
| 533 .password() | 540 .password() |
| 534 .has_unencrypted_metadata()); | 541 .has_unencrypted_metadata()); |
| 535 } | 542 } |
| 536 } | 543 } |
| 537 | 544 |
| 545 TEST_F(SyncApiTest, WritePasswordAndCheckMetadata) { |
| 546 KeyParams params = {"localhost", "username", "passphrase"}; |
| 547 { |
| 548 ReadTransaction trans(FROM_HERE, user_share()); |
| 549 trans.GetCryptographer()->AddKey(params); |
| 550 } |
| 551 |
| 552 base::FeatureList::ClearInstanceForTesting(); |
| 553 base::FieldTrialList field_trial_list(nullptr); |
| 554 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 555 feature_list->InitializeFromCommandLine(kFillPasswordMetadata.name, |
| 556 std::string()); |
| 557 base::FeatureList::SetInstance(std::move(feature_list)); |
| 558 |
| 559 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
| 560 { |
| 561 WriteTransaction trans(FROM_HERE, user_share()); |
| 562 ReadNode root_node(&trans); |
| 563 root_node.InitByRootLookup(); |
| 564 |
| 565 WriteNode password_node(&trans); |
| 566 WriteNode::InitUniqueByCreationResult result = |
| 567 password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag); |
| 568 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 569 sync_pb::PasswordSpecificsData data; |
| 570 data.set_password_value(kPasswordValue); |
| 571 data.set_signon_realm(kUrl); |
| 572 password_node.SetPasswordSpecifics(data); |
| 573 } |
| 574 { |
| 575 ReadTransaction trans(FROM_HERE, user_share()); |
| 576 |
| 577 ReadNode password_node(&trans); |
| 578 EXPECT_EQ(BaseNode::INIT_OK, |
| 579 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); |
| 580 const sync_pb::PasswordSpecificsData& data = |
| 581 password_node.GetPasswordSpecifics(); |
| 582 EXPECT_EQ(kPasswordValue, data.password_value()); |
| 583 EXPECT_EQ(kUrl, password_node.GetEntitySpecifics() |
| 584 .password() |
| 585 .unencrypted_metadata() |
| 586 .url()); |
| 587 } |
| 588 } |
| 589 |
| 538 TEST_F(SyncApiTest, WriteEncryptedTitle) { | 590 TEST_F(SyncApiTest, WriteEncryptedTitle) { |
| 539 KeyParams params = {"localhost", "username", "passphrase"}; | 591 KeyParams params = {"localhost", "username", "passphrase"}; |
| 540 { | 592 { |
| 541 ReadTransaction trans(FROM_HERE, user_share()); | 593 ReadTransaction trans(FROM_HERE, user_share()); |
| 542 trans.GetCryptographer()->AddKey(params); | 594 trans.GetCryptographer()->AddKey(params); |
| 543 } | 595 } |
| 544 encryption_handler()->EnableEncryptEverything(); | 596 encryption_handler()->EnableEncryptEverything(); |
| 545 int bookmark_id; | 597 int bookmark_id; |
| 546 { | 598 { |
| 547 WriteTransaction trans(FROM_HERE, user_share()); | 599 WriteTransaction trans(FROM_HERE, user_share()); |
| (...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 const syncable::Entry* node_entry = node.GetEntry(); | 2093 const syncable::Entry* node_entry = node.GetEntry(); |
| 2042 EXPECT_TRUE(node_entry->GetIsUnsynced()); | 2094 EXPECT_TRUE(node_entry->GetIsUnsynced()); |
| 2043 } | 2095 } |
| 2044 } | 2096 } |
| 2045 | 2097 |
| 2046 // Passwords have their own handling for encryption. Verify setting a new | 2098 // Passwords have their own handling for encryption. Verify setting a new |
| 2047 // passphrase updates the data and clears the unencrypted metadta for passwords. | 2099 // passphrase updates the data and clears the unencrypted metadta for passwords. |
| 2048 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { | 2100 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { |
| 2049 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2101 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2050 sync_pb::EntitySpecifics entity_specifics; | 2102 sync_pb::EntitySpecifics entity_specifics; |
| 2103 base::FeatureList::ClearInstanceForTesting(); |
| 2104 base::FieldTrialList field_trial_list(nullptr); |
| 2105 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 2106 feature_list->InitializeFromCommandLine(kFillPasswordMetadata.name, |
| 2107 std::string()); |
| 2108 base::FeatureList::SetInstance(std::move(feature_list)); |
| 2051 { | 2109 { |
| 2052 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2110 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2053 Cryptographer* cryptographer = trans.GetCryptographer(); | 2111 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2054 sync_pb::PasswordSpecificsData data; | 2112 sync_pb::PasswordSpecificsData data; |
| 2055 data.set_password_value(kPasswordValue); | 2113 data.set_password_value(kPasswordValue); |
| 2056 entity_specifics.mutable_password() | 2114 entity_specifics.mutable_password() |
| 2057 ->mutable_unencrypted_metadata() | 2115 ->mutable_unencrypted_metadata() |
| 2058 ->set_url(kUrl); | 2116 ->set_url(kUrl); |
| 2059 cryptographer->Encrypt( | 2117 cryptographer->Encrypt( |
| 2060 data, entity_specifics.mutable_password()->mutable_encrypted()); | 2118 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2080 EXPECT_EQ(BaseNode::INIT_OK, | 2138 EXPECT_EQ(BaseNode::INIT_OK, |
| 2081 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); | 2139 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); |
| 2082 const sync_pb::PasswordSpecificsData& data = | 2140 const sync_pb::PasswordSpecificsData& data = |
| 2083 password_node.GetPasswordSpecifics(); | 2141 password_node.GetPasswordSpecifics(); |
| 2084 EXPECT_EQ(kPasswordValue, data.password_value()); | 2142 EXPECT_EQ(kPasswordValue, data.password_value()); |
| 2085 EXPECT_FALSE(password_node.GetEntitySpecifics() | 2143 EXPECT_FALSE(password_node.GetEntitySpecifics() |
| 2086 .password() | 2144 .password() |
| 2087 .has_unencrypted_metadata()); | 2145 .has_unencrypted_metadata()); |
| 2088 } | 2146 } |
| 2089 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); | 2147 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2148 |
| 2149 // Check that writing new password doesn't set the metadata. |
| 2150 const std::string tag = "newpassentity"; |
| 2151 { |
| 2152 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2153 ReadNode root_node(&trans); |
| 2154 root_node.InitByRootLookup(); |
| 2155 |
| 2156 WriteNode password_node(&trans); |
| 2157 WriteNode::InitUniqueByCreationResult result = |
| 2158 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); |
| 2159 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 2160 sync_pb::PasswordSpecificsData data; |
| 2161 data.set_password_value(kPasswordValue); |
| 2162 data.set_signon_realm(kUrl); |
| 2163 password_node.SetPasswordSpecifics(data); |
| 2164 } |
| 2165 { |
| 2166 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2167 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2168 EXPECT_TRUE(cryptographer->is_ready()); |
| 2169 ReadNode password_node(&trans); |
| 2170 EXPECT_EQ(BaseNode::INIT_OK, |
| 2171 password_node.InitByClientTagLookup(PASSWORDS, tag)); |
| 2172 const sync_pb::PasswordSpecificsData& data = |
| 2173 password_node.GetPasswordSpecifics(); |
| 2174 EXPECT_EQ(kPasswordValue, data.password_value()); |
| 2175 EXPECT_FALSE(password_node.GetEntitySpecifics() |
| 2176 .password() |
| 2177 .has_unencrypted_metadata()); |
| 2178 } |
| 2090 } | 2179 } |
| 2091 | 2180 |
| 2092 // Passwords have their own handling for encryption. Verify it does not result | 2181 // Passwords have their own handling for encryption. Verify it does not result |
| 2093 // in unnecessary writes via ReencryptEverything. | 2182 // in unnecessary writes via ReencryptEverything. |
| 2094 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { | 2183 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { |
| 2095 std::string client_tag = "title"; | 2184 base::FeatureList::ClearInstanceForTesting(); |
| 2185 EXPECT_FALSE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
| 2186 |
| 2096 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2187 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2097 sync_pb::EntitySpecifics entity_specifics; | 2188 sync_pb::EntitySpecifics entity_specifics; |
| 2098 { | 2189 { |
| 2099 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2190 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2100 Cryptographer* cryptographer = trans.GetCryptographer(); | 2191 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2101 sync_pb::PasswordSpecificsData data; | 2192 sync_pb::PasswordSpecificsData data; |
| 2102 data.set_password_value("secret"); | 2193 data.set_password_value("secret"); |
| 2103 cryptographer->Encrypt( | 2194 cryptographer->Encrypt( |
| 2104 data, entity_specifics.mutable_password()->mutable_encrypted()); | 2195 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2105 } | 2196 } |
| 2106 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2197 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag, |
| 2107 syncable::GenerateSyncableHash(PASSWORDS, client_tag), | 2198 syncable::GenerateSyncableHash(PASSWORDS, kClientTag), |
| 2108 entity_specifics); | 2199 entity_specifics); |
| 2109 // New node shouldn't start off unsynced. | 2200 // New node shouldn't start off unsynced. |
| 2110 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2201 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2111 | 2202 |
| 2112 // Force a re-encrypt everything. Should not set is_unsynced. | 2203 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2113 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2204 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2114 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2205 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2115 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2206 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2116 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 2207 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 2117 sync_manager_.GetEncryptionHandler()->Init(); | 2208 sync_manager_.GetEncryptionHandler()->Init(); |
| 2118 PumpLoop(); | 2209 PumpLoop(); |
| 2119 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2210 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2211 } |
| 2212 |
| 2213 // Metadata filling can happen during ReencryptEverything, check that data is |
| 2214 // written when it's applicable, namely that password specifics entity is marked |
| 2215 // unsynced, when data was written to the unencrypted metadata field. |
| 2216 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverythingFillMetadata) { |
| 2217 base::FeatureList::ClearInstanceForTesting(); |
| 2218 base::FieldTrialList field_trial_list(nullptr); |
| 2219 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 2220 feature_list->InitializeFromCommandLine(kFillPasswordMetadata.name, |
| 2221 std::string()); |
| 2222 base::FeatureList::SetInstance(std::move(feature_list)); |
| 2223 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
| 2224 |
| 2225 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2226 sync_pb::EntitySpecifics entity_specifics; |
| 2227 { |
| 2228 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2229 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2230 sync_pb::PasswordSpecificsData data; |
| 2231 data.set_password_value("secret"); |
| 2232 data.set_signon_realm(kUrl); |
| 2233 cryptographer->Encrypt( |
| 2234 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2235 } |
| 2236 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag, |
| 2237 syncable::GenerateSyncableHash(PASSWORDS, kClientTag), |
| 2238 entity_specifics); |
| 2239 // New node shouldn't start off unsynced. |
| 2240 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2241 |
| 2242 // Force a re-encrypt everything. Should set is_unsynced. |
| 2243 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2244 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2245 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2246 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 2247 sync_manager_.GetEncryptionHandler()->Init(); |
| 2248 PumpLoop(); |
| 2249 // Check that unencrypted metadata field was set. |
| 2250 { |
| 2251 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2252 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2253 EXPECT_TRUE(cryptographer->is_ready()); |
| 2254 ReadNode password_node(&trans); |
| 2255 EXPECT_EQ(BaseNode::INIT_OK, |
| 2256 password_node.InitByClientTagLookup(PASSWORDS, kClientTag)); |
| 2257 EXPECT_EQ(kUrl, password_node.GetEntitySpecifics() |
| 2258 .password() |
| 2259 .unencrypted_metadata() |
| 2260 .url()); |
| 2261 } |
| 2262 |
| 2263 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2264 } |
| 2265 |
| 2266 // Check that when the data in PasswordSpecifics hasn't changed during |
| 2267 // ReEncryption, entity is not marked as unsynced. |
| 2268 TEST_F(SyncManagerTest, |
| 2269 UpdatePasswordReencryptEverythingDontMarkUnsyncWhenNotNeeded) { |
| 2270 base::FeatureList::ClearInstanceForTesting(); |
| 2271 base::FieldTrialList field_trial_list(nullptr); |
| 2272 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 2273 feature_list->InitializeFromCommandLine(kFillPasswordMetadata.name, |
| 2274 std::string()); |
| 2275 base::FeatureList::SetInstance(std::move(feature_list)); |
| 2276 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
| 2277 |
| 2278 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2279 sync_pb::EntitySpecifics entity_specifics; |
| 2280 { |
| 2281 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2282 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2283 sync_pb::PasswordSpecificsData data; |
| 2284 data.set_password_value("secret"); |
| 2285 data.set_signon_realm(kUrl); |
| 2286 cryptographer->Encrypt( |
| 2287 data, entity_specifics.mutable_password()->mutable_encrypted()); |
| 2288 } |
| 2289 entity_specifics.mutable_password()->mutable_unencrypted_metadata()->set_url( |
| 2290 kUrl); |
| 2291 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag, |
| 2292 syncable::GenerateSyncableHash(PASSWORDS, kClientTag), |
| 2293 entity_specifics); |
| 2294 // New node shouldn't start off unsynced. |
| 2295 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2296 |
| 2297 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2298 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2299 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2300 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2301 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 2302 sync_manager_.GetEncryptionHandler()->Init(); |
| 2303 PumpLoop(); |
| 2304 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
| 2120 } | 2305 } |
| 2121 | 2306 |
| 2122 // Test that attempting to start up with corrupted password data triggers | 2307 // Test that attempting to start up with corrupted password data triggers |
| 2123 // an unrecoverable error (rather than crashing). | 2308 // an unrecoverable error (rather than crashing). |
| 2124 TEST_F(SyncManagerTest, ReencryptEverythingWithUnrecoverableErrorPasswords) { | 2309 TEST_F(SyncManagerTest, ReencryptEverythingWithUnrecoverableErrorPasswords) { |
| 2125 const char kClientTag[] = "client_tag"; | 2310 const char kClientTag[] = "client_tag"; |
| 2126 | 2311 |
| 2127 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2312 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2128 sync_pb::EntitySpecifics entity_specifics; | 2313 sync_pb::EntitySpecifics entity_specifics; |
| 2129 { | 2314 { |
| (...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3351 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3536 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3352 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3537 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3353 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3538 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3354 // task is to ensure that SyncManagerImpl reported initialization failure in | 3539 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3355 // OnInitializationComplete callback. | 3540 // OnInitializationComplete callback. |
| 3356 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3541 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3357 EXPECT_FALSE(initialization_succeeded_); | 3542 EXPECT_FALSE(initialization_succeeded_); |
| 3358 } | 3543 } |
| 3359 | 3544 |
| 3360 } // namespace syncer | 3545 } // namespace syncer |
| OLD | NEW |