Commit 03c41c9e authored by zea@chromium.org's avatar zea@chromium.org

[Sync] The cryptographer should be able to handle empty or old nigori nodes.

This includes never unsetting the encryption status of a type once it has been
set.

BUG=104218
TEST=unit_tests


Review URL: http://codereview.chromium.org/8564032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110578 0039d316-1c4b-4281-b951-d872f2087c98
parent 9f65f4b3
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include "base/base64.h"
#include "chrome/browser/sync/util/cryptographer.h"
#include "chrome/browser/password_manager/encryptor.h"
......@@ -326,7 +328,7 @@ void Cryptographer::UpdateEncryptedTypesFromNigori(
return;
}
SetEncryptedTypes(encrypted_types);
MergeEncryptedTypes(encrypted_types);
}
void Cryptographer::UpdateNigoriFromEncryptedTypes(
......@@ -376,14 +378,15 @@ syncable::ModelTypeSet Cryptographer::GetEncryptedTypes() const {
return encrypted_types_;
}
void Cryptographer::SetEncryptedTypesForTest(
void Cryptographer::MergeEncryptedTypesForTest(
const syncable::ModelTypeSet& encrypted_types) {
SetEncryptedTypes(encrypted_types);
MergeEncryptedTypes(encrypted_types);
}
void Cryptographer::SetEncryptedTypes(
void Cryptographer::MergeEncryptedTypes(
const syncable::ModelTypeSet& encrypted_types) {
if (encrypted_types_ == encrypted_types) {
if (std::includes(encrypted_types_.begin(), encrypted_types_.end(),
encrypted_types.begin(), encrypted_types.end())) {
return;
}
encrypted_types_ = encrypted_types;
......
......@@ -182,17 +182,17 @@ class Cryptographer {
// Return the set of encrypted types.
syncable::ModelTypeSet GetEncryptedTypes() const;
// Forwards to SetEncryptedTypes.
void SetEncryptedTypesForTest(
// Forwards to MergeEncryptedTypes.
void MergeEncryptedTypesForTest(
const syncable::ModelTypeSet& encrypted_types);
private:
FRIEND_TEST_ALL_PREFIXES(CryptographerTest, PackUnpack);
typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap;
// Changes the set of encrypted types and emits a notification if
// necessary.
void SetEncryptedTypes(const syncable::ModelTypeSet& encrypted_types);
// Merges the given set of encrypted types with the existing set and emits a
// notification if necessary.
void MergeEncryptedTypes(const syncable::ModelTypeSet& encrypted_types);
void EmitEncryptedTypesChangedNotification();
......
......@@ -207,7 +207,7 @@ TEST(CryptographerTest, NigoriEncryptionTypes) {
// Just set the sensitive types (shouldn't trigger any
// notifications).
ModelTypeSet encrypted_types(Cryptographer::SensitiveTypes());
cryptographer.SetEncryptedTypesForTest(encrypted_types);
cryptographer.MergeEncryptedTypesForTest(encrypted_types);
cryptographer.UpdateNigoriFromEncryptedTypes(&nigori);
cryptographer2.UpdateEncryptedTypesFromNigori(nigori);
EXPECT_EQ(encrypted_types, cryptographer.GetEncryptedTypes());
......@@ -225,11 +225,18 @@ TEST(CryptographerTest, NigoriEncryptionTypes) {
// Set all encrypted types
encrypted_types = syncable::GetAllRealModelTypes();
cryptographer.SetEncryptedTypesForTest(encrypted_types);
cryptographer.MergeEncryptedTypesForTest(encrypted_types);
cryptographer.UpdateNigoriFromEncryptedTypes(&nigori);
cryptographer2.UpdateEncryptedTypesFromNigori(nigori);
EXPECT_EQ(encrypted_types, cryptographer.GetEncryptedTypes());
EXPECT_EQ(encrypted_types, cryptographer2.GetEncryptedTypes());
// Receiving an empty nigori should not reset any encrypted types or trigger
// an observer notification.
Mock::VerifyAndClearExpectations(&observer);
nigori = sync_pb::NigoriSpecifics();
cryptographer.UpdateEncryptedTypesFromNigori(nigori);
EXPECT_EQ(encrypted_types, cryptographer.GetEncryptedTypes());
}
TEST(CryptographerTest, EncryptEverythingExplicit) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment