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

Unified Diff: chrome/browser/prefs/profile_pref_store_manager_unittest.cc

Issue 324493002: Move preference MACs to the protected preference stores. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment typo. Created 6 years, 6 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: chrome/browser/prefs/profile_pref_store_manager_unittest.cc
diff --git a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc
index 13f054f9e7fd79be471f736b2815dd5041e995eb..c478ac44834340166de6b10ac410695f54da1d5c 100644
--- a/chrome/browser/prefs/profile_pref_store_manager_unittest.cc
+++ b/chrome/browser/prefs/profile_pref_store_manager_unittest.cc
@@ -24,6 +24,7 @@
#include "base/values.h"
#include "chrome/browser/prefs/mock_validation_delegate.h"
#include "chrome/browser/prefs/pref_hash_filter.h"
+#include "chrome/browser/prefs/tracked/pref_service_hash_store_contents.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -151,6 +152,16 @@ class ProfilePrefStoreManagerTest : public testing::Test {
return !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null();
}
+ void ClearResetRecorded() {
+ base::PrefServiceFactory pref_service_factory;
+ pref_service_factory.set_user_prefs(pref_store_);
+
+ scoped_ptr<PrefService> pref_service(
+ pref_service_factory.Create(profile_pref_registry_));
+
+ ProfilePrefStoreManager::ClearResetTime(pref_service.get());
+ }
+
void InitializePrefs() {
// According to the implementation of ProfilePrefStoreManager, this is
// actually a SegregatedPrefStore backed by two underlying pref stores.
@@ -165,6 +176,7 @@ class ProfilePrefStoreManagerTest : public testing::Test {
void DestroyPrefStore() {
if (pref_store_) {
+ ClearResetRecorded();
// Force everything to be written to disk, triggering the PrefHashFilter
// while our RegistryVerifier is watching.
pref_store_->CommitPendingWrite();
@@ -307,11 +319,78 @@ TEST_F(ProfilePrefStoreManagerTest, ProtectValues) {
TEST_F(ProfilePrefStoreManagerTest, MigrateFromOneFile) {
InitializeDeprecatedCombinedProfilePrefStore();
+ // The deprecated model stores hashes in local state (on supported
+ // platforms)..
+ ASSERT_EQ(
+ ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
+ local_state_.GetUserPrefValue(
+ PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL);
+
LoadExistingPrefs();
+ // After a first migration, the hashes were copied to the two user preference
+ // files but were not cleaned.
+ ASSERT_EQ(
+ ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
+ local_state_.GetUserPrefValue(
+ PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL);
+
ExpectStringValueEquals(kTrackedAtomic, kFoobar);
ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
EXPECT_FALSE(WasResetRecorded());
+
+ LoadExistingPrefs();
+
+ // In a subsequent launch, the local state hash store should be reset.
+ ASSERT_FALSE(local_state_.GetUserPrefValue(
+ PrefServiceHashStoreContents::kProfilePreferenceHashes));
+
+ ExpectStringValueEquals(kTrackedAtomic, kFoobar);
+ ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
+ EXPECT_FALSE(WasResetRecorded());
+}
+
+TEST_F(ProfilePrefStoreManagerTest, MigrateWithTampering) {
+ InitializeDeprecatedCombinedProfilePrefStore();
+
+ ReplaceStringInPrefs(kFoobar, kBarfoo);
+ ReplaceStringInPrefs(kHelloWorld, kGoodbyeWorld);
+
+ // The deprecated model stores hashes in local state (on supported
+ // platforms)..
+ ASSERT_EQ(
+ ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
+ local_state_.GetUserPrefValue(
+ PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL);
+
+ LoadExistingPrefs();
+
+ // After a first migration, the hashes were copied to the two user preference
+ // files but were not cleaned.
+ ASSERT_EQ(
+ ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
+ local_state_.GetUserPrefValue(
+ PrefServiceHashStoreContents::kProfilePreferenceHashes) != NULL);
+
+ // kTrackedAtomic is unprotected and thus will be loaded as it appears on
+ // disk.
+ ExpectStringValueEquals(kTrackedAtomic, kBarfoo);
+
+ // If preference tracking is supported, the tampered value of kProtectedAtomic
+ // will be discarded at load time, leaving this preference undefined.
+ EXPECT_NE(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
+ pref_store_->GetValue(kProtectedAtomic, NULL));
+ EXPECT_EQ(ProfilePrefStoreManager::kPlatformSupportsPreferenceTracking,
+ WasResetRecorded());
+
+ LoadExistingPrefs();
+
+ // In a subsequent launch, the local state hash store would be reset.
+ ASSERT_FALSE(local_state_.GetUserPrefValue(
+ PrefServiceHashStoreContents::kProfilePreferenceHashes));
+
+ ExpectStringValueEquals(kTrackedAtomic, kBarfoo);
+ EXPECT_FALSE(WasResetRecorded());
}
TEST_F(ProfilePrefStoreManagerTest, InitializePrefsFromMasterPrefs) {
@@ -375,6 +454,45 @@ TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtected) {
WasResetRecorded());
}
+TEST_F(ProfilePrefStoreManagerTest, NewPrefWhenFirstProtecting) {
+ std::vector<PrefHashFilter::TrackedPreferenceMetadata>
+ original_configuration = configuration_;
+ for (std::vector<PrefHashFilter::TrackedPreferenceMetadata>::iterator it =
+ configuration_.begin();
+ it != configuration_.end();
+ ++it) {
+ it->enforcement_level = PrefHashFilter::NO_ENFORCEMENT;
+ }
+ ReloadConfiguration();
+
+ InitializePrefs();
+
+ ExpectValidationObserved(kTrackedAtomic);
+ ExpectValidationObserved(kProtectedAtomic);
+
+ LoadExistingPrefs();
+ ExpectStringValueEquals(kUnprotectedPref, kFoobar);
+
+ // Ensure everything is written out to disk.
+ DestroyPrefStore();
+
+ // Now introduce protection, including the never-before tracked "new_pref".
+ configuration_ = original_configuration;
+ PrefHashFilter::TrackedPreferenceMetadata new_protected = {
+ kExtraReportingId, kUnprotectedPref, PrefHashFilter::ENFORCE_ON_LOAD,
+ PrefHashFilter::TRACKING_STRATEGY_ATOMIC};
+ configuration_.push_back(new_protected);
+ ReloadConfiguration();
+
+ // And try loading with the new configuration.
+ LoadExistingPrefs();
+
+ // Since there was a valid super MAC we were able to extend the existing trust
+ // to the newly tracked & protected preference.
+ ExpectStringValueEquals(kUnprotectedPref, kFoobar);
+ EXPECT_FALSE(WasResetRecorded());
+}
+
TEST_F(ProfilePrefStoreManagerTest, UnprotectedToProtectedWithoutTrust) {
InitializePrefs();
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager.cc ('k') | chrome/browser/prefs/tracked/dictionary_hash_store_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698