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

Unified Diff: chrome/browser/metrics/variations/variations_seed_store_unittest.cc

Issue 183003008: Enforce variations signature verification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/variations/variations_seed_store_unittest.cc
===================================================================
--- chrome/browser/metrics/variations/variations_seed_store_unittest.cc (revision 254843)
+++ chrome/browser/metrics/variations/variations_seed_store_unittest.cc (working copy)
@@ -18,6 +18,23 @@
namespace {
+class TestVariationsSeedStore : public VariationsSeedStore {
+ public:
+ explicit TestVariationsSeedStore(PrefService* local_state)
+ : VariationsSeedStore(local_state) {}
+ virtual ~TestVariationsSeedStore() {}
+
+ virtual VariationsSeedStore::VerifySignatureResult VerifySeedSignature(
+ const std::string& seed_bytes,
+ const std::string& base64_seed_signature) OVERRIDE {
+ return VariationsSeedStore::VARIATIONS_SEED_SIGNATURE_ENUM_SIZE;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestVariationsSeedStore);
+};
+
+
// Populates |seed| with simple test data. The resulting seed will contain one
// study called "test", which contains one experiment called "abc" with
// probability weight 100. |seed|'s study field will be cleared before adding
@@ -72,7 +89,7 @@
VariationsSeedStore::RegisterPrefs(prefs.registry());
prefs.SetString(prefs::kVariationsSeed, base64_seed);
- VariationsSeedStore seed_store(&prefs);
+ TestVariationsSeedStore seed_store(&prefs);
VariationsSeed loaded_seed;
// Check that loading a seed without a hash pref set works correctly.
@@ -90,20 +107,6 @@
EXPECT_TRUE(seed_store.LoadSeed(&loaded_seed));
EXPECT_EQ(SerializeSeed(seed), SerializeSeed(loaded_seed));
- // Check that false is returned and the pref is cleared when hash differs.
- VariationsSeed different_seed = seed;
- different_seed.mutable_study(0)->set_name("octopus");
- std::string different_hash;
- prefs.SetString(prefs::kVariationsSeed,
- SerializeSeedBase64(different_seed, &different_hash));
- ASSERT_NE(different_hash, prefs.GetString(prefs::kVariationsSeedHash));
- EXPECT_FALSE(PrefHasDefaultValue(prefs, prefs::kVariationsSeed));
- EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed));
- EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeed));
- EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedDate));
- EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedHash));
- EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedSignature));
-
// Check that loading a bad seed returns false and clears the pref.
prefs.ClearPref(prefs::kVariationsSeed);
prefs.SetString(prefs::kVariationsSeed, "this should fail");
@@ -111,7 +114,6 @@
EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed));
EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeed));
EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedDate));
- EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedHash));
EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedSignature));
// Check that having no seed in prefs results in a return value of false.
@@ -127,7 +129,7 @@
TestingPrefServiceSimple prefs;
VariationsSeedStore::RegisterPrefs(prefs.registry());
- VariationsSeedStore seed_store(&prefs);
+ TestVariationsSeedStore seed_store(&prefs);
EXPECT_TRUE(seed_store.StoreSeedData(serialized_seed, std::string(), now));
// Make sure the pref was actually set.

Powered by Google App Engine
This is Rietveld 408576698