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

Unified Diff: components/feedback/feedback_common_unittest.cc

Issue 1530403003: Add anonymizer tool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Vasilii's comments Created 5 years 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: components/feedback/feedback_common_unittest.cc
diff --git a/components/feedback/feedback_common_unittest.cc b/components/feedback/feedback_common_unittest.cc
index d3fb9502210c7de0d591c84275b96038a58a6793..d47105bbe2f92cbdf4ff17ea5c1cb13a7de53c42 100644
--- a/components/feedback/feedback_common_unittest.cc
+++ b/components/feedback/feedback_common_unittest.cc
@@ -5,12 +5,14 @@
#include "components/feedback/feedback_common.h"
#include "base/bind.h"
+#include "base/files/scoped_temp_dir.h"
#include "components/feedback/proto/common.pb.h"
#include "components/feedback/proto/dom.pb.h"
#include "components/feedback/proto/extension.pb.h"
#include "components/feedback/proto/math.pb.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/zlib/google/zip.h"
namespace {
const char kOne[] = "one";
@@ -20,60 +22,100 @@ const char kFour[] = "four";
#define TEN_LINES "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n"
const char kLongLog[] = TEN_LINES TEN_LINES TEN_LINES TEN_LINES TEN_LINES;
const char kLogsAttachmentName[] = "system_logs.zip";
+const char kLogsFilename[] = "system_logs.txt";
} // namespace
class FeedbackCommonTest : public testing::Test {
protected:
FeedbackCommonTest() {
- feedback = scoped_refptr<FeedbackCommon>(new FeedbackCommon());
+ feedback_ = scoped_refptr<FeedbackCommon>(new FeedbackCommon());
}
~FeedbackCommonTest() override {}
- scoped_refptr<FeedbackCommon> feedback;
- userfeedback::ExtensionSubmit report;
+ scoped_refptr<FeedbackCommon> feedback_;
+ userfeedback::ExtensionSubmit report_;
};
TEST_F(FeedbackCommonTest, TestBasicData) {
// Test that basic data can be set and propagates to the request.
- feedback->set_category_tag(kOne);
- feedback->set_description(kTwo);
- feedback->set_page_url(kThree);
- feedback->set_user_email(kFour);
- feedback->PrepareReport(&report);
-
- EXPECT_EQ(kOne, report.bucket());
- EXPECT_EQ(kTwo, report.common_data().description());
- EXPECT_EQ(kThree, report.web_data().url());
- EXPECT_EQ(kFour, report.common_data().user_email());
+ feedback_->set_category_tag(kOne);
+ feedback_->set_description(kTwo);
+ feedback_->set_page_url(kThree);
+ feedback_->set_user_email(kFour);
+ feedback_->PrepareReport(&report_);
+
+ EXPECT_EQ(kOne, report_.bucket());
+ EXPECT_EQ(kTwo, report_.common_data().description());
+ EXPECT_EQ(kThree, report_.web_data().url());
+ EXPECT_EQ(kFour, report_.common_data().user_email());
}
TEST_F(FeedbackCommonTest, TestAddLogs) {
- feedback->AddLog(kOne, kTwo);
- feedback->AddLog(kThree, kFour);
+ feedback_->AddLog(kOne, kTwo);
+ feedback_->AddLog(kThree, kFour);
- EXPECT_EQ(2U, feedback->sys_info()->size());
+ EXPECT_EQ(2U, feedback_->sys_info()->size());
}
TEST_F(FeedbackCommonTest, TestCompressionThreshold) {
// Add a large and small log, verify that only the small log gets
// included in the report.
- feedback->AddLog(kOne, kTwo);
- feedback->AddLog(kThree, kLongLog);
- feedback->PrepareReport(&report);
+ feedback_->AddLog(kOne, kTwo);
+ feedback_->AddLog(kThree, kLongLog);
+ feedback_->PrepareReport(&report_);
- EXPECT_EQ(1, report.web_data().product_specific_data_size());
- EXPECT_EQ(kOne, report.web_data().product_specific_data(0).key());
+ EXPECT_EQ(1, report_.web_data().product_specific_data_size());
+ EXPECT_EQ(kOne, report_.web_data().product_specific_data(0).key());
}
TEST_F(FeedbackCommonTest, TestCompression) {
// Add a large and small log, verify that an attachment has been
// added with the right name.
- feedback->AddLog(kOne, kTwo);
- feedback->AddLog(kThree, kLongLog);
- feedback->CompressLogs();
- feedback->PrepareReport(&report);
+ feedback_->AddLog(kOne, kTwo);
+ feedback_->AddLog(kThree, kLongLog);
+ feedback_->CompressLogs();
+ feedback_->PrepareReport(&report_);
+
+ EXPECT_EQ(1, report_.product_specific_binary_data_size());
+ EXPECT_EQ(kLogsAttachmentName,
+ report_.product_specific_binary_data(0).name());
+}
+
+TEST_F(FeedbackCommonTest, TestAddLogsAnonymization) {
+ std::string mac_address = "Some text 00:11:22:33:44:55 text";
+ std::string anonymized_mac_address = "Some text 00:11:22:00:00:01 text";
+ feedback_->AddLog(kOne, mac_address);
+ feedback_->AddLog(kThree, mac_address + kLongLog);
+ feedback_->CompressLogs();
+ feedback_->PrepareReport(&report_);
+
+ // Verify that uncompressed data is anonymized.
+ ASSERT_EQ(1, report_.web_data().product_specific_data_size());
+ EXPECT_EQ(anonymized_mac_address,
+ report_.web_data().product_specific_data(0).value());
+
+ // Verify that compressed data is anonymized.
+ ASSERT_EQ(1, report_.product_specific_binary_data_size());
+ const ::userfeedback::ProductSpecificBinaryData& binary_data =
+ report_.product_specific_binary_data(0);
+
+ base::ScopedTempDir scoped_dir;
+ ASSERT_TRUE(scoped_dir.CreateUniqueTempDir());
+ base::FilePath zip_file = scoped_dir.path().Append("logs.zip");
+
+ ASSERT_TRUE(binary_data.has_data());
+ bool success = base::WriteFile(zip_file, binary_data.data().data(),
+ binary_data.data().size());
+ ASSERT_TRUE(success);
+ success = zip::Unzip(zip_file, scoped_dir.path());
+ ASSERT_TRUE(success);
+
+ std::string file_content;
+ success = base::ReadFileToString(scoped_dir.path().Append(kLogsFilename),
+ &file_content);
+ ASSERT_TRUE(success);
- EXPECT_EQ(1, report.product_specific_binary_data_size());
- EXPECT_EQ(kLogsAttachmentName, report.product_specific_binary_data(0).name());
+ EXPECT_TRUE(file_content.find(anonymized_mac_address) != std::string::npos);
+ EXPECT_TRUE(file_content.find(mac_address) == std::string::npos);
}
« components/feedback/anonymizer_tool.h ('K') | « components/feedback/feedback_common.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698