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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 5 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_encryption_handler_impl_unittest.cc
diff --git a/sync/internal_api/sync_encryption_handler_impl_unittest.cc b/components/sync/core_impl/sync_encryption_handler_impl_unittest.cc
similarity index 79%
rename from sync/internal_api/sync_encryption_handler_impl_unittest.cc
rename to components/sync/core_impl/sync_encryption_handler_impl_unittest.cc
index 730116106a8190f6046243da6daae4353724651f..1c07bb5719f741b69853f49f2e614367b9acb105 100644
--- a/sync/internal_api/sync_encryption_handler_impl_unittest.cc
+++ b/components/sync/core_impl/sync_encryption_handler_impl_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/internal_api/sync_encryption_handler_impl.h"
+#include "components/sync/core_impl/sync_encryption_handler_impl.h"
#include <stdint.h>
@@ -13,20 +13,20 @@
#include "base/json/json_string_value_serializer.h"
#include "base/run_loop.h"
#include "base/tracked_objects.h"
-#include "sync/internal_api/public/base/model_type_test_util.h"
-#include "sync/internal_api/public/read_node.h"
-#include "sync/internal_api/public/read_transaction.h"
-#include "sync/internal_api/public/test/test_user_share.h"
-#include "sync/internal_api/public/write_node.h"
-#include "sync/internal_api/public/write_transaction.h"
-#include "sync/protocol/nigori_specifics.pb.h"
-#include "sync/protocol/sync.pb.h"
-#include "sync/syncable/entry.h"
-#include "sync/syncable/mutable_entry.h"
-#include "sync/syncable/syncable_write_transaction.h"
-#include "sync/test/engine/test_id_factory.h"
-#include "sync/test/fake_encryptor.h"
-#include "sync/util/cryptographer.h"
+#include "components/sync/base/cryptographer.h"
+#include "components/sync/base/model_type_test_util.h"
+#include "components/sync/core/read_node.h"
+#include "components/sync/core/read_transaction.h"
+#include "components/sync/core/test/test_user_share.h"
+#include "components/sync/core/write_node.h"
+#include "components/sync/core/write_transaction.h"
+#include "components/sync/protocol/nigori_specifics.pb.h"
+#include "components/sync/protocol/sync.pb.h"
+#include "components/sync/syncable/entry.h"
+#include "components/sync/syncable/mutable_entry.h"
+#include "components/sync/syncable/syncable_write_transaction.h"
+#include "components/sync/test/engine/test_id_factory.h"
+#include "components/sync/test/fake_encryptor.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -52,15 +52,15 @@ class SyncEncryptionHandlerObserverMock
MOCK_METHOD2(OnPassphraseRequired,
void(PassphraseRequiredReason,
const sync_pb::EncryptedData&)); // NOLINT
- MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT
+ MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT
MOCK_METHOD2(OnBootstrapTokenUpdated,
void(const std::string&, BootstrapTokenType type)); // NOLINT
- MOCK_METHOD2(OnEncryptedTypesChanged,
- void(ModelTypeSet, bool)); // NOLINT
- MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT
+ MOCK_METHOD2(OnEncryptedTypesChanged, void(ModelTypeSet, bool)); // NOLINT
+ MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT
MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT
- MOCK_METHOD2(OnPassphraseTypeChanged, void(PassphraseType,
- base::Time)); // NOLINT
+ MOCK_METHOD2(OnPassphraseTypeChanged,
+ void(PassphraseType,
+ base::Time)); // NOLINT
MOCK_METHOD1(OnLocalSetPassphraseEncryption,
void(const SyncEncryptionHandler::NigoriState&)); // NOLINT
};
@@ -109,11 +109,8 @@ class SyncEncryptionHandlerImplTest : public ::testing::Test {
std::string tag_name = ModelTypeToRootTag(model_type);
syncable::WriteTransaction wtrans(FROM_HERE, syncable::UNITTEST, directory);
- syncable::MutableEntry node(&wtrans,
- syncable::CREATE,
- model_type,
- wtrans.root_id(),
- tag_name);
+ syncable::MutableEntry node(&wtrans, syncable::CREATE, model_type,
+ wtrans.root_id(), tag_name);
node.PutUniqueServerTag(tag_name);
node.PutIsDir(true);
node.PutServerIsDir(false);
@@ -128,14 +125,12 @@ class SyncEncryptionHandlerImplTest : public ::testing::Test {
node.PutSpecifics(specifics);
}
- void PumpLoop() {
- base::RunLoop().RunUntilIdle();
- }
+ void PumpLoop() { base::RunLoop().RunUntilIdle(); }
// Getters for tests.
UserShare* user_share() { return test_user_share_.user_share(); }
SyncEncryptionHandlerImpl* encryption_handler() {
- return encryption_handler_.get();
+ return encryption_handler_.get();
}
SyncEncryptionHandlerObserverMock* observer() { return &observer_; }
Cryptographer* GetCryptographer() {
@@ -167,9 +162,9 @@ class SyncEncryptionHandlerImplTest : public ::testing::Test {
EXPECT_EQ(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE,
nigori.passphrase_type());
if (!encryption_handler()->custom_passphrase_time().is_null()) {
- EXPECT_EQ(nigori.custom_passphrase_time(),
- TimeToProtoTime(
- encryption_handler()->custom_passphrase_time()));
+ EXPECT_EQ(
+ nigori.custom_passphrase_time(),
+ TimeToProtoTime(encryption_handler()->custom_passphrase_time()));
}
} else {
EXPECT_EQ(sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE,
@@ -221,18 +216,16 @@ class SyncEncryptionHandlerImplTest : public ::testing::Test {
if (passphrase_type == KEYSTORE_PASSPHRASE) {
sync_pb::EncryptedData keystore_decryptor_token;
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- keystore_key,
- &keystore_decryptor_token));
+ other_cryptographer, keystore_key, &keystore_decryptor_token));
nigori.mutable_keystore_decryptor_token()->CopyFrom(
keystore_decryptor_token);
nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
} else {
nigori.set_encrypt_everything(true);
nigori.set_passphrase_type(
- passphrase_type == CUSTOM_PASSPHRASE ?
- sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE :
- sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE);
+ passphrase_type == CUSTOM_PASSPHRASE
+ ? sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE
+ : sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE);
}
return nigori;
}
@@ -246,24 +239,18 @@ class SyncEncryptionHandlerImplTest : public ::testing::Test {
WriteTransaction trans(FROM_HERE, user_share());
WriteNode nigori_node(&trans);
ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK);
- sync_pb::NigoriSpecifics nigori = BuildMigratedNigori(
- KEYSTORE_PASSPHRASE,
- migration_time,
- default_passphrase,
- keystore_key);
+ sync_pb::NigoriSpecifics nigori =
+ BuildMigratedNigori(KEYSTORE_PASSPHRASE, migration_time,
+ default_passphrase, keystore_key);
nigori_node.SetNigoriSpecifics(nigori);
}
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AtLeast(1));
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete()).Times(AtLeast(1));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AtLeast(1));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnEncryptionComplete()).Times(AtLeast(1));
encryption_handler()->Init();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
@@ -280,21 +267,15 @@ class SyncEncryptionHandlerImplTest : public ::testing::Test {
WriteNode nigori_node(&trans);
ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK);
sync_pb::NigoriSpecifics nigori = BuildMigratedNigori(
- CUSTOM_PASSPHRASE,
- migration_time,
- default_passphrase,
- kKeystoreKey);
+ CUSTOM_PASSPHRASE, migration_time, default_passphrase, kKeystoreKey);
nigori_node.SetNigoriSpecifics(nigori);
}
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AtLeast(1));
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true)).Times(AtLeast(1));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete()).Times(AtLeast(1));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AtLeast(1));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true))
+ .Times(AtLeast(1));
+ EXPECT_CALL(*observer(), OnEncryptionComplete()).Times(AtLeast(1));
encryption_handler()->Init();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE);
@@ -323,13 +304,10 @@ class SyncEncryptionHandlerImplTest : public ::testing::Test {
}
if (passphrase_type != IMPLICIT_PASSPHRASE) {
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(passphrase_type, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(passphrase_type, _));
}
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AtLeast(1));
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AtLeast(1));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
encryption_handler()->Init();
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
EXPECT_EQ(encryption_handler()->GetPassphraseType(), passphrase_type);
@@ -387,12 +365,10 @@ TEST_F(SyncEncryptionHandlerImplTest, NigoriEncryptionTypes) {
ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes());
{
WriteTransaction trans(FROM_HERE, user_share());
- encryption_handler()->MergeEncryptedTypes(
- encrypted_types,
- trans.GetWrappedTrans());
+ encryption_handler()->MergeEncryptedTypes(encrypted_types,
+ trans.GetWrappedTrans());
encryption_handler()->UpdateNigoriFromEncryptedTypes(
- &nigori,
- trans.GetWrappedTrans());
+ &nigori, trans.GetWrappedTrans());
handler2.UpdateEncryptedTypesFromNigori(nigori, trans.GetWrappedTrans());
}
EXPECT_EQ(encrypted_types, encryption_handler()->GetEncryptedTypesUnsafe());
@@ -403,23 +379,19 @@ TEST_F(SyncEncryptionHandlerImplTest, NigoriEncryptionTypes) {
ModelTypeSet encrypted_user_types = EncryptableUserTypes();
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(
- HasModelTypes(encrypted_user_types), false));
- EXPECT_CALL(observer2,
- OnEncryptedTypesChanged(
- HasModelTypes(encrypted_user_types), false));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(
+ HasModelTypes(encrypted_user_types), false));
+ EXPECT_CALL(observer2, OnEncryptedTypesChanged(
+ HasModelTypes(encrypted_user_types), false));
// Set all encrypted types
encrypted_types = EncryptableUserTypes();
{
WriteTransaction trans(FROM_HERE, user_share());
- encryption_handler()->MergeEncryptedTypes(
- encrypted_types,
- trans.GetWrappedTrans());
+ encryption_handler()->MergeEncryptedTypes(encrypted_types,
+ trans.GetWrappedTrans());
encryption_handler()->UpdateNigoriFromEncryptedTypes(
- &nigori,
- trans.GetWrappedTrans());
+ &nigori, trans.GetWrappedTrans());
handler2.UpdateEncryptedTypesFromNigori(nigori, trans.GetWrappedTrans());
}
EXPECT_EQ(encrypted_types, encryption_handler()->GetEncryptedTypesUnsafe());
@@ -443,9 +415,8 @@ TEST_F(SyncEncryptionHandlerImplTest, EncryptEverythingExplicit) {
sync_pb::NigoriSpecifics nigori;
nigori.set_encrypt_everything(true);
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(
- HasModelTypes(EncryptableUserTypes()), true));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(
+ HasModelTypes(EncryptableUserTypes()), true));
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
ModelTypeSet encrypted_types =
@@ -455,8 +426,7 @@ TEST_F(SyncEncryptionHandlerImplTest, EncryptEverythingExplicit) {
{
WriteTransaction trans(FROM_HERE, user_share());
encryption_handler()->UpdateEncryptedTypesFromNigori(
- nigori,
- trans.GetWrappedTrans());
+ nigori, trans.GetWrappedTrans());
}
EXPECT_TRUE(encryption_handler()->IsEncryptEverythingEnabled());
@@ -468,8 +438,7 @@ TEST_F(SyncEncryptionHandlerImplTest, EncryptEverythingExplicit) {
{
WriteTransaction trans(FROM_HERE, user_share());
encryption_handler()->UpdateEncryptedTypesFromNigori(
- nigori,
- trans.GetWrappedTrans());
+ nigori, trans.GetWrappedTrans());
}
}
@@ -479,9 +448,8 @@ TEST_F(SyncEncryptionHandlerImplTest, EncryptEverythingImplicit) {
sync_pb::NigoriSpecifics nigori;
nigori.set_encrypt_bookmarks(true); // Non-passwords = encrypt everything
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(
- HasModelTypes(EncryptableUserTypes()), true));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(
+ HasModelTypes(EncryptableUserTypes()), true));
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
ModelTypeSet encrypted_types =
@@ -491,8 +459,7 @@ TEST_F(SyncEncryptionHandlerImplTest, EncryptEverythingImplicit) {
{
WriteTransaction trans(FROM_HERE, user_share());
encryption_handler()->UpdateEncryptedTypesFromNigori(
- nigori,
- trans.GetWrappedTrans());
+ nigori, trans.GetWrappedTrans());
}
EXPECT_TRUE(encryption_handler()->IsEncryptEverythingEnabled());
@@ -506,8 +473,7 @@ TEST_F(SyncEncryptionHandlerImplTest, EncryptEverythingImplicit) {
{
WriteTransaction trans(FROM_HERE, user_share());
encryption_handler()->UpdateEncryptedTypesFromNigori(
- nigori,
- trans.GetWrappedTrans());
+ nigori, trans.GetWrappedTrans());
}
}
@@ -523,9 +489,8 @@ TEST_F(SyncEncryptionHandlerImplTest, UnknownSensitiveTypes) {
SyncEncryptionHandler::SensitiveTypes();
expected_encrypted_types.Put(BOOKMARKS);
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(
- HasModelTypes(expected_encrypted_types), false));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(
+ HasModelTypes(expected_encrypted_types), false));
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
ModelTypeSet encrypted_types =
@@ -535,8 +500,7 @@ TEST_F(SyncEncryptionHandlerImplTest, UnknownSensitiveTypes) {
{
WriteTransaction trans(FROM_HERE, user_share());
encryption_handler()->UpdateEncryptedTypesFromNigori(
- nigori,
- trans.GetWrappedTrans());
+ nigori, trans.GetWrappedTrans());
}
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
@@ -557,9 +521,8 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveOldNigori) {
other_cryptographer.AddKey(old_key);
sync_pb::EntitySpecifics other_encrypted_specifics;
other_encrypted_specifics.mutable_bookmark()->set_title("title");
- other_cryptographer.Encrypt(
- other_encrypted_specifics,
- other_encrypted_specifics.mutable_encrypted());
+ other_cryptographer.Encrypt(other_encrypted_specifics,
+ other_encrypted_specifics.mutable_encrypted());
sync_pb::EntitySpecifics our_encrypted_specifics;
our_encrypted_specifics.mutable_bookmark()->set_title("title2");
ModelTypeSet encrypted_types = EncryptableUserTypes();
@@ -569,22 +532,20 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveOldNigori) {
sync_pb::NigoriSpecifics current_nigori_specifics;
GetCryptographer()->AddKey(old_key);
GetCryptographer()->AddKey(current_key);
- GetCryptographer()->Encrypt(
- our_encrypted_specifics,
- our_encrypted_specifics.mutable_encrypted());
+ GetCryptographer()->Encrypt(our_encrypted_specifics,
+ our_encrypted_specifics.mutable_encrypted());
GetCryptographer()->GetKeys(
current_nigori_specifics.mutable_encryption_keybag());
current_nigori_specifics.set_encrypt_everything(true);
EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(), OnEncryptedTypesChanged(
- HasModelTypes(EncryptableUserTypes()), true));
+ HasModelTypes(EncryptableUserTypes()), true));
{
// Update the encryption handler.
WriteTransaction trans(FROM_HERE, user_share());
- encryption_handler()->ApplyNigoriUpdate(
- current_nigori_specifics,
- trans.GetWrappedTrans());
+ encryption_handler()->ApplyNigoriUpdate(current_nigori_specifics,
+ trans.GetWrappedTrans());
}
Mock::VerifyAndClearExpectations(observer());
@@ -597,9 +558,8 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveOldNigori) {
{
// Update the encryption handler.
WriteTransaction trans(FROM_HERE, user_share());
- encryption_handler()->ApplyNigoriUpdate(
- old_nigori,
- trans.GetWrappedTrans());
+ encryption_handler()->ApplyNigoriUpdate(old_nigori,
+ trans.GetWrappedTrans());
}
EXPECT_TRUE(GetCryptographer()->is_ready());
EXPECT_FALSE(GetCryptographer()->has_pending_keys());
@@ -619,13 +579,12 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveOldNigori) {
const sync_pb::NigoriSpecifics& nigori = nigori_node.GetNigoriSpecifics();
EXPECT_TRUE(GetCryptographer()->CanDecryptUsingDefaultKey(
our_encrypted_specifics.encrypted()));
- EXPECT_TRUE(GetCryptographer()->CanDecrypt(
- other_encrypted_specifics.encrypted()));
+ EXPECT_TRUE(
+ GetCryptographer()->CanDecrypt(other_encrypted_specifics.encrypted()));
EXPECT_TRUE(GetCryptographer()->CanDecrypt(nigori.encryption_keybag()));
EXPECT_TRUE(nigori.encrypt_everything());
- EXPECT_TRUE(
- GetCryptographer()->CanDecryptUsingDefaultKey(
- nigori.encryption_keybag()));
+ EXPECT_TRUE(GetCryptographer()->CanDecryptUsingDefaultKey(
+ nigori.encryption_keybag()));
}
EXPECT_TRUE(encryption_handler()->IsEncryptEverythingEnabled());
}
@@ -663,16 +622,12 @@ TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreMigratesAndUpdatesBootstrap) {
EXPECT_CALL(*observer(), OnCryptographerStateChanged(_));
EXPECT_CALL(*observer(), OnPassphraseAccepted());
EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnBootstrapTokenUpdated(_,
- KEYSTORE_BOOTSTRAP_TOKEN)).
- WillOnce(SaveArg<0>(&keystore_bootstrap));
+ EXPECT_CALL(*observer(), OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN))
+ .WillOnce(SaveArg<0>(&keystore_bootstrap));
{
WriteTransaction trans(FROM_HERE, user_share());
EXPECT_TRUE(
- encryption_handler()->SetKeystoreKeys(
- keys,
- trans.GetWrappedTrans()));
+ encryption_handler()->SetKeystoreKeys(keys, trans.GetWrappedTrans()));
EXPECT_FALSE(
encryption_handler()->NeedKeystoreKey(trans.GetWrappedTrans()));
EXPECT_FALSE(GetCryptographer()->is_initialized());
@@ -686,9 +641,8 @@ TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreMigratesAndUpdatesBootstrap) {
std::string decoded_bootstrap;
ASSERT_TRUE(base::Base64Decode(keystore_bootstrap, &decoded_bootstrap));
std::string decrypted_bootstrap;
- ASSERT_TRUE(
- GetCryptographer()->encryptor()->DecryptString(decoded_bootstrap,
- &decrypted_bootstrap));
+ ASSERT_TRUE(GetCryptographer()->encryptor()->DecryptString(
+ decoded_bootstrap, &decrypted_bootstrap));
JSONStringValueDeserializer json(decrypted_bootstrap);
std::unique_ptr<base::Value> deserialized_keystore_keys(
json.Deserialize(NULL, NULL));
@@ -703,7 +657,6 @@ TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreMigratesAndUpdatesBootstrap) {
keystore_list->GetString(1, &test_string);
ASSERT_EQ(kKeystoreKey, test_string);
-
// Now make sure a new encryption handler can correctly parse the bootstrap
// token.
SyncEncryptionHandlerImpl handler2(user_share(), &encryptor_,
@@ -727,14 +680,10 @@ TEST_F(SyncEncryptionHandlerImplTest, GetKeystoreDecryptor) {
other_cryptographer.AddKey(cur_key);
EXPECT_TRUE(other_cryptographer.is_ready());
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
- &encrypted));
+ other_cryptographer, kKeystoreKey, &encrypted));
std::string serialized = encrypted.SerializeAsString();
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
- &encrypted));
+ other_cryptographer, kKeystoreKey, &encrypted));
EXPECT_EQ(serialized, encrypted.SerializeAsString());
}
@@ -747,9 +696,8 @@ TEST_F(SyncEncryptionHandlerImplTest, MigrateOnDecryptImplicitPass) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
Mock::VerifyAndClearExpectations(observer());
}
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
@@ -766,10 +714,8 @@ TEST_F(SyncEncryptionHandlerImplTest, MigrateOnDecryptImplicitPass) {
other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
nigori.set_keybag_is_frozen(false);
nigori.set_encrypt_everything(false);
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
nigori_node.SetNigoriSpecifics(nigori);
}
@@ -778,16 +724,12 @@ TEST_F(SyncEncryptionHandlerImplTest, MigrateOnDecryptImplicitPass) {
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
Mock::VerifyAndClearExpectations(observer());
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
encryption_handler()->SetDecryptionPassphrase(kOtherKey);
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
@@ -804,9 +746,8 @@ TEST_F(SyncEncryptionHandlerImplTest, MigrateOnDecryptCustomPass) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
Mock::VerifyAndClearExpectations(observer());
}
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
@@ -823,12 +764,9 @@ TEST_F(SyncEncryptionHandlerImplTest, MigrateOnDecryptCustomPass) {
other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
nigori.set_keybag_is_frozen(true);
nigori.set_encrypt_everything(false);
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
nigori_node.SetNigoriSpecifics(nigori);
}
@@ -837,21 +775,17 @@ TEST_F(SyncEncryptionHandlerImplTest, MigrateOnDecryptCustomPass) {
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
Mock::VerifyAndClearExpectations(observer());
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
std::string captured_bootstrap_token;
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
.WillOnce(testing::SaveArg<0>(&captured_bootstrap_token));
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete()).Times(2);
+ EXPECT_CALL(*observer(), OnEncryptionComplete()).Times(2);
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
encryption_handler()->SetDecryptionPassphrase(kOtherKey);
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
@@ -871,33 +805,26 @@ TEST_F(SyncEncryptionHandlerImplTest, MigrateOnKeystoreKeyAvailableImplicit) {
const char kCurKey[] = "cur";
KeyParams current_key = {"localhost", "dummy", kCurKey};
GetCryptographer()->AddKey(current_key);
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->Init();
Mock::VerifyAndClearExpectations(observer());
{
ReadTransaction trans(FROM_HERE, user_share());
// Once we provide a keystore key, we should perform the migration.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
// The actual migration gets posted, so run all pending tasks.
PumpLoop();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
- EXPECT_EQ(KEYSTORE_PASSPHRASE,
- encryption_handler()->GetPassphraseType());
+ EXPECT_EQ(KEYSTORE_PASSPHRASE, encryption_handler()->GetPassphraseType());
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey);
}
@@ -910,33 +837,26 @@ TEST_F(SyncEncryptionHandlerImplTest,
const char kCurKey[] = "cur";
KeyParams current_key = {"localhost", "dummy", kCurKey};
GetCryptographer()->AddKey(current_key);
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->Init();
Mock::VerifyAndClearExpectations(observer());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->EnableEncryptEverything();
{
ReadTransaction trans(FROM_HERE, user_share());
// Once we provide a keystore key, we should perform the migration.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
EXPECT_CALL(*observer(),
OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE, _));
@@ -968,18 +888,12 @@ TEST_F(SyncEncryptionHandlerImplTest,
TEST_F(SyncEncryptionHandlerImplTest,
MigrateOnKeystoreKeyAvailableCustomWithEncryption) {
const char kCurKey[] = "cur";
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
std::string captured_bootstrap_token;
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
@@ -989,10 +903,8 @@ TEST_F(SyncEncryptionHandlerImplTest,
EXPECT_FALSE(encryption_handler()->custom_passphrase_time().is_null());
Mock::VerifyAndClearExpectations(observer());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->EnableEncryptEverything();
Mock::VerifyAndClearExpectations(observer());
@@ -1000,15 +912,13 @@ TEST_F(SyncEncryptionHandlerImplTest,
{
ReadTransaction trans(FROM_HERE, user_share());
// Once we provide a keystore key, we should perform the migration.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
// The actual migration gets posted, so run all pending tasks.
@@ -1017,8 +927,7 @@ TEST_F(SyncEncryptionHandlerImplTest,
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
const base::Time migration_time = encryption_handler()->migration_time();
- EXPECT_EQ(CUSTOM_PASSPHRASE,
- encryption_handler()->GetPassphraseType());
+ EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType());
EXPECT_TRUE(encryption_handler()->IsEncryptEverythingEnabled());
VerifyMigratedNigori(CUSTOM_PASSPHRASE, kCurKey);
@@ -1033,18 +942,12 @@ TEST_F(SyncEncryptionHandlerImplTest,
TEST_F(SyncEncryptionHandlerImplTest,
MigrateOnKeystoreKeyAvailableCustomNoEncryption) {
const char kCurKey[] = "cur";
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
std::string captured_bootstrap_token;
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
@@ -1057,27 +960,22 @@ TEST_F(SyncEncryptionHandlerImplTest,
{
ReadTransaction trans(FROM_HERE, user_share());
// Once we provide a keystore key, we should perform the migration.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
// The actual migration gets posted, so run all pending tasks.
PumpLoop();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
const base::Time migration_time = encryption_handler()->migration_time();
- EXPECT_EQ(CUSTOM_PASSPHRASE,
- encryption_handler()->GetPassphraseType());
+ EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType());
EXPECT_TRUE(encryption_handler()->IsEncryptEverythingEnabled());
VerifyMigratedNigori(CUSTOM_PASSPHRASE, kCurKey);
@@ -1097,9 +995,7 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriKeystorePass) {
other_cryptographer.AddKey(cur_key);
EXPECT_TRUE(other_cryptographer.is_ready());
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
- &keystore_decryptor_token));
+ other_cryptographer, kKeystoreKey, &keystore_decryptor_token));
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
EXPECT_FALSE(GetCryptographer()->is_ready());
EXPECT_NE(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
@@ -1124,13 +1020,10 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriKeystorePass) {
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
nigori_node.SetNigoriSpecifics(nigori);
}
@@ -1151,7 +1044,7 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriKeystorePass) {
// Check that the cryptographer can decrypt keystore key based encryption.
Cryptographer keystore_cryptographer(GetCryptographer()->encryptor());
- KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
+ KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
keystore_cryptographer.AddKey(keystore_key);
sync_pb::EncryptedData keystore_encrypted;
keystore_cryptographer.EncryptString("string", &keystore_encrypted);
@@ -1173,21 +1066,17 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriFrozenImplicitPass) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
{
EXPECT_CALL(*observer(),
OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
WriteTransaction trans(FROM_HERE, user_share());
WriteNode nigori_node(&trans);
ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK);
@@ -1213,12 +1102,9 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriFrozenImplicitPass) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
encryption_handler()->SetDecryptionPassphrase(kCurKey);
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->is_ready());
@@ -1231,7 +1117,7 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriFrozenImplicitPass) {
// Check that the cryptographer can decrypt keystore key based encryption.
Cryptographer keystore_cryptographer(GetCryptographer()->encryptor());
- KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
+ KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
keystore_cryptographer.AddKey(keystore_key);
sync_pb::EncryptedData keystore_encrypted;
keystore_cryptographer.EncryptString("string", &keystore_encrypted);
@@ -1253,21 +1139,16 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriCustomPass) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
{
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
WriteTransaction trans(FROM_HERE, user_share());
WriteNode nigori_node(&trans);
ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK);
@@ -1291,12 +1172,9 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriCustomPass) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
encryption_handler()->SetDecryptionPassphrase(kCurKey);
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->is_ready());
@@ -1309,7 +1187,7 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriCustomPass) {
// Check that the cryptographer can decrypt keystore key based encryption.
Cryptographer keystore_cryptographer(GetCryptographer()->encryptor());
- KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
+ KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
keystore_cryptographer.AddKey(keystore_key);
sync_pb::EncryptedData keystore_encrypted;
keystore_cryptographer.EncryptString("string", &keystore_encrypted);
@@ -1343,14 +1221,10 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveUnmigratedNigoriAfterMigration) {
nigori_node.SetNigoriSpecifics(nigori);
}
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true)).Times(2);
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true)).Times(2);
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->Init();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->is_ready());
@@ -1362,16 +1236,14 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveUnmigratedNigoriAfterMigration) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
Mock::VerifyAndClearExpectations(observer());
// Now build an old unmigrated nigori node with old encrypted types. We should
// properly overwrite it with the migrated + encrypt everything state.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
@@ -1434,14 +1306,10 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveOldMigratedNigori) {
nigori_node.SetNigoriSpecifics(nigori);
}
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true)).Times(2);
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true)).Times(2);
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->Init();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->is_ready());
@@ -1453,16 +1321,14 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveOldMigratedNigori) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
Mock::VerifyAndClearExpectations(observer());
// Now build an old keystore nigori node with old encrypted types. We should
// properly overwrite it with the migrated + encrypt everything state.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
@@ -1476,8 +1342,7 @@ TEST_F(SyncEncryptionHandlerImplTest, ReceiveOldMigratedNigori) {
Cryptographer other_cryptographer(GetCryptographer()->encryptor());
other_cryptographer.AddKey(old_key);
encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
+ other_cryptographer, kKeystoreKey,
nigori.mutable_keystore_decryptor_token());
other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
nigori.set_keybag_is_frozen(true);
@@ -1516,9 +1381,7 @@ TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreAfterReceivingMigratedNigori) {
other_cryptographer.AddKey(cur_key);
EXPECT_TRUE(other_cryptographer.is_ready());
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
- &keystore_decryptor_token));
+ other_cryptographer, kKeystoreKey, &keystore_decryptor_token));
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
EXPECT_FALSE(GetCryptographer()->is_ready());
EXPECT_NE(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
@@ -1538,12 +1401,9 @@ TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreAfterReceivingMigratedNigori) {
nigori.set_keystore_migration_time(1);
nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
nigori_node.SetNigoriSpecifics(nigori);
}
@@ -1556,17 +1416,15 @@ TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreAfterReceivingMigratedNigori) {
Mock::VerifyAndClearExpectations(observer());
EXPECT_CALL(*observer(), OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
{
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
PumpLoop();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
@@ -1582,7 +1440,7 @@ TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreAfterReceivingMigratedNigori) {
// Check that the cryptographer can decrypt keystore key based encryption.
Cryptographer keystore_cryptographer(GetCryptographer()->encryptor());
- KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
+ KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
keystore_cryptographer.AddKey(keystore_key);
sync_pb::EncryptedData keystore_encrypted;
keystore_cryptographer.EncryptString("string", &keystore_encrypted);
@@ -1600,9 +1458,7 @@ TEST_F(SyncEncryptionHandlerImplTest, SetCustomPassAfterMigration) {
other_cryptographer.AddKey(cur_key);
EXPECT_TRUE(other_cryptographer.is_ready());
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
- &keystore_decryptor_token));
+ other_cryptographer, kKeystoreKey, &keystore_decryptor_token));
// Build a nigori node with the generated keystore decryptor token and
// initialize the encryption handler with it. The cryptographer should be
@@ -1622,22 +1478,17 @@ TEST_F(SyncEncryptionHandlerImplTest, SetCustomPassAfterMigration) {
nigori_node.SetNigoriSpecifics(nigori);
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
EXPECT_CALL(*observer(), OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->Init();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->is_ready());
@@ -1646,10 +1497,8 @@ TEST_F(SyncEncryptionHandlerImplTest, SetCustomPassAfterMigration) {
Mock::VerifyAndClearExpectations(observer());
const char kNewKey[] = "new_key";
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
@@ -1657,12 +1506,9 @@ TEST_F(SyncEncryptionHandlerImplTest, SetCustomPassAfterMigration) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
.WillOnce(testing::SaveArg<0>(&captured_bootstrap_token));
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete()).Times(2);
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnEncryptionComplete()).Times(2);
encryption_handler()->SetEncryptionPassphrase(kNewKey, true);
Mock::VerifyAndClearExpectations(observer());
@@ -1681,7 +1527,7 @@ TEST_F(SyncEncryptionHandlerImplTest, SetCustomPassAfterMigration) {
// Check that the cryptographer can decrypt keystore key based encryption.
Cryptographer keystore_cryptographer(GetCryptographer()->encryptor());
- KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
+ KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
keystore_cryptographer.AddKey(keystore_key);
sync_pb::EncryptedData keystore_encrypted;
keystore_cryptographer.EncryptString("string", &keystore_encrypted);
@@ -1717,9 +1563,7 @@ TEST_F(SyncEncryptionHandlerImplTest,
other_cryptographer.AddNonDefaultKey(keystore_key);
EXPECT_TRUE(other_cryptographer.is_ready());
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
- &keystore_decryptor_token));
+ other_cryptographer, kKeystoreKey, &keystore_decryptor_token));
// Build a nigori node with the generated keystore decryptor token and
// initialize the encryption handler with it. The cryptographer will have
@@ -1739,14 +1583,10 @@ TEST_F(SyncEncryptionHandlerImplTest,
nigori_node.SetNigoriSpecifics(nigori);
}
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
encryption_handler()->Init();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->has_pending_keys());
@@ -1754,24 +1594,19 @@ TEST_F(SyncEncryptionHandlerImplTest,
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
Mock::VerifyAndClearExpectations(observer());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->SetDecryptionPassphrase(kOldKey);
EXPECT_TRUE(GetCryptographer()->is_ready());
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
Mock::VerifyAndClearExpectations(observer());
const char kNewKey[] = "new_key";
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _));
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
@@ -1779,12 +1614,9 @@ TEST_F(SyncEncryptionHandlerImplTest,
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
.WillOnce(testing::SaveArg<0>(&captured_bootstrap_token));
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete()).Times(2);
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnEncryptionComplete()).Times(2);
encryption_handler()->SetEncryptionPassphrase(kNewKey, true);
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->is_ready());
@@ -1836,9 +1668,7 @@ TEST_F(SyncEncryptionHandlerImplTest,
other_cryptographer.AddNonDefaultKey(keystore_key);
EXPECT_TRUE(other_cryptographer.is_ready());
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
- &keystore_decryptor_token));
+ other_cryptographer, kKeystoreKey, &keystore_decryptor_token));
// Build a nigori node with the generated keystore decryptor token and
// initialize the encryption handler with it. The cryptographer will have
@@ -1857,14 +1687,10 @@ TEST_F(SyncEncryptionHandlerImplTest,
nigori_node.SetNigoriSpecifics(nigori);
}
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
encryption_handler()->Init();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->has_pending_keys());
@@ -1872,14 +1698,11 @@ TEST_F(SyncEncryptionHandlerImplTest,
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
Mock::VerifyAndClearExpectations(observer());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->SetDecryptionPassphrase(kOldKey);
EXPECT_TRUE(GetCryptographer()->is_ready());
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
@@ -1931,9 +1754,7 @@ TEST_F(SyncEncryptionHandlerImplTest,
other_cryptographer.AddNonDefaultKey(keystore_key);
EXPECT_TRUE(other_cryptographer.is_ready());
EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
- &keystore_decryptor_token));
+ other_cryptographer, kKeystoreKey, &keystore_decryptor_token));
// Build a nigori node with the generated keystore decryptor token and
// initialize the encryption handler with it. The cryptographer will have
@@ -1952,14 +1773,10 @@ TEST_F(SyncEncryptionHandlerImplTest,
nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
nigori_node.SetNigoriSpecifics(nigori);
}
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
encryption_handler()->Init();
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
EXPECT_TRUE(GetCryptographer()->has_pending_keys());
@@ -1967,30 +1784,24 @@ TEST_F(SyncEncryptionHandlerImplTest,
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
Mock::VerifyAndClearExpectations(observer());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
std::string captured_bootstrap_token;
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
.WillOnce(testing::SaveArg<0>(&captured_bootstrap_token));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->SetDecryptionPassphrase(kCurKey);
Mock::VerifyAndClearExpectations(observer());
EXPECT_CALL(*observer(),
OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE, _));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
encryption_handler()->EnableEncryptEverything();
Mock::VerifyAndClearExpectations(observer());
@@ -2022,8 +1833,7 @@ TEST_F(SyncEncryptionHandlerImplTest,
// If we receive a nigori migrated and with a KEYSTORE_PASSPHRASE type, but
// using an old default key (i.e. old GAIA password), we should overwrite the
// nigori, updating the keybag and keystore decryptor.
-TEST_F(SyncEncryptionHandlerImplTest,
- ReceiveMigratedNigoriWithOldPassphrase) {
+TEST_F(SyncEncryptionHandlerImplTest, ReceiveMigratedNigoriWithOldPassphrase) {
const char kOldKey[] = "old";
const char kCurKey[] = "cur";
sync_pb::EncryptedData encrypted;
@@ -2036,12 +1846,9 @@ TEST_F(SyncEncryptionHandlerImplTest,
other_cryptographer.AddKey(old_key);
EXPECT_TRUE(other_cryptographer.is_ready());
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnEncryptionComplete());
encryption_handler()->Init();
EXPECT_TRUE(GetCryptographer()->is_ready());
EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled());
@@ -2050,12 +1857,10 @@ TEST_F(SyncEncryptionHandlerImplTest,
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
PumpLoop();
Mock::VerifyAndClearExpectations(observer());
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
@@ -2063,8 +1868,7 @@ TEST_F(SyncEncryptionHandlerImplTest,
VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey);
// Now build an old keystore passphrase nigori node.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(), OnEncryptionComplete());
{
WriteTransaction trans(FROM_HERE, user_share());
@@ -2074,8 +1878,7 @@ TEST_F(SyncEncryptionHandlerImplTest,
Cryptographer other_cryptographer(GetCryptographer()->encryptor());
other_cryptographer.AddKey(old_key);
encryption_handler()->GetKeystoreDecryptor(
- other_cryptographer,
- kKeystoreKey,
+ other_cryptographer, kKeystoreKey,
nigori.mutable_keystore_decryptor_token());
other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
nigori.set_keybag_is_frozen(true);
@@ -2112,9 +1915,8 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysGaiaDefault) {
ReadTransaction trans(FROM_HERE, user_share());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawOldKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawOldKeystoreKey), trans.GetWrappedTrans());
}
PumpLoop();
Mock::VerifyAndClearExpectations(observer());
@@ -2134,8 +1936,7 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysGaiaDefault) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(keys,
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(keys, trans.GetWrappedTrans());
}
// Pump for any posted tasks.
PumpLoop();
@@ -2166,9 +1967,8 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysKeystoreDefault) {
ReadTransaction trans(FROM_HERE, user_share());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawOldKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawOldKeystoreKey), trans.GetWrappedTrans());
}
PumpLoop();
Mock::VerifyAndClearExpectations(observer());
@@ -2188,8 +1988,7 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysKeystoreDefault) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(keys,
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(keys, trans.GetWrappedTrans());
}
// Pump for any posted tasks.
PumpLoop();
@@ -2221,23 +2020,18 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysAfterPendingGaiaResolved) {
ReadTransaction trans(FROM_HERE, user_share());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(keys,
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(keys, trans.GetWrappedTrans());
}
PumpLoop();
Mock::VerifyAndClearExpectations(observer());
// Resolve the pending keys. This should trigger the key rotation.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete()).Times(AtLeast(1));
+ EXPECT_CALL(*observer(), OnEncryptionComplete()).Times(AtLeast(1));
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
encryption_handler()->SetDecryptionPassphrase(kOldGaiaKey);
EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
@@ -2267,8 +2061,7 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysGaiaDefaultOnInit) {
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(keys,
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(keys, trans.GetWrappedTrans());
}
// Then init the nigori node with an old set of keys.
@@ -2307,35 +2100,25 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysWhenMigratedNigoriArrives) {
ReadTransaction trans(FROM_HERE, user_share());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(keys,
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(keys, trans.GetWrappedTrans());
}
PumpLoop();
Mock::VerifyAndClearExpectations(observer());
// Now simulate downloading a nigori node that was migrated before the
// keys were rotated, and hence still encrypt with the old gaia key.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete()).Times(AtLeast(1));
+ EXPECT_CALL(*observer(), OnEncryptionComplete()).Times(AtLeast(1));
{
sync_pb::NigoriSpecifics nigori = BuildMigratedNigori(
- KEYSTORE_PASSPHRASE,
- 1,
- kOldGaiaKey,
- old_keystore_key);
+ KEYSTORE_PASSPHRASE, 1, kOldGaiaKey, old_keystore_key);
// Update the encryption handler.
WriteTransaction trans(FROM_HERE, user_share());
- encryption_handler()->ApplyNigoriUpdate(
- nigori,
- trans.GetWrappedTrans());
+ encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
}
EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
PumpLoop();
@@ -2362,25 +2145,20 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysUnmigratedCustomPassphrase) {
ReadTransaction trans(FROM_HERE, user_share());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- encryption_handler()->SetKeystoreKeys(keys,
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(keys, trans.GetWrappedTrans());
}
PumpLoop();
Mock::VerifyAndClearExpectations(observer());
// Pass the decryption passphrase. This will also trigger the migration,
// but should not overwrite the default key.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseAccepted());
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, true));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseAccepted());
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true));
SyncEncryptionHandler::NigoriState captured_nigori_state;
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
- EXPECT_CALL(*observer(),
- OnEncryptionComplete()).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnEncryptionComplete()).Times(AnyNumber());
std::string captured_bootstrap_token;
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
@@ -2419,12 +2197,10 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysMigratedCustomPassphrase) {
ReadTransaction trans(FROM_HERE, user_share());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_))
.WillOnce(testing::SaveArg<0>(&captured_nigori_state));
- encryption_handler()->SetKeystoreKeys(keys,
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(keys, trans.GetWrappedTrans());
}
PumpLoop();
Mock::VerifyAndClearExpectations(observer());
@@ -2445,49 +2221,36 @@ TEST_F(SyncEncryptionHandlerImplTest, RotateKeysMigratedCustomPassphrase) {
// Verify that the client can gracefully handle a nigori node that is missing
// the keystore migration time field.
TEST_F(SyncEncryptionHandlerImplTest, MissingKeystoreMigrationTime) {
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnEncryptedTypesChanged(_, false));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, false));
encryption_handler()->Init();
Mock::VerifyAndClearExpectations(observer());
// Now simulate downloading a nigori node that that is missing the keystore
// migration time. It should be interpreted properly, and the passphrase type
// should switch to keystore passphrase.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
- EXPECT_CALL(*observer(),
- OnPassphraseRequired(_, _));
- EXPECT_CALL(*observer(),
- OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnPassphraseRequired(_, _));
+ EXPECT_CALL(*observer(), OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE, _));
{
- sync_pb::NigoriSpecifics nigori = BuildMigratedNigori(
- KEYSTORE_PASSPHRASE,
- 1,
- kKeystoreKey,
- kKeystoreKey);
+ sync_pb::NigoriSpecifics nigori =
+ BuildMigratedNigori(KEYSTORE_PASSPHRASE, 1, kKeystoreKey, kKeystoreKey);
nigori.clear_keystore_migration_time();
// Update the encryption handler.
WriteTransaction trans(FROM_HERE, user_share());
- encryption_handler()->ApplyNigoriUpdate(
- nigori,
- trans.GetWrappedTrans());
+ encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
}
Mock::VerifyAndClearExpectations(observer());
// Now provide the keystore key to fully initialize the cryptographer.
- EXPECT_CALL(*observer(),
- OnCryptographerStateChanged(_)).Times(AnyNumber());
+ EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
EXPECT_CALL(*observer(),
OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
{
ReadTransaction trans(FROM_HERE, user_share());
- encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(
- kRawKeystoreKey),
- trans.GetWrappedTrans());
+ encryption_handler()->SetKeystoreKeys(
+ BuildEncryptionKeyProto(kRawKeystoreKey), trans.GetWrappedTrans());
}
}
« no previous file with comments | « components/sync/core_impl/sync_encryption_handler_impl.cc ('k') | components/sync/core_impl/sync_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698