diff options
author | Bertrand SIMONNET <bsimonnet@google.com> | 2015-11-17 13:20:06 -0800 |
---|---|---|
committer | Bertrand SIMONNET <bsimonnet@google.com> | 2015-11-17 13:22:30 -0800 |
commit | b723585d7ec0323ab02df05a5f02927be3a852b6 (patch) | |
tree | 8458c8e3f9a498b1293234245b4dcbc3ab9865af | |
parent | 9e35650d38266973fd8d9843511ff709eddcb0d1 (diff) | |
download | metricsd-b723585d7ec0323ab02df05a5f02927be3a852b6.tar.gz |
metricsd: Don't upload if product id is empty.
If the product id is not set, the product_id file might exist but be
empty. In this case, to try to update the metrics.
Bug: 25745391
Change-Id: I3942afaf38921b44ddb7e5a29d5d0e4fb6d48d94
Test: Unit tests.
-rw-r--r-- | uploader/system_profile_cache.cc | 3 | ||||
-rw-r--r-- | uploader/system_profile_cache.h | 1 | ||||
-rw-r--r-- | uploader/upload_service_test.cc | 11 |
3 files changed, 14 insertions, 1 deletions
diff --git a/uploader/system_profile_cache.cc b/uploader/system_profile_cache.cc index 637cf9e..7a5eb93 100644 --- a/uploader/system_profile_cache.cc +++ b/uploader/system_profile_cache.cc @@ -87,7 +87,8 @@ bool SystemProfileCache::Initialize() { } } - if (!reader.GetString(metrics::kProductId, &profile_.product_id)) { + if (!reader.GetString(metrics::kProductId, &profile_.product_id) + || profile_.product_id.empty()) { LOG(ERROR) << "product_id is not set."; return false; } diff --git a/uploader/system_profile_cache.h b/uploader/system_profile_cache.h index ae54a2a..0a21ad4 100644 --- a/uploader/system_profile_cache.h +++ b/uploader/system_profile_cache.h @@ -69,6 +69,7 @@ class SystemProfileCache : public SystemProfileSetter { FRIEND_TEST(UploadServiceTest, ReadKeyValueFromFile); FRIEND_TEST(UploadServiceTest, SessionIdIncrementedAtInitialization); FRIEND_TEST(UploadServiceTest, ValuesInConfigFileAreSent); + FRIEND_TEST(UploadServiceTest, ProductIdMandatory); // Fetches all informations and populates |profile_| bool Initialize(); diff --git a/uploader/upload_service_test.cc b/uploader/upload_service_test.cc index 47e7b91..e80db96 100644 --- a/uploader/upload_service_test.cc +++ b/uploader/upload_service_test.cc @@ -291,3 +291,14 @@ TEST_F(UploadServiceTest, LogFromTheMetricsLibrary) { EXPECT_EQ(1, sender->send_call_count()); } + +// The product id must be set for metrics to be uploaded. +// If it is not set, the system profile cache should fail to initialize. +TEST_F(UploadServiceTest, ProductIdMandatory) { + SystemProfileCache cache(true, dir_.path()); + ASSERT_FALSE(cache.Initialize()); + SetTestingProperty(metrics::kProductId, ""); + ASSERT_FALSE(cache.Initialize()); + SetTestingProperty(metrics::kProductId, "hello"); + ASSERT_TRUE(cache.Initialize()); +} |