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

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: 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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, report.product_specific_binary_data(0).name());
79 } 82 }
83
84 TEST_F(FeedbackCommonTest, TestAddLogsAnonymization) {
85 std::string mac_address = "Some text 00:11:22:33:44:55 text";
86 std::string anonymized_mac_address = "Some text 00:11:22:00:00:01 text";
87 feedback->AddLog(kOne, mac_address);
88 feedback->AddLog(kThree, mac_address + kLongLog);
89 feedback->CompressLogs();
90 feedback->PrepareReport(&report);
vasilii 2015/12/17 12:40:37 The class members aren't marked with '_'. It's ver
battre 2015/12/17 13:24:24 Done.
91
92 // Verify that uncompressed data is anonymized.
vasilii 2015/12/17 12:40:37 But you compress them above.
battre 2015/12/17 13:24:24 The feedback can contain two types of data at the
vasilii 2015/12/17 13:39:05 Then it should go to a comment explaining why two
battre 2015/12/17 14:34:55 Done.
93 ASSERT_EQ(1, report.web_data().product_specific_data_size());
94 EXPECT_EQ(anonymized_mac_address,
95 report.web_data().product_specific_data(0).value());
96
97 // Verify that compressed data is anonymized.
98 ASSERT_EQ(1, report.product_specific_binary_data_size());
99 const ::userfeedback::ProductSpecificBinaryData& binary_data =
100 report.product_specific_binary_data(0);
101
102 base::ScopedTempDir scoped_dir;
103 ASSERT_TRUE(scoped_dir.CreateUniqueTempDir());
104 base::FilePath zip_file = scoped_dir.path().Append("logs.zip");
105
106 ASSERT_TRUE(binary_data.has_data());
107 bool success = base::WriteFile(zip_file, binary_data.data().data(),
vasilii 2015/12/17 12:40:37 Why do you test filesystem and zip here?
battre 2015/12/17 13:24:24 Not sure I understand you. My goal is to test whet
vasilii 2015/12/17 13:39:05 Isn't there a way to unzip |binary_data| without t
battre 2015/12/17 14:34:56 Ok, found one. Done.
108 binary_data.data().size());
109 ASSERT_TRUE(success);
110 success = zip::Unzip(zip_file, scoped_dir.path());
111 ASSERT_TRUE(success);
112
113 std::string file_content;
114 success = base::ReadFileToString(scoped_dir.path().Append(kLogsFilename),
115 &file_content);
116 ASSERT_TRUE(success);
117
118 EXPECT_TRUE(file_content.find(anonymized_mac_address) != std::string::npos);
119 EXPECT_TRUE(file_content.find(mac_address) == std::string::npos);
120 }
OLDNEW
« components/feedback/feedback_common.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