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