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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/feedback/feedback_common.h" 5 #include "components/feedback/feedback_common.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/scoped_temp_dir.h"
8 #include "components/feedback/proto/common.pb.h" 9 #include "components/feedback/proto/common.pb.h"
9 #include "components/feedback/proto/dom.pb.h" 10 #include "components/feedback/proto/dom.pb.h"
10 #include "components/feedback/proto/extension.pb.h" 11 #include "components/feedback/proto/extension.pb.h"
11 #include "components/feedback/proto/math.pb.h" 12 #include "components/feedback/proto/math.pb.h"
12 #include "content/public/test/test_browser_thread.h" 13 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/zlib/google/zip.h"
14 16
15 namespace { 17 namespace {
16 const char kOne[] = "one"; 18 const char kOne[] = "one";
17 const char kTwo[] = "two"; 19 const char kTwo[] = "two";
18 const char kThree[] = "three"; 20 const char kThree[] = "three";
19 const char kFour[] = "four"; 21 const char kFour[] = "four";
20 #define TEN_LINES "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" 22 #define TEN_LINES "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n"
21 const char kLongLog[] = TEN_LINES TEN_LINES TEN_LINES TEN_LINES TEN_LINES; 23 const char kLongLog[] = TEN_LINES TEN_LINES TEN_LINES TEN_LINES TEN_LINES;
22 const char kLogsAttachmentName[] = "system_logs.zip"; 24 const char kLogsAttachmentName[] = "system_logs.zip";
25 const char kLogsFilename[] = "system_logs.txt";
23 } // namespace 26 } // namespace
24 27
25 class FeedbackCommonTest : public testing::Test { 28 class FeedbackCommonTest : public testing::Test {
26 protected: 29 protected:
27 FeedbackCommonTest() { 30 FeedbackCommonTest() {
28 feedback = scoped_refptr<FeedbackCommon>(new FeedbackCommon()); 31 feedback_ = scoped_refptr<FeedbackCommon>(new FeedbackCommon());
29 } 32 }
30 33
31 ~FeedbackCommonTest() override {} 34 ~FeedbackCommonTest() override {}
32 35
33 scoped_refptr<FeedbackCommon> feedback; 36 scoped_refptr<FeedbackCommon> feedback_;
34 userfeedback::ExtensionSubmit report; 37 userfeedback::ExtensionSubmit report_;
35 }; 38 };
36 39
37 TEST_F(FeedbackCommonTest, TestBasicData) { 40 TEST_F(FeedbackCommonTest, TestBasicData) {
38 // Test that basic data can be set and propagates to the request. 41 // Test that basic data can be set and propagates to the request.
39 feedback->set_category_tag(kOne); 42 feedback_->set_category_tag(kOne);
40 feedback->set_description(kTwo); 43 feedback_->set_description(kTwo);
41 feedback->set_page_url(kThree); 44 feedback_->set_page_url(kThree);
42 feedback->set_user_email(kFour); 45 feedback_->set_user_email(kFour);
43 feedback->PrepareReport(&report); 46 feedback_->PrepareReport(&report_);
44 47
45 EXPECT_EQ(kOne, report.bucket()); 48 EXPECT_EQ(kOne, report_.bucket());
46 EXPECT_EQ(kTwo, report.common_data().description()); 49 EXPECT_EQ(kTwo, report_.common_data().description());
47 EXPECT_EQ(kThree, report.web_data().url()); 50 EXPECT_EQ(kThree, report_.web_data().url());
48 EXPECT_EQ(kFour, report.common_data().user_email()); 51 EXPECT_EQ(kFour, report_.common_data().user_email());
49 } 52 }
50 53
51 TEST_F(FeedbackCommonTest, TestAddLogs) { 54 TEST_F(FeedbackCommonTest, TestAddLogs) {
52 feedback->AddLog(kOne, kTwo); 55 feedback_->AddLog(kOne, kTwo);
53 feedback->AddLog(kThree, kFour); 56 feedback_->AddLog(kThree, kFour);
54 57
55 EXPECT_EQ(2U, feedback->sys_info()->size()); 58 EXPECT_EQ(2U, feedback_->sys_info()->size());
56 } 59 }
57 60
58 TEST_F(FeedbackCommonTest, TestCompressionThreshold) { 61 TEST_F(FeedbackCommonTest, TestCompressionThreshold) {
59 // Add a large and small log, verify that only the small log gets 62 // Add a large and small log, verify that only the small log gets
60 // included in the report. 63 // included in the report.
61 feedback->AddLog(kOne, kTwo); 64 feedback_->AddLog(kOne, kTwo);
62 feedback->AddLog(kThree, kLongLog); 65 feedback_->AddLog(kThree, kLongLog);
63 feedback->PrepareReport(&report); 66 feedback_->PrepareReport(&report_);
64 67
65 EXPECT_EQ(1, report.web_data().product_specific_data_size()); 68 EXPECT_EQ(1, report_.web_data().product_specific_data_size());
66 EXPECT_EQ(kOne, report.web_data().product_specific_data(0).key()); 69 EXPECT_EQ(kOne, report_.web_data().product_specific_data(0).key());
67 } 70 }
68 71
69 TEST_F(FeedbackCommonTest, TestCompression) { 72 TEST_F(FeedbackCommonTest, TestCompression) {
70 // Add a large and small log, verify that an attachment has been 73 // Add a large and small log, verify that an attachment has been
71 // added with the right name. 74 // added with the right name.
72 feedback->AddLog(kOne, kTwo); 75 feedback_->AddLog(kOne, kTwo);
73 feedback->AddLog(kThree, kLongLog); 76 feedback_->AddLog(kThree, kLongLog);
74 feedback->CompressLogs(); 77 feedback_->CompressLogs();
75 feedback->PrepareReport(&report); 78 feedback_->PrepareReport(&report_);
76 79
77 EXPECT_EQ(1, report.product_specific_binary_data_size()); 80 EXPECT_EQ(1, report_.product_specific_binary_data_size());
78 EXPECT_EQ(kLogsAttachmentName, report.product_specific_binary_data(0).name()); 81 EXPECT_EQ(kLogsAttachmentName,
82 report_.product_specific_binary_data(0).name());
79 } 83 }
84
85 TEST_F(FeedbackCommonTest, TestAddLogsAnonymization) {
86 std::string mac_address = "Some text 00:11:22:33:44:55 text";
87 std::string anonymized_mac_address = "Some text 00:11:22:00:00:01 text";
88 feedback_->AddLog(kOne, mac_address);
89 feedback_->AddLog(kThree, mac_address + kLongLog);
90 feedback_->CompressLogs();
91 feedback_->PrepareReport(&report_);
92
93 // Verify that uncompressed data is anonymized.
94 ASSERT_EQ(1, report_.web_data().product_specific_data_size());
95 EXPECT_EQ(anonymized_mac_address,
96 report_.web_data().product_specific_data(0).value());
97
98 // Verify that compressed data is anonymized.
99 ASSERT_EQ(1, report_.product_specific_binary_data_size());
100 const ::userfeedback::ProductSpecificBinaryData& binary_data =
101 report_.product_specific_binary_data(0);
102
103 base::ScopedTempDir scoped_dir;
104 ASSERT_TRUE(scoped_dir.CreateUniqueTempDir());
105 base::FilePath zip_file = scoped_dir.path().Append("logs.zip");
106
107 ASSERT_TRUE(binary_data.has_data());
108 bool success = base::WriteFile(zip_file, binary_data.data().data(),
109 binary_data.data().size());
110 ASSERT_TRUE(success);
111 success = zip::Unzip(zip_file, scoped_dir.path());
112 ASSERT_TRUE(success);
113
114 std::string file_content;
115 success = base::ReadFileToString(scoped_dir.path().Append(kLogsFilename),
116 &file_content);
117 ASSERT_TRUE(success);
118
119 EXPECT_TRUE(file_content.find(anonymized_mac_address) != std::string::npos);
120 EXPECT_TRUE(file_content.find(mac_address) == std::string::npos);
121 }
OLDNEW
« 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