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

Unified Diff: components/sync/core_impl/sync_manager_impl_unittest.cc

Issue 2278333002: Supplimentary identifier for passwords specific (Closed)
Patch Set: cleanup Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/sync/core_impl/sync_manager_impl_unittest.cc
diff --git a/components/sync/core_impl/sync_manager_impl_unittest.cc b/components/sync/core_impl/sync_manager_impl_unittest.cc
index 3c0f595bfdfc1ae8b52905ef0f3ea2978250d215..d731e43164933753ec96c977a4dff341fa654e46 100644
--- a/components/sync/core_impl/sync_manager_impl_unittest.cc
+++ b/components/sync/core_impl/sync_manager_impl_unittest.cc
@@ -222,6 +222,10 @@ int GetTotalNodeCount(UserShare* share, int64_t root) {
return node.GetTotalNodeCount();
}
+const char kUrl[] = "example.com";
+const char kPasswordValue[] = "secret";
+const char kClientTag[] = "tag";
+
} // namespace
class SyncApiTest : public testing::Test {
@@ -518,21 +522,65 @@ TEST_F(SyncApiTest, WriteAndReadPassword) {
WriteNode password_node(&trans);
WriteNode::InitUniqueByCreationResult result =
- password_node.InitUniqueByCreation(PASSWORDS, root_node, "foo");
+ password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag);
EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
sync_pb::PasswordSpecificsData data;
- data.set_password_value("secret");
- password_node.SetPasswordSpecifics(data);
+ data.set_password_value(kPasswordValue);
+ password_node.SetPasswordSpecifics(data, GetPassphraseType(&trans));
}
{
ReadTransaction trans(FROM_HERE, user_share());
ReadNode password_node(&trans);
EXPECT_EQ(BaseNode::INIT_OK,
- password_node.InitByClientTagLookup(PASSWORDS, "foo"));
+ password_node.InitByClientTagLookup(PASSWORDS, kClientTag));
const sync_pb::PasswordSpecificsData& data =
password_node.GetPasswordSpecifics();
- EXPECT_EQ("secret", data.password_value());
+ EXPECT_EQ(kPasswordValue, data.password_value());
+ // Check that nothing has appeared in the unencrypted field.
+ EXPECT_FALSE(password_node.GetEntitySpecifics()
+ .password()
+ .has_unencrypted_metadata());
+ }
+}
+
+TEST_F(SyncApiTest, WriteDoesntChangeUnencryptedPasswordMetadata) {
+ KeyParams params = {"localhost", "username", "passphrase"};
+ {
+ ReadTransaction trans(FROM_HERE, user_share());
+ trans.GetCryptographer()->AddKey(params);
+ }
+ {
+ WriteTransaction trans(FROM_HERE, user_share());
+ ReadNode root_node(&trans);
+ root_node.InitByRootLookup();
+
+ WriteNode password_node(&trans);
+ WriteNode::InitUniqueByCreationResult result =
+ password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag);
+ EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
+ sync_pb::EntitySpecifics entity_specifics;
+ sync_pb::PasswordSpecifics* password_specifics =
+ entity_specifics.mutable_password();
+ password_specifics->mutable_unencrypted_metadata()->set_url(kUrl);
+ password_node.SetEntitySpecifics(entity_specifics);
+ sync_pb::PasswordSpecificsData data;
+ data.set_password_value(kPasswordValue);
+ password_node.SetPasswordSpecifics(data, GetPassphraseType(&trans));
+ }
+ {
+ ReadTransaction trans(FROM_HERE, user_share());
+
+ ReadNode password_node(&trans);
+ EXPECT_EQ(BaseNode::INIT_OK,
+ password_node.InitByClientTagLookup(PASSWORDS, kClientTag));
+ const sync_pb::PasswordSpecificsData& data =
+ password_node.GetPasswordSpecifics();
+ EXPECT_EQ(kUrl, password_node.GetEntitySpecifics()
+ .password()
+ .unencrypted_metadata()
+ .url());
+ EXPECT_EQ(kPasswordValue, data.password_value());
}
}
@@ -842,7 +890,8 @@ TEST_F(SyncApiTest, WriteNode_PasswordUniqueByCreationAfterDelete) {
ASSERT_EQ(WriteNode::INIT_SUCCESS, result);
sync_pb::PasswordSpecificsData password_specifics;
password_specifics.set_password_value("secret");
- password_node.SetPasswordSpecifics(password_specifics);
+ password_node.SetPasswordSpecifics(password_specifics,
+ GetPassphraseType(&trans));
}
// Delete password.
{
@@ -1457,7 +1506,8 @@ TEST_F(SyncManagerTest, SetPassphraseWithPassword) {
EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
sync_pb::PasswordSpecificsData data;
data.set_password_value("secret");
- password_node.SetPasswordSpecifics(data);
+ password_node.SetPasswordSpecifics(data,
+ GetPassphraseTypeWithTrans(&trans));
}
EXPECT_CALL(encryption_observer_,
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
@@ -2040,7 +2090,8 @@ TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) {
WriteNode node(&trans);
EXPECT_EQ(BaseNode::INIT_OK,
node.InitByClientTagLookup(PASSWORDS, client_tag));
- node.SetPasswordSpecifics(node.GetPasswordSpecifics());
+ node.SetPasswordSpecifics(node.GetPasswordSpecifics(),
+ GetPassphraseTypeWithTrans(&trans));
}
EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
@@ -2055,7 +2106,7 @@ TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) {
data.set_password_value("secret2");
cryptographer->Encrypt(
data, entity_specifics.mutable_password()->mutable_encrypted());
- node.SetPasswordSpecifics(data);
+ node.SetPasswordSpecifics(data, GetPassphraseTypeWithTrans(&trans));
const syncable::Entry* node_entry = node.GetEntry();
EXPECT_TRUE(node_entry->GetIsUnsynced());
}
@@ -2064,51 +2115,70 @@ TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) {
// Passwords have their own handling for encryption. Verify setting a new
// passphrase updates the data.
TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) {
- std::string client_tag = "title";
EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
sync_pb::EntitySpecifics entity_specifics;
{
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
Cryptographer* cryptographer = trans.GetCryptographer();
sync_pb::PasswordSpecificsData data;
- data.set_password_value("secret");
+ data.set_password_value(kPasswordValue);
+ entity_specifics.mutable_password()
+ ->mutable_unencrypted_metadata()
+ ->set_url(kUrl);
cryptographer->Encrypt(
data, entity_specifics.mutable_password()->mutable_encrypted());
}
- MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag,
- syncable::GenerateSyncableHash(PASSWORDS, client_tag),
+ EXPECT_TRUE(entity_specifics.password().has_unencrypted_metadata());
+ MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag,
+ syncable::GenerateSyncableHash(PASSWORDS, kClientTag),
entity_specifics);
// New node shouldn't start off unsynced.
- EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
+ EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag));
// Set a new passphrase. Should set is_unsynced.
testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
+
EXPECT_CALL(encryption_observer_,
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
ExpectPassphraseAcceptance();
SetCustomPassphraseAndCheck("new_passphrase");
- EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag));
+ {
+ ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
+ Cryptographer* cryptographer = trans.GetCryptographer();
+ EXPECT_TRUE(cryptographer->is_ready());
+ ReadNode password_node(&trans);
+ EXPECT_EQ(BaseNode::INIT_OK,
+ password_node.InitByClientTagLookup(PASSWORDS, kClientTag));
+ const sync_pb::PasswordSpecificsData& data =
+ password_node.GetPasswordSpecifics();
+ EXPECT_EQ(kPasswordValue, data.password_value());
+ EXPECT_FALSE(password_node.GetEntitySpecifics()
+ .password()
+ .has_unencrypted_metadata());
+ }
+ EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, kClientTag));
}
// Passwords have their own handling for encryption. Verify it does not result
// in unnecessary writes via ReencryptEverything.
TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) {
- std::string client_tag = "title";
EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
sync_pb::EntitySpecifics entity_specifics;
{
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
Cryptographer* cryptographer = trans.GetCryptographer();
sync_pb::PasswordSpecificsData data;
- data.set_password_value("secret");
+ data.set_password_value(kPasswordValue);
cryptographer->Encrypt(
data, entity_specifics.mutable_password()->mutable_encrypted());
}
- MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag,
- syncable::GenerateSyncableHash(PASSWORDS, client_tag),
+ entity_specifics.mutable_password()->mutable_unencrypted_metadata()->set_url(
+ kUrl);
+ MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag,
+ syncable::GenerateSyncableHash(PASSWORDS, kClientTag),
entity_specifics);
// New node shouldn't start off unsynced.
- EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
+ EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag));
// Force a re-encrypt everything. Should not set is_unsynced.
testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
@@ -2117,7 +2187,7 @@ TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) {
EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false));
sync_manager_.GetEncryptionHandler()->Init();
PumpLoop();
- EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
+ EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag));
}
// Test that attempting to start up with corrupted password data triggers

Powered by Google App Engine
This is Rietveld 408576698