Chromium Code Reviews| Index: chrome/browser/metrics/variations/variations_seed_store_unittest.cc |
| diff --git a/chrome/browser/metrics/variations/variations_seed_store_unittest.cc b/chrome/browser/metrics/variations/variations_seed_store_unittest.cc |
| index 6f42c807bf3360a0ef55cdc61ad66638707468b4..cf3e0de1f3f7a5785b43fda6ac21dce309160db0 100644 |
| --- a/chrome/browser/metrics/variations/variations_seed_store_unittest.cc |
| +++ b/chrome/browser/metrics/variations/variations_seed_store_unittest.cc |
| @@ -126,6 +126,56 @@ TEST(VariationsSeedStoreTest, LoadSeed) { |
| EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed)); |
| } |
| +TEST(VariationsSeedStoreTest, GetInvalidSignature) { |
| + const variations::VariationsSeed seed = CreateTestSeed(); |
| + std::string seed_hash; |
| + const std::string base64_seed = SerializeSeedBase64(seed, &seed_hash); |
| + |
| + TestingPrefServiceSimple prefs; |
| + VariationsSeedStore::RegisterPrefs(prefs.registry()); |
| + prefs.SetString(prefs::kVariationsSeed, base64_seed); |
| + |
| + variations::VariationsSeed loaded_seed; |
|
Alexei Svitkine (slow)
2014/10/15 14:53:07
Nit: Move this closer to where it's used - i.e. ab
Georges Khalil
2014/10/15 16:53:19
Done.
|
| + |
| + // The below seed and signature pair were generated using the server's |
| + // private key. |
| + const std::string base64_seed_data = |
| + "CigxZDI5NDY0ZmIzZDc4ZmYxNTU2ZTViNTUxYzY0NDdjYmM3NGU1ZmQwEr0BCh9VTUEtVW5p" |
| + "Zm9ybWl0eS1UcmlhbC0xMC1QZXJjZW50GICckqUFOAFCB2RlZmF1bHRKCwoHZGVmYXVsdBAB" |
| + "SgwKCGdyb3VwXzAxEAFKDAoIZ3JvdXBfMDIQAUoMCghncm91cF8wMxABSgwKCGdyb3VwXzA0" |
| + "EAFKDAoIZ3JvdXBfMDUQAUoMCghncm91cF8wNhABSgwKCGdyb3VwXzA3EAFKDAoIZ3JvdXBf" |
| + "MDgQAUoMCghncm91cF8wORAB"; |
| + const std::string base64_seed_signature = |
| + "MEQCIDD1IVxjzWYncun+9IGzqYjZvqxxujQEayJULTlbTGA/AiAr0oVmEgVUQZBYq5VLOSvy" |
| + "96JkMYgzTkHPwbv7K/CmgA=="; |
| + const std::string base64_seed_signature_invalid = |
| + "AEQCIDD1IVxjzWYncun+9IGzqYjZvqxxujQEayJULTlbTGA/AiAr0oVmEgVUQZBYq5VLOSvy" |
| + "96JkMYgzTkHPwbv7K/CmgA=="; |
| + |
| + // Set seed and valid signature in prefs. |
| + prefs.SetString(prefs::kVariationsSeed, base64_seed_data); |
| + prefs.SetString(prefs::kVariationsSeedSignature, base64_seed_signature); |
| + |
| + VariationsSeedStore seed_store(&prefs); |
| + seed_store.LoadSeed(&loaded_seed); |
| + std::string invalid_signature = seed_store.GetInvalidSignature(); |
| + // Valid signature so we get an empty string. |
| + EXPECT_EQ("", invalid_signature); |
| + |
| + prefs.SetString(prefs::kVariationsSeedSignature, |
| + base64_seed_signature_invalid); |
| + seed_store.LoadSeed(&loaded_seed); |
| + // Invalid signature, so we should get the signature itself. |
| + invalid_signature = seed_store.GetInvalidSignature(); |
| + EXPECT_EQ(base64_seed_signature_invalid, invalid_signature); |
| + |
| + prefs.SetString(prefs::kVariationsSeedSignature, std::string()); |
| + seed_store.LoadSeed(&loaded_seed); |
| + invalid_signature = seed_store.GetInvalidSignature(); |
| + // Empty signature, not considered invalid. |
| + EXPECT_EQ("", invalid_signature); |
|
Alexei Svitkine (slow)
2014/10/15 14:53:07
Nit: std::string() instead of "". Same thing above
Georges Khalil
2014/10/15 16:53:19
Done.
|
| +} |
| + |
| TEST(VariationsSeedStoreTest, StoreSeedData) { |
| const variations::VariationsSeed seed = CreateTestSeed(); |
| const std::string serialized_seed = SerializeSeed(seed); |