Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 32 #include "components/search_engines/default_search_manager.h" | 32 #include "components/search_engines/default_search_manager.h" |
| 33 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" | 33 #include "components/user_prefs/tracked/tracked_preference_histogram_names.h" |
| 34 #include "extensions/browser/pref_names.h" | 34 #include "extensions/browser/pref_names.h" |
| 35 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
| 36 | 36 |
| 37 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
| 38 #include "chromeos/chromeos_switches.h" | 38 #include "chromeos/chromeos_switches.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 #if defined(OS_WIN) | |
| 42 #include "base/test/test_reg_util_win.h" | |
| 43 #endif | |
| 44 | |
| 41 namespace { | 45 namespace { |
| 42 | 46 |
| 43 // Extension ID of chrome/test/data/extensions/good.crx | 47 // Extension ID of chrome/test/data/extensions/good.crx |
| 44 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 48 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 45 | 49 |
| 50 // Prefix for the registry path. | |
| 51 constexpr base::char16 kRegistryTestPathPrefix[] = | |
|
gab
2016/09/30 19:03:28
"registry" things don't make sense on non-Windows
proberge
2016/09/30 19:08:28
Great idea. Done.
| |
| 52 L"SOFTWARE\\Chromium\\PrefHashBrowserTest\\"; | |
| 53 | |
| 46 // Explicit expectations from the caller of GetTrackedPrefHistogramCount(). This | 54 // Explicit expectations from the caller of GetTrackedPrefHistogramCount(). This |
| 47 // enables detailed reporting of the culprit on failure. | 55 // enables detailed reporting of the culprit on failure. |
| 48 enum AllowedBuckets { | 56 enum AllowedBuckets { |
| 49 // Allow no samples in any buckets. | 57 // Allow no samples in any buckets. |
| 50 ALLOW_NONE = -1, | 58 ALLOW_NONE = -1, |
| 51 // Any integer between BEGIN_ALLOW_SINGLE_BUCKET and END_ALLOW_SINGLE_BUCKET | 59 // Any integer between BEGIN_ALLOW_SINGLE_BUCKET and END_ALLOW_SINGLE_BUCKET |
| 52 // indicates that only this specific bucket is allowed to have a sample. | 60 // indicates that only this specific bucket is allowed to have a sample. |
| 53 BEGIN_ALLOW_SINGLE_BUCKET = 0, | 61 BEGIN_ALLOW_SINGLE_BUCKET = 0, |
| 54 END_ALLOW_SINGLE_BUCKET = 100, | 62 END_ALLOW_SINGLE_BUCKET = 100, |
| 55 // Allow any buckets (no extra verifications performed). | 63 // Allow any buckets (no extra verifications performed). |
| 56 ALLOW_ANY | 64 ALLOW_ANY |
| 57 }; | 65 }; |
| 58 | 66 |
| 67 base::string16 GetRegistryPathForTestProfile() { | |
| 68 base::FilePath profile_dir; | |
| 69 EXPECT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &profile_dir)); | |
| 70 return kRegistryTestPathPrefix + profile_dir.BaseName().value(); | |
| 71 } | |
| 72 | |
| 59 // Returns the number of times |histogram_name| was reported so far; adding the | 73 // Returns the number of times |histogram_name| was reported so far; adding the |
| 60 // results of the first 100 buckets (there are only ~19 reporting IDs as of this | 74 // results of the first 100 buckets (there are only ~19 reporting IDs as of this |
| 61 // writing; varies depending on the platform). |allowed_buckets| hints at extra | 75 // writing; varies depending on the platform). |allowed_buckets| hints at extra |
| 62 // requirements verified in this method (see AllowedBuckets for details). | 76 // requirements verified in this method (see AllowedBuckets for details). |
| 63 int GetTrackedPrefHistogramCount(const char* histogram_name, | 77 int GetTrackedPrefHistogramCount(const char* histogram_name, |
| 78 const char* histogram_suffix, | |
| 64 int allowed_buckets) { | 79 int allowed_buckets) { |
| 80 std::string full_histogram_name(histogram_name); | |
| 81 if (*histogram_suffix) | |
| 82 full_histogram_name.append(".").append(histogram_suffix); | |
| 65 const base::HistogramBase* histogram = | 83 const base::HistogramBase* histogram = |
| 66 base::StatisticsRecorder::FindHistogram(histogram_name); | 84 base::StatisticsRecorder::FindHistogram(full_histogram_name); |
| 67 if (!histogram) | 85 if (!histogram) |
| 68 return 0; | 86 return 0; |
| 69 | 87 |
| 70 std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | 88 std::unique_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); |
| 71 int sum = 0; | 89 int sum = 0; |
| 72 for (int i = 0; i < 100; ++i) { | 90 for (int i = 0; i < 100; ++i) { |
| 73 int count_for_id = samples->GetCount(i); | 91 int count_for_id = samples->GetCount(i); |
| 74 EXPECT_GE(count_for_id, 0); | 92 EXPECT_GE(count_for_id, 0); |
| 75 sum += count_for_id; | 93 sum += count_for_id; |
| 76 | 94 |
| 77 if (allowed_buckets == ALLOW_NONE || | 95 if (allowed_buckets == ALLOW_NONE || |
| 78 (allowed_buckets != ALLOW_ANY && i != allowed_buckets)) { | 96 (allowed_buckets != ALLOW_ANY && i != allowed_buckets)) { |
| 79 EXPECT_EQ(0, count_for_id) << "Unexpected reporting_id: " << i; | 97 EXPECT_EQ(0, count_for_id) << "Unexpected reporting_id: " << i; |
| 80 } | 98 } |
| 81 } | 99 } |
| 82 return sum; | 100 return sum; |
| 83 } | 101 } |
| 84 | 102 |
| 103 // Helper function to call GetTrackedPrefHistogramCount with no external | |
| 104 // validation suffix. | |
| 105 int GetTrackedPrefHistogramCount(const char* histogram_name, | |
| 106 int allowed_buckets) { | |
| 107 return GetTrackedPrefHistogramCount(histogram_name, "", allowed_buckets); | |
| 108 } | |
| 109 | |
| 85 std::unique_ptr<base::DictionaryValue> ReadPrefsDictionary( | 110 std::unique_ptr<base::DictionaryValue> ReadPrefsDictionary( |
| 86 const base::FilePath& pref_file) { | 111 const base::FilePath& pref_file) { |
| 87 JSONFileValueDeserializer deserializer(pref_file); | 112 JSONFileValueDeserializer deserializer(pref_file); |
| 88 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR; | 113 int error_code = JSONFileValueDeserializer::JSON_NO_ERROR; |
| 89 std::string error_str; | 114 std::string error_str; |
| 90 std::unique_ptr<base::Value> prefs = | 115 std::unique_ptr<base::Value> prefs = |
| 91 deserializer.Deserialize(&error_code, &error_str); | 116 deserializer.Deserialize(&error_code, &error_str); |
| 92 if (!prefs || error_code != JSONFileValueDeserializer::JSON_NO_ERROR) { | 117 if (!prefs || error_code != JSONFileValueDeserializer::JSON_NO_ERROR) { |
| 93 ADD_FAILURE() << "Error #" << error_code << ": " << error_str; | 118 ADD_FAILURE() << "Error #" << error_code << ": " << error_str; |
| 94 return std::unique_ptr<base::DictionaryValue>(); | 119 return std::unique_ptr<base::DictionaryValue>(); |
| 95 } | 120 } |
| 96 if (!prefs->IsType(base::Value::TYPE_DICTIONARY)) { | 121 if (!prefs->IsType(base::Value::TYPE_DICTIONARY)) { |
| 97 ADD_FAILURE(); | 122 ADD_FAILURE(); |
| 98 return std::unique_ptr<base::DictionaryValue>(); | 123 return std::unique_ptr<base::DictionaryValue>(); |
| 99 } | 124 } |
| 100 return std::unique_ptr<base::DictionaryValue>( | 125 return std::unique_ptr<base::DictionaryValue>( |
| 101 static_cast<base::DictionaryValue*>(prefs.release())); | 126 static_cast<base::DictionaryValue*>(prefs.release())); |
| 102 } | 127 } |
| 103 | 128 |
| 129 // Returns whether external validation is supported on the platform through | |
| 130 // storing MACs in the registry. | |
| 131 bool SupportsRegistryValidation() { | |
| 132 #if defined(OS_WIN) | |
| 133 return true; | |
| 134 #else | |
| 135 return false; | |
| 136 #endif | |
| 137 } | |
| 138 | |
| 104 #define PREF_HASH_BROWSER_TEST(fixture, test_name) \ | 139 #define PREF_HASH_BROWSER_TEST(fixture, test_name) \ |
| 105 IN_PROC_BROWSER_TEST_P(fixture, PRE_##test_name) { \ | 140 IN_PROC_BROWSER_TEST_P(fixture, PRE_##test_name) { \ |
| 106 SetupPreferences(); \ | 141 SetupPreferences(); \ |
| 107 } \ | 142 } \ |
| 108 IN_PROC_BROWSER_TEST_P(fixture, test_name) { \ | 143 IN_PROC_BROWSER_TEST_P(fixture, test_name) { \ |
| 109 VerifyReactionToPrefAttack(); \ | 144 VerifyReactionToPrefAttack(); \ |
| 110 } \ | 145 } \ |
| 111 INSTANTIATE_TEST_CASE_P( \ | 146 INSTANTIATE_TEST_CASE_P( \ |
| 112 fixture##Instance, \ | 147 fixture##Instance, \ |
| 113 fixture, \ | 148 fixture, \ |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 261 |
| 227 return true; | 262 return true; |
| 228 } | 263 } |
| 229 | 264 |
| 230 void SetUpInProcessBrowserTestFixture() override { | 265 void SetUpInProcessBrowserTestFixture() override { |
| 231 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); | 266 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 232 | 267 |
| 233 // Bots are on a domain, turn off the domain check for settings hardening in | 268 // Bots are on a domain, turn off the domain check for settings hardening in |
| 234 // order to be able to test all SettingsEnforcement groups. | 269 // order to be able to test all SettingsEnforcement groups. |
| 235 chrome_prefs::DisableDomainCheckForTesting(); | 270 chrome_prefs::DisableDomainCheckForTesting(); |
| 271 | |
| 272 #if defined(OS_WIN) | |
| 273 // Avoid polluting prefs for the user and the bots by writing to a specific | |
| 274 // testing registry path. | |
| 275 registry_key_for_external_validation_ = GetRegistryPathForTestProfile(); | |
| 276 ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( | |
| 277 ®istry_key_for_external_validation_); | |
| 278 | |
| 279 // Keys should be unique, but to avoid flakes in the long run make sure an | |
| 280 // identical test key wasn't left behind by a previous test. | |
| 281 if (IsPRETest()) { | |
| 282 base::win::RegKey key; | |
| 283 if (key.Open(HKEY_CURRENT_USER, | |
| 284 registry_key_for_external_validation_.c_str(), | |
| 285 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
| 286 LONG result = key.DeleteKey(L""); | |
| 287 ASSERT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | |
| 288 } | |
| 289 } | |
| 290 #endif | |
| 291 } | |
| 292 | |
| 293 void TearDown() override { | |
| 294 #if defined(OS_WIN) | |
| 295 // When done, delete the Registry key to avoid polluting the registry. | |
| 296 // TODO(proberge): it would be nice to delete keys from interrupted tests | |
| 297 // as well. | |
| 298 if (!IsPRETest()) { | |
| 299 base::string16 registry_key = GetRegistryPathForTestProfile(); | |
| 300 base::win::RegKey key; | |
| 301 if (key.Open(HKEY_CURRENT_USER, registry_key.c_str(), | |
| 302 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
| 303 LONG result = key.DeleteKey(L""); | |
| 304 ASSERT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | |
| 305 } | |
| 306 } | |
| 307 #endif | |
| 308 ExtensionBrowserTest::TearDown(); | |
| 236 } | 309 } |
| 237 | 310 |
| 238 // In the PRE_ test, find the number of tracked preferences that were | 311 // In the PRE_ test, find the number of tracked preferences that were |
| 239 // initialized and save it to a file to be read back in the main test and used | 312 // initialized and save it to a file to be read back in the main test and used |
| 240 // as the total number of tracked preferences. | 313 // as the total number of tracked preferences. |
| 241 void SetUpOnMainThread() override { | 314 void SetUpOnMainThread() override { |
| 242 ExtensionBrowserTest::SetUpOnMainThread(); | 315 ExtensionBrowserTest::SetUpOnMainThread(); |
| 243 | 316 |
| 244 // File in which the PRE_ test will save the number of tracked preferences | 317 // File in which the PRE_ test will save the number of tracked preferences |
| 245 // on this platform. | 318 // on this platform. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 259 | 332 |
| 260 // Split tracked prefs are reported as Unchanged not as NullInitialized | 333 // Split tracked prefs are reported as Unchanged not as NullInitialized |
| 261 // when an empty dictionary is encountered on first run (this should only | 334 // when an empty dictionary is encountered on first run (this should only |
| 262 // hit for pref #5 in the current design). | 335 // hit for pref #5 in the current design). |
| 263 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( | 336 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( |
| 264 user_prefs::tracked::kTrackedPrefHistogramUnchanged, | 337 user_prefs::tracked::kTrackedPrefHistogramUnchanged, |
| 265 BEGIN_ALLOW_SINGLE_BUCKET + 5); | 338 BEGIN_ALLOW_SINGLE_BUCKET + 5); |
| 266 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | 339 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, |
| 267 num_split_tracked_prefs); | 340 num_split_tracked_prefs); |
| 268 | 341 |
| 342 if (SupportsRegistryValidation()) { | |
| 343 // Same checks as above, but for the registry. | |
| 344 num_tracked_prefs_ = GetTrackedPrefHistogramCount( | |
| 345 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | |
| 346 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 347 ALLOW_ANY); | |
| 348 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM, | |
| 349 num_tracked_prefs_ > 0); | |
| 350 | |
| 351 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( | |
| 352 user_prefs::tracked::kTrackedPrefHistogramUnchanged, | |
| 353 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 354 BEGIN_ALLOW_SINGLE_BUCKET + 5); | |
| 355 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 356 num_split_tracked_prefs); | |
| 357 } | |
| 358 | |
| 269 num_tracked_prefs_ += num_split_tracked_prefs; | 359 num_tracked_prefs_ += num_split_tracked_prefs; |
| 270 | 360 |
| 271 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_); | 361 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_); |
| 272 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()), | 362 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()), |
| 273 base::WriteFile(num_tracked_prefs_file, | 363 base::WriteFile(num_tracked_prefs_file, |
| 274 num_tracked_prefs_str.c_str(), | 364 num_tracked_prefs_str.c_str(), |
| 275 num_tracked_prefs_str.size())); | 365 num_tracked_prefs_str.size())); |
| 276 } else { | 366 } else { |
| 277 std::string num_tracked_prefs_str; | 367 std::string num_tracked_prefs_str; |
| 278 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file, | 368 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 } else { | 436 } else { |
| 347 ADD_FAILURE(); | 437 ADD_FAILURE(); |
| 348 return static_cast<SettingsProtectionLevel>(-1); | 438 return static_cast<SettingsProtectionLevel>(-1); |
| 349 } | 439 } |
| 350 | 440 |
| 351 #endif // defined(OFFICIAL_BUILD) | 441 #endif // defined(OFFICIAL_BUILD) |
| 352 | 442 |
| 353 } | 443 } |
| 354 | 444 |
| 355 int num_tracked_prefs_; | 445 int num_tracked_prefs_; |
| 446 | |
| 447 #if defined(OS_WIN) | |
| 448 base::string16 registry_key_for_external_validation_; | |
| 449 #endif | |
| 356 }; | 450 }; |
| 357 | 451 |
| 358 } // namespace | 452 } // namespace |
| 359 | 453 |
| 360 // Verifies that nothing is reset when nothing is tampered with. | 454 // Verifies that nothing is reset when nothing is tampered with. |
| 361 // Also sanity checks that the expected preferences files are in place. | 455 // Also sanity checks that the expected preferences files are in place. |
| 362 class PrefHashBrowserTestUnchangedDefault : public PrefHashBrowserTestBase { | 456 class PrefHashBrowserTestUnchangedDefault : public PrefHashBrowserTestBase { |
| 363 public: | 457 public: |
| 364 void SetupPreferences() override { | 458 void SetupPreferences() override { |
| 365 // Default Chrome setup. | 459 // Default Chrome setup. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 GetTrackedPrefHistogramCount( | 494 GetTrackedPrefHistogramCount( |
| 401 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 495 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 402 ALLOW_NONE)); | 496 ALLOW_NONE)); |
| 403 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 497 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 404 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 498 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 405 ALLOW_NONE)); | 499 ALLOW_NONE)); |
| 406 EXPECT_EQ( | 500 EXPECT_EQ( |
| 407 0, GetTrackedPrefHistogramCount( | 501 0, GetTrackedPrefHistogramCount( |
| 408 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 502 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 409 ALLOW_NONE)); | 503 ALLOW_NONE)); |
| 504 | |
| 505 if (SupportsRegistryValidation()) { | |
| 506 // Expect all prefs to be reported as Unchanged. | |
| 507 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 508 ? num_tracked_prefs() | |
| 509 : 0, | |
| 510 GetTrackedPrefHistogramCount( | |
| 511 user_prefs::tracked::kTrackedPrefHistogramUnchanged, | |
| 512 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 513 ALLOW_ANY)); | |
| 514 } | |
| 410 } | 515 } |
| 411 }; | 516 }; |
| 412 | 517 |
| 413 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault); | 518 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault); |
| 414 | 519 |
| 415 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset | 520 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset |
| 416 // when nothing is tampered with, even if Chrome itself wrote custom prefs in | 521 // when nothing is tampered with, even if Chrome itself wrote custom prefs in |
| 417 // its last run. | 522 // its last run. |
| 418 class PrefHashBrowserTestUnchangedCustom | 523 class PrefHashBrowserTestUnchangedCustom |
| 419 : public PrefHashBrowserTestUnchangedDefault { | 524 : public PrefHashBrowserTestUnchangedDefault { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 GetTrackedPrefHistogramCount( | 595 GetTrackedPrefHistogramCount( |
| 491 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 596 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 492 ALLOW_NONE)); | 597 ALLOW_NONE)); |
| 493 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 598 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 494 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 599 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 495 ALLOW_NONE)); | 600 ALLOW_NONE)); |
| 496 EXPECT_EQ( | 601 EXPECT_EQ( |
| 497 0, GetTrackedPrefHistogramCount( | 602 0, GetTrackedPrefHistogramCount( |
| 498 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 603 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 499 ALLOW_NONE)); | 604 ALLOW_NONE)); |
| 605 | |
| 606 if (SupportsRegistryValidation()) { | |
| 607 // Expect homepage clearance to have been noticed by registry validation. | |
| 608 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 609 GetTrackedPrefHistogramCount( | |
| 610 user_prefs::tracked::kTrackedPrefHistogramCleared, | |
| 611 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 612 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 613 } | |
| 500 } | 614 } |
| 501 }; | 615 }; |
| 502 | 616 |
| 503 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic); | 617 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic); |
| 504 | 618 |
| 505 // Verifies that clearing the MACs results in untrusted Initialized pings for | 619 // Verifies that clearing the MACs results in untrusted Initialized pings for |
| 506 // non-null protected prefs. | 620 // non-null protected prefs. |
| 507 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase { | 621 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase { |
| 508 public: | 622 public: |
| 509 void SetupPreferences() override { | 623 void SetupPreferences() override { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 EXPECT_EQ( | 726 EXPECT_EQ( |
| 613 0, GetTrackedPrefHistogramCount( | 727 0, GetTrackedPrefHistogramCount( |
| 614 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); | 728 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); |
| 615 EXPECT_EQ( | 729 EXPECT_EQ( |
| 616 0, GetTrackedPrefHistogramCount( | 730 0, GetTrackedPrefHistogramCount( |
| 617 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); | 731 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); |
| 618 EXPECT_EQ( | 732 EXPECT_EQ( |
| 619 0, GetTrackedPrefHistogramCount( | 733 0, GetTrackedPrefHistogramCount( |
| 620 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 734 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 621 ALLOW_NONE)); | 735 ALLOW_NONE)); |
| 736 | |
| 737 if (SupportsRegistryValidation()) { | |
| 738 // The MACs have been cleared but the preferences have not been tampered. | |
| 739 // The registry should report all prefs as unchanged. | |
| 740 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 741 ? num_tracked_prefs() | |
| 742 : 0, | |
| 743 GetTrackedPrefHistogramCount( | |
| 744 user_prefs::tracked::kTrackedPrefHistogramUnchanged, | |
| 745 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 746 ALLOW_ANY)); | |
| 747 } | |
| 622 } | 748 } |
| 623 }; | 749 }; |
| 624 | 750 |
| 625 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized, | 751 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized, |
| 626 UntrustedInitialized); | 752 UntrustedInitialized); |
| 627 | 753 |
| 628 // Verifies that changing an atomic pref results in it being reported (and reset | 754 // Verifies that changing an atomic pref results in it being reported (and reset |
| 629 // if the protection level allows it). | 755 // if the protection level allows it). |
| 630 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase { | 756 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase { |
| 631 public: | 757 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 GetTrackedPrefHistogramCount( | 828 GetTrackedPrefHistogramCount( |
| 703 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 829 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 704 ALLOW_NONE)); | 830 ALLOW_NONE)); |
| 705 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 831 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 706 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 832 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 707 ALLOW_NONE)); | 833 ALLOW_NONE)); |
| 708 EXPECT_EQ( | 834 EXPECT_EQ( |
| 709 0, GetTrackedPrefHistogramCount( | 835 0, GetTrackedPrefHistogramCount( |
| 710 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 836 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 711 ALLOW_NONE)); | 837 ALLOW_NONE)); |
| 838 | |
| 839 if (SupportsRegistryValidation()) { | |
| 840 // Expect a single Changed event for tracked pref #4 (startup URLs). | |
| 841 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 842 GetTrackedPrefHistogramCount( | |
| 843 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 844 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 845 BEGIN_ALLOW_SINGLE_BUCKET + 4)); | |
| 846 } | |
| 712 } | 847 } |
| 713 }; | 848 }; |
| 714 | 849 |
| 715 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic); | 850 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic); |
| 716 | 851 |
| 717 // Verifies that changing or adding an entry in a split pref results in both | 852 // Verifies that changing or adding an entry in a split pref results in both |
| 718 // items being reported (and remove if the protection level allows it). | 853 // items being reported (and remove if the protection level allows it). |
| 719 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase { | 854 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase { |
| 720 public: | 855 public: |
| 721 void SetupPreferences() override { | 856 void SetupPreferences() override { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 GetTrackedPrefHistogramCount( | 934 GetTrackedPrefHistogramCount( |
| 800 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 935 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 801 ALLOW_NONE)); | 936 ALLOW_NONE)); |
| 802 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 937 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 803 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 938 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 804 ALLOW_NONE)); | 939 ALLOW_NONE)); |
| 805 EXPECT_EQ( | 940 EXPECT_EQ( |
| 806 0, GetTrackedPrefHistogramCount( | 941 0, GetTrackedPrefHistogramCount( |
| 807 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 942 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 808 ALLOW_NONE)); | 943 ALLOW_NONE)); |
| 944 | |
| 945 if (SupportsRegistryValidation()) { | |
| 946 // Expect that the registry validation caught the invalid MAC in split | |
| 947 // pref #5 (extensions). | |
| 948 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 949 GetTrackedPrefHistogramCount( | |
| 950 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 951 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 952 BEGIN_ALLOW_SINGLE_BUCKET + 5)); | |
| 953 } | |
| 809 } | 954 } |
| 810 }; | 955 }; |
| 811 | 956 |
| 812 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref); | 957 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref); |
| 813 | 958 |
| 814 // Verifies that adding a value to unprotected preferences for a key which is | 959 // Verifies that adding a value to unprotected preferences for a key which is |
| 815 // still using the default (i.e. has no value stored in protected preferences) | 960 // still using the default (i.e. has no value stored in protected preferences) |
| 816 // doesn't allow that value to slip in with no valid MAC (regression test for | 961 // doesn't allow that value to slip in with no valid MAC (regression test for |
| 817 // http://crbug.com/414554) | 962 // http://crbug.com/414554) |
| 818 class PrefHashBrowserTestUntrustedAdditionToPrefs | 963 class PrefHashBrowserTestUntrustedAdditionToPrefs |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 GetTrackedPrefHistogramCount( | 1017 GetTrackedPrefHistogramCount( |
| 873 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 1018 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 874 ALLOW_NONE)); | 1019 ALLOW_NONE)); |
| 875 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 1020 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 876 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 1021 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 877 ALLOW_NONE)); | 1022 ALLOW_NONE)); |
| 878 EXPECT_EQ( | 1023 EXPECT_EQ( |
| 879 0, GetTrackedPrefHistogramCount( | 1024 0, GetTrackedPrefHistogramCount( |
| 880 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 1025 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 881 ALLOW_NONE)); | 1026 ALLOW_NONE)); |
| 1027 | |
| 1028 if (SupportsRegistryValidation()) { | |
| 1029 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && | |
| 1030 protection_level_ < PROTECTION_ENABLED_BASIC) | |
| 1031 ? changed_expected | |
| 1032 : 0, | |
| 1033 GetTrackedPrefHistogramCount( | |
| 1034 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 1035 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 1036 BEGIN_ALLOW_SINGLE_BUCKET + 3)); | |
| 1037 } | |
| 882 } | 1038 } |
| 883 }; | 1039 }; |
| 884 | 1040 |
| 885 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs, | 1041 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs, |
| 886 UntrustedAdditionToPrefs); | 1042 UntrustedAdditionToPrefs); |
| 887 | 1043 |
| 888 // Verifies that adding a value to unprotected preferences while wiping a | 1044 // Verifies that adding a value to unprotected preferences while wiping a |
| 889 // user-selected value from protected preferences doesn't allow that value to | 1045 // user-selected value from protected preferences doesn't allow that value to |
| 890 // slip in with no valid MAC (regression test for http://crbug.com/414554). | 1046 // slip in with no valid MAC (regression test for http://crbug.com/414554). |
| 891 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe | 1047 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 GetTrackedPrefHistogramCount( | 1102 GetTrackedPrefHistogramCount( |
| 947 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 1103 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 948 ALLOW_NONE)); | 1104 ALLOW_NONE)); |
| 949 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 1105 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 950 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 1106 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 951 ALLOW_NONE)); | 1107 ALLOW_NONE)); |
| 952 EXPECT_EQ( | 1108 EXPECT_EQ( |
| 953 0, GetTrackedPrefHistogramCount( | 1109 0, GetTrackedPrefHistogramCount( |
| 954 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 1110 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 955 ALLOW_NONE)); | 1111 ALLOW_NONE)); |
| 1112 | |
| 1113 if (SupportsRegistryValidation()) { | |
| 1114 EXPECT_EQ(changed_expected, | |
| 1115 GetTrackedPrefHistogramCount( | |
| 1116 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 1117 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 1118 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 1119 EXPECT_EQ(cleared_expected, | |
| 1120 GetTrackedPrefHistogramCount( | |
| 1121 user_prefs::tracked::kTrackedPrefHistogramCleared, | |
| 1122 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 1123 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 1124 } | |
| 956 } | 1125 } |
| 957 }; | 1126 }; |
| 958 | 1127 |
| 959 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe, | 1128 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe, |
| 960 UntrustedAdditionToPrefsAfterWipe); | 1129 UntrustedAdditionToPrefsAfterWipe); |
| 1130 | |
| 1131 #if defined(OS_WIN) | |
| 1132 class PrefHashBrowserTestRegistryValidationFailure | |
| 1133 : public PrefHashBrowserTestBase { | |
| 1134 public: | |
| 1135 void SetupPreferences() override { | |
| 1136 profile()->GetPrefs()->SetString(prefs::kHomePage, "http://example.com"); | |
| 1137 } | |
| 1138 | |
| 1139 void AttackPreferencesOnDisk( | |
| 1140 base::DictionaryValue* unprotected_preferences, | |
| 1141 base::DictionaryValue* protected_preferences) override { | |
| 1142 base::string16 registry_key = | |
| 1143 GetRegistryPathForTestProfile() + L"\\PreferenceMACs\\Default"; | |
| 1144 base::win::RegKey key; | |
| 1145 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, registry_key.c_str(), | |
| 1146 KEY_SET_VALUE | KEY_WOW64_32KEY)); | |
| 1147 // An incorrect hash should still have the correct size. | |
| 1148 ASSERT_EQ(ERROR_SUCCESS, | |
| 1149 key.WriteValue(L"homepage", base::string16(64, 'A').c_str())); | |
| 1150 } | |
| 1151 | |
| 1152 void VerifyReactionToPrefAttack() override { | |
| 1153 EXPECT_EQ( | |
| 1154 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 1155 ? num_tracked_prefs() | |
| 1156 : 0, | |
| 1157 GetTrackedPrefHistogramCount( | |
| 1158 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY)); | |
| 1159 | |
| 1160 if (SupportsRegistryValidation()) { | |
| 1161 // Expect that the registry validation caught the invalid MAC for pref #2 | |
| 1162 // (homepage). | |
| 1163 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 1164 GetTrackedPrefHistogramCount( | |
| 1165 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 1166 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 1167 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 1168 } | |
| 1169 } | |
| 1170 }; | |
| 1171 | |
| 1172 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestRegistryValidationFailure, | |
| 1173 RegistryValidationFailure); | |
| 1174 #endif | |
| OLD | NEW |