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[] = | |
| 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 != 0) | |
| 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 base::string16 registry_key = GetRegistryPathForTestProfile(); | |
| 276 ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting( | |
| 277 registry_key); | |
| 278 | |
| 279 // For PRE tests, delete the Registry key to avoid collisions. | |
| 280 if (IsPRETest()) { | |
| 281 base::win::RegKey key; | |
| 282 if (key.Open(HKEY_CURRENT_USER, registry_key.c_str(), | |
| 283 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
| 284 LONG result = key.DeleteKey(L""); | |
| 285 ASSERT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | |
| 286 } | |
| 287 } | |
| 288 #endif | |
| 289 } | |
| 290 | |
| 291 void TearDown() override { | |
| 292 #if defined(OS_WIN) | |
| 293 // For non-PRE tests, delete the Registry key to avoid polluting the | |
| 294 // registry. | |
| 295 // TODO(proberge): it would be nice to delete keys from interrupted tests | |
| 296 // as well. | |
|
gab
2016/09/21 17:55:30
If you mean tests that fail by assertion, I think
proberge
2016/09/21 21:09:24
Yeah I meant by crash (or CTRL-C). There's some lo
gab
2016/09/22 18:38:28
I see, but if we're going to re-use too much of te
proberge
2016/09/22 19:10:15
Thinking about it a bit more, the cleanup logic re
| |
| 297 if (!IsPRETest()) { | |
| 298 base::string16 registry_key = GetRegistryPathForTestProfile(); | |
| 299 base::win::RegKey key; | |
| 300 if (key.Open(HKEY_CURRENT_USER, registry_key.c_str(), | |
| 301 KEY_SET_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { | |
| 302 LONG result = key.DeleteKey(L""); | |
| 303 ASSERT_TRUE(result == ERROR_SUCCESS || result == ERROR_FILE_NOT_FOUND); | |
| 304 } | |
| 305 } | |
| 306 #endif | |
| 307 ExtensionBrowserTest::TearDown(); | |
| 236 } | 308 } |
| 237 | 309 |
| 238 // In the PRE_ test, find the number of tracked preferences that were | 310 // 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 | 311 // 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. | 312 // as the total number of tracked preferences. |
| 241 void SetUpOnMainThread() override { | 313 void SetUpOnMainThread() override { |
| 242 ExtensionBrowserTest::SetUpOnMainThread(); | 314 ExtensionBrowserTest::SetUpOnMainThread(); |
| 243 | 315 |
| 244 // File in which the PRE_ test will save the number of tracked preferences | 316 // File in which the PRE_ test will save the number of tracked preferences |
| 245 // on this platform. | 317 // on this platform. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 259 | 331 |
| 260 // Split tracked prefs are reported as Unchanged not as NullInitialized | 332 // Split tracked prefs are reported as Unchanged not as NullInitialized |
| 261 // when an empty dictionary is encountered on first run (this should only | 333 // when an empty dictionary is encountered on first run (this should only |
| 262 // hit for pref #5 in the current design). | 334 // hit for pref #5 in the current design). |
| 263 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( | 335 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( |
| 264 user_prefs::tracked::kTrackedPrefHistogramUnchanged, | 336 user_prefs::tracked::kTrackedPrefHistogramUnchanged, |
| 265 BEGIN_ALLOW_SINGLE_BUCKET + 5); | 337 BEGIN_ALLOW_SINGLE_BUCKET + 5); |
| 266 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | 338 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, |
| 267 num_split_tracked_prefs); | 339 num_split_tracked_prefs); |
| 268 | 340 |
| 341 if (SupportsRegistryValidation()) { | |
| 342 // Same checks as above, but for the registry. | |
| 343 num_tracked_prefs_ = GetTrackedPrefHistogramCount( | |
| 344 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | |
| 345 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 346 ALLOW_ANY); | |
| 347 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM, | |
| 348 num_tracked_prefs_ > 0); | |
| 349 | |
| 350 int num_split_tracked_prefs = GetTrackedPrefHistogramCount( | |
| 351 user_prefs::tracked::kTrackedPrefHistogramUnchanged, | |
| 352 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 353 BEGIN_ALLOW_SINGLE_BUCKET + 5); | |
| 354 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 355 num_split_tracked_prefs); | |
| 356 } | |
| 357 | |
| 269 num_tracked_prefs_ += num_split_tracked_prefs; | 358 num_tracked_prefs_ += num_split_tracked_prefs; |
| 270 | 359 |
| 271 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_); | 360 std::string num_tracked_prefs_str = base::IntToString(num_tracked_prefs_); |
| 272 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()), | 361 EXPECT_EQ(static_cast<int>(num_tracked_prefs_str.size()), |
| 273 base::WriteFile(num_tracked_prefs_file, | 362 base::WriteFile(num_tracked_prefs_file, |
| 274 num_tracked_prefs_str.c_str(), | 363 num_tracked_prefs_str.c_str(), |
| 275 num_tracked_prefs_str.size())); | 364 num_tracked_prefs_str.size())); |
| 276 } else { | 365 } else { |
| 277 std::string num_tracked_prefs_str; | 366 std::string num_tracked_prefs_str; |
| 278 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file, | 367 EXPECT_TRUE(base::ReadFileToString(num_tracked_prefs_file, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 GetTrackedPrefHistogramCount( | 489 GetTrackedPrefHistogramCount( |
| 401 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 490 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 402 ALLOW_NONE)); | 491 ALLOW_NONE)); |
| 403 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 492 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 404 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 493 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 405 ALLOW_NONE)); | 494 ALLOW_NONE)); |
| 406 EXPECT_EQ( | 495 EXPECT_EQ( |
| 407 0, GetTrackedPrefHistogramCount( | 496 0, GetTrackedPrefHistogramCount( |
| 408 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 497 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 409 ALLOW_NONE)); | 498 ALLOW_NONE)); |
| 499 | |
| 500 if (SupportsRegistryValidation()) { | |
| 501 // Expect all prefs to be reported as Unchanged with no resets. | |
| 502 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 503 ? num_tracked_prefs() | |
| 504 : 0, | |
| 505 GetTrackedPrefHistogramCount( | |
| 506 user_prefs::tracked::kTrackedPrefHistogramUnchanged, | |
| 507 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 508 ALLOW_ANY)); | |
| 509 } | |
| 410 } | 510 } |
| 411 }; | 511 }; |
| 412 | 512 |
| 413 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault); | 513 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUnchangedDefault, UnchangedDefault); |
| 414 | 514 |
| 415 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset | 515 // Augments PrefHashBrowserTestUnchangedDefault to confirm that nothing is reset |
| 416 // when nothing is tampered with, even if Chrome itself wrote custom prefs in | 516 // when nothing is tampered with, even if Chrome itself wrote custom prefs in |
| 417 // its last run. | 517 // its last run. |
| 418 class PrefHashBrowserTestUnchangedCustom | 518 class PrefHashBrowserTestUnchangedCustom |
| 419 : public PrefHashBrowserTestUnchangedDefault { | 519 : public PrefHashBrowserTestUnchangedDefault { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 GetTrackedPrefHistogramCount( | 590 GetTrackedPrefHistogramCount( |
| 491 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 591 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 492 ALLOW_NONE)); | 592 ALLOW_NONE)); |
| 493 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 593 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 494 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 594 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 495 ALLOW_NONE)); | 595 ALLOW_NONE)); |
| 496 EXPECT_EQ( | 596 EXPECT_EQ( |
| 497 0, GetTrackedPrefHistogramCount( | 597 0, GetTrackedPrefHistogramCount( |
| 498 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 598 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 499 ALLOW_NONE)); | 599 ALLOW_NONE)); |
| 600 | |
| 601 if (SupportsRegistryValidation()) { | |
| 602 // Expect homepage to have been cleared. | |
| 603 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 604 GetTrackedPrefHistogramCount( | |
| 605 user_prefs::tracked::kTrackedPrefHistogramCleared, | |
| 606 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 607 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 608 } | |
| 500 } | 609 } |
| 501 }; | 610 }; |
| 502 | 611 |
| 503 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic); | 612 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestClearedAtomic, ClearedAtomic); |
| 504 | 613 |
| 505 // Verifies that clearing the MACs results in untrusted Initialized pings for | 614 // Verifies that clearing the MACs results in untrusted Initialized pings for |
| 506 // non-null protected prefs. | 615 // non-null protected prefs. |
| 507 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase { | 616 class PrefHashBrowserTestUntrustedInitialized : public PrefHashBrowserTestBase { |
| 508 public: | 617 public: |
| 509 void SetupPreferences() override { | 618 void SetupPreferences() override { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 EXPECT_EQ( | 721 EXPECT_EQ( |
| 613 0, GetTrackedPrefHistogramCount( | 722 0, GetTrackedPrefHistogramCount( |
| 614 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); | 723 user_prefs::tracked::kTrackedPrefHistogramChanged, ALLOW_NONE)); |
| 615 EXPECT_EQ( | 724 EXPECT_EQ( |
| 616 0, GetTrackedPrefHistogramCount( | 725 0, GetTrackedPrefHistogramCount( |
| 617 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); | 726 user_prefs::tracked::kTrackedPrefHistogramCleared, ALLOW_NONE)); |
| 618 EXPECT_EQ( | 727 EXPECT_EQ( |
| 619 0, GetTrackedPrefHistogramCount( | 728 0, GetTrackedPrefHistogramCount( |
| 620 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 729 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 621 ALLOW_NONE)); | 730 ALLOW_NONE)); |
| 731 | |
| 732 if (SupportsRegistryValidation()) { | |
| 733 // The MACs have been cleared but the preferences have not been tampered. | |
| 734 // The registry should report all prefs as unchanged. | |
| 735 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 736 ? num_tracked_prefs() | |
| 737 : 0, | |
| 738 GetTrackedPrefHistogramCount( | |
| 739 user_prefs::tracked::kTrackedPrefHistogramUnchanged, | |
| 740 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 741 ALLOW_ANY)); | |
| 742 } | |
| 622 } | 743 } |
| 623 }; | 744 }; |
| 624 | 745 |
| 625 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized, | 746 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedInitialized, |
| 626 UntrustedInitialized); | 747 UntrustedInitialized); |
| 627 | 748 |
| 628 // Verifies that changing an atomic pref results in it being reported (and reset | 749 // Verifies that changing an atomic pref results in it being reported (and reset |
| 629 // if the protection level allows it). | 750 // if the protection level allows it). |
| 630 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase { | 751 class PrefHashBrowserTestChangedAtomic : public PrefHashBrowserTestBase { |
| 631 public: | 752 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 GetTrackedPrefHistogramCount( | 823 GetTrackedPrefHistogramCount( |
| 703 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 824 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 704 ALLOW_NONE)); | 825 ALLOW_NONE)); |
| 705 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 826 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 706 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 827 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 707 ALLOW_NONE)); | 828 ALLOW_NONE)); |
| 708 EXPECT_EQ( | 829 EXPECT_EQ( |
| 709 0, GetTrackedPrefHistogramCount( | 830 0, GetTrackedPrefHistogramCount( |
| 710 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 831 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 711 ALLOW_NONE)); | 832 ALLOW_NONE)); |
| 833 | |
| 834 if (SupportsRegistryValidation()) { | |
| 835 // Expect a single Changed event for tracked pref #4 (startup URLs). | |
| 836 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 837 GetTrackedPrefHistogramCount( | |
| 838 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 839 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 840 BEGIN_ALLOW_SINGLE_BUCKET + 4)); | |
| 841 } | |
| 712 } | 842 } |
| 713 }; | 843 }; |
| 714 | 844 |
| 715 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic); | 845 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedAtomic, ChangedAtomic); |
| 716 | 846 |
| 717 // Verifies that changing or adding an entry in a split pref results in both | 847 // 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). | 848 // items being reported (and remove if the protection level allows it). |
| 719 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase { | 849 class PrefHashBrowserTestChangedSplitPref : public PrefHashBrowserTestBase { |
| 720 public: | 850 public: |
| 721 void SetupPreferences() override { | 851 void SetupPreferences() override { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 GetTrackedPrefHistogramCount( | 929 GetTrackedPrefHistogramCount( |
| 800 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 930 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 801 ALLOW_NONE)); | 931 ALLOW_NONE)); |
| 802 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 932 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 803 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 933 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 804 ALLOW_NONE)); | 934 ALLOW_NONE)); |
| 805 EXPECT_EQ( | 935 EXPECT_EQ( |
| 806 0, GetTrackedPrefHistogramCount( | 936 0, GetTrackedPrefHistogramCount( |
| 807 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 937 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 808 ALLOW_NONE)); | 938 ALLOW_NONE)); |
| 939 | |
| 940 if (SupportsRegistryValidation()) { | |
| 941 // Expect a single split pref changed report with a count of 2 for tracked | |
| 942 // pref #5 (extensions). | |
| 943 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 944 GetTrackedPrefHistogramCount( | |
| 945 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 946 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 947 BEGIN_ALLOW_SINGLE_BUCKET + 5)); | |
| 948 } | |
| 809 } | 949 } |
| 810 }; | 950 }; |
| 811 | 951 |
| 812 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref); | 952 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestChangedSplitPref, ChangedSplitPref); |
| 813 | 953 |
| 814 // Verifies that adding a value to unprotected preferences for a key which is | 954 // 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) | 955 // 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 | 956 // doesn't allow that value to slip in with no valid MAC (regression test for |
| 817 // http://crbug.com/414554) | 957 // http://crbug.com/414554) |
| 818 class PrefHashBrowserTestUntrustedAdditionToPrefs | 958 class PrefHashBrowserTestUntrustedAdditionToPrefs |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 GetTrackedPrefHistogramCount( | 1012 GetTrackedPrefHistogramCount( |
| 873 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 1013 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 874 ALLOW_NONE)); | 1014 ALLOW_NONE)); |
| 875 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 1015 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 876 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 1016 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 877 ALLOW_NONE)); | 1017 ALLOW_NONE)); |
| 878 EXPECT_EQ( | 1018 EXPECT_EQ( |
| 879 0, GetTrackedPrefHistogramCount( | 1019 0, GetTrackedPrefHistogramCount( |
| 880 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 1020 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 881 ALLOW_NONE)); | 1021 ALLOW_NONE)); |
| 1022 | |
| 1023 if (SupportsRegistryValidation()) { | |
| 1024 EXPECT_EQ((protection_level_ > PROTECTION_DISABLED_ON_PLATFORM && | |
| 1025 protection_level_ < PROTECTION_ENABLED_BASIC) | |
| 1026 ? changed_expected | |
| 1027 : 0, | |
| 1028 GetTrackedPrefHistogramCount( | |
| 1029 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 1030 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 1031 BEGIN_ALLOW_SINGLE_BUCKET + 3)); | |
| 1032 } | |
| 882 } | 1033 } |
| 883 }; | 1034 }; |
| 884 | 1035 |
| 885 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs, | 1036 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefs, |
| 886 UntrustedAdditionToPrefs); | 1037 UntrustedAdditionToPrefs); |
| 887 | 1038 |
| 888 // Verifies that adding a value to unprotected preferences while wiping a | 1039 // Verifies that adding a value to unprotected preferences while wiping a |
| 889 // user-selected value from protected preferences doesn't allow that value to | 1040 // 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). | 1041 // slip in with no valid MAC (regression test for http://crbug.com/414554). |
| 891 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe | 1042 class PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 GetTrackedPrefHistogramCount( | 1097 GetTrackedPrefHistogramCount( |
| 947 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, | 1098 user_prefs::tracked::kTrackedPrefHistogramTrustedInitialized, |
| 948 ALLOW_NONE)); | 1099 ALLOW_NONE)); |
| 949 EXPECT_EQ(0, GetTrackedPrefHistogramCount( | 1100 EXPECT_EQ(0, GetTrackedPrefHistogramCount( |
| 950 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, | 1101 user_prefs::tracked::kTrackedPrefHistogramNullInitialized, |
| 951 ALLOW_NONE)); | 1102 ALLOW_NONE)); |
| 952 EXPECT_EQ( | 1103 EXPECT_EQ( |
| 953 0, GetTrackedPrefHistogramCount( | 1104 0, GetTrackedPrefHistogramCount( |
| 954 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, | 1105 user_prefs::tracked::kTrackedPrefHistogramMigratedLegacyDeviceId, |
| 955 ALLOW_NONE)); | 1106 ALLOW_NONE)); |
| 1107 | |
| 1108 if (SupportsRegistryValidation()) { | |
| 1109 EXPECT_EQ(changed_expected, | |
| 1110 GetTrackedPrefHistogramCount( | |
| 1111 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 1112 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 1113 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 1114 EXPECT_EQ(cleared_expected, | |
| 1115 GetTrackedPrefHistogramCount( | |
| 1116 user_prefs::tracked::kTrackedPrefHistogramCleared, | |
| 1117 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 1118 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 1119 } | |
| 956 } | 1120 } |
| 957 }; | 1121 }; |
| 958 | 1122 |
| 959 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe, | 1123 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestUntrustedAdditionToPrefsAfterWipe, |
| 960 UntrustedAdditionToPrefsAfterWipe); | 1124 UntrustedAdditionToPrefsAfterWipe); |
| 1125 class PrefHashBrowserTestRegistryValidationFailure | |
| 1126 : public PrefHashBrowserTestBase { | |
| 1127 public: | |
| 1128 void SetupPreferences() override { | |
| 1129 profile()->GetPrefs()->SetString(prefs::kHomePage, "http://example.com"); | |
| 1130 } | |
| 1131 | |
| 1132 void AttackPreferencesOnDisk( | |
| 1133 base::DictionaryValue* unprotected_preferences, | |
| 1134 base::DictionaryValue* protected_preferences) override { | |
| 1135 #if defined(OS_WIN) | |
|
gab
2016/09/21 17:55:30
Wrap the 1125-1166 in the if-def? Or is there a po
proberge
2016/09/21 21:09:25
Done.
| |
| 1136 base::string16 registry_key = | |
| 1137 GetRegistryPathForTestProfile() + L"\\PreferenceMACs\\Default"; | |
| 1138 base::win::RegKey key; | |
| 1139 ASSERT_EQ(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, registry_key.c_str(), | |
| 1140 KEY_SET_VALUE | KEY_WOW64_32KEY)); | |
| 1141 // An incorrect hash should still have the correct size. | |
| 1142 ASSERT_EQ(ERROR_SUCCESS, | |
| 1143 key.WriteValue(L"homepage", base::string16(64, 'A').c_str())); | |
| 1144 #endif | |
| 1145 } | |
| 1146 | |
| 1147 void VerifyReactionToPrefAttack() override { | |
| 1148 EXPECT_EQ( | |
| 1149 protection_level_ > PROTECTION_DISABLED_ON_PLATFORM | |
| 1150 ? num_tracked_prefs() | |
| 1151 : 0, | |
| 1152 GetTrackedPrefHistogramCount( | |
| 1153 user_prefs::tracked::kTrackedPrefHistogramUnchanged, ALLOW_ANY)); | |
| 1154 | |
| 1155 if (SupportsRegistryValidation()) { | |
| 1156 EXPECT_EQ(protection_level_ > PROTECTION_DISABLED_ON_PLATFORM ? 1 : 0, | |
| 1157 GetTrackedPrefHistogramCount( | |
| 1158 user_prefs::tracked::kTrackedPrefHistogramChanged, | |
| 1159 user_prefs::tracked::kTrackedPrefRegistryValidationSuffix, | |
| 1160 BEGIN_ALLOW_SINGLE_BUCKET + 2)); | |
| 1161 } | |
| 1162 } | |
| 1163 }; | |
| 1164 | |
| 1165 PREF_HASH_BROWSER_TEST(PrefHashBrowserTestRegistryValidationFailure, | |
| 1166 RegistryValidationFailure); | |
| OLD | NEW |