summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand Simonnet <bsimonnet@google.com>2015-11-17 21:51:21 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-11-17 21:51:21 +0000
commit0ba260644440f51cd5e1d8db10bebf4c041ec7e7 (patch)
tree7c66b38284b43153e25da4fe1c49fc130424d9b9
parent1337349ea11a6bb5c44ba5c5bb064c750bd626c5 (diff)
parent1d15d46e1758052d25436e78487d5a778d0a3bc6 (diff)
downloadcore-0ba260644440f51cd5e1d8db10bebf4c041ec7e7.tar.gz
core-0ba260644440f51cd5e1d8db10bebf4c041ec7e7.tar.bz2
core-0ba260644440f51cd5e1d8db10bebf4c041ec7e7.zip
Merge "metricsd: Don't upload if product id is empty."
-rw-r--r--metricsd/uploader/system_profile_cache.cc3
-rw-r--r--metricsd/uploader/system_profile_cache.h1
-rw-r--r--metricsd/uploader/upload_service_test.cc11
3 files changed, 14 insertions, 1 deletions
diff --git a/metricsd/uploader/system_profile_cache.cc b/metricsd/uploader/system_profile_cache.cc
index 637cf9e68..7a5eb9329 100644
--- a/metricsd/uploader/system_profile_cache.cc
+++ b/metricsd/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/metricsd/uploader/system_profile_cache.h b/metricsd/uploader/system_profile_cache.h
index ae54a2a42..0a21ad4f4 100644
--- a/metricsd/uploader/system_profile_cache.h
+++ b/metricsd/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/metricsd/uploader/upload_service_test.cc b/metricsd/uploader/upload_service_test.cc
index 47e7b917c..e80db967d 100644
--- a/metricsd/uploader/upload_service_test.cc
+++ b/metricsd/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());
+}