OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/feedback/anonymizer_tool.h" | |
6 | |
7 #include <gtest/gtest.h> | |
8 | |
9 using std::map; | |
10 using std::string; | |
vasilii
2015/12/17 12:40:37
These don't look beneficial to me.
battre
2015/12/17 13:24:24
Done.
| |
11 | |
12 namespace feedback { | |
13 | |
14 class AnonymizerToolTest : public testing::Test { | |
15 protected: | |
16 string AnonymizeMACAddresses(const string& input) { | |
17 return anonymizer_.AnonymizeMACAddresses(input); | |
18 } | |
19 | |
20 string AnonymizeCustomPatterns(const string& input) { | |
21 return anonymizer_.AnonymizeCustomPatterns(input); | |
22 } | |
23 | |
24 static string AnonymizeCustomPattern(const string& input, | |
25 const string& pattern, | |
26 map<string, string>* space) { | |
27 return AnonymizerTool::AnonymizeCustomPattern(input, pattern, space); | |
28 } | |
29 | |
30 AnonymizerTool anonymizer_; | |
31 }; | |
32 | |
33 TEST_F(AnonymizerToolTest, Anonymize) { | |
34 EXPECT_EQ("", anonymizer_.Anonymize("")); | |
35 EXPECT_EQ("foo\nbar\n", anonymizer_.Anonymize("foo\nbar\n")); | |
36 | |
37 // Make sure MAC address anonymization is invoked. | |
38 EXPECT_EQ("02:46:8a:00:00:01", anonymizer_.Anonymize("02:46:8a:ce:13:57")); | |
39 | |
40 // Make sure custom pattern anonymization is invoked. | |
41 EXPECT_EQ("Cell ID: '1'", AnonymizeCustomPatterns("Cell ID: 'A1B2'")); | |
42 } | |
43 | |
44 TEST_F(AnonymizerToolTest, AnonymizeMACAddresses) { | |
45 EXPECT_EQ("", AnonymizeMACAddresses("")); | |
46 EXPECT_EQ("foo\nbar\n", AnonymizeMACAddresses("foo\nbar\n")); | |
47 EXPECT_EQ("11:22:33:44:55", AnonymizeMACAddresses("11:22:33:44:55")); | |
48 EXPECT_EQ("aa:bb:cc:00:00:01", AnonymizeMACAddresses("aa:bb:cc:dd:ee:ff")); | |
49 EXPECT_EQ( | |
50 "BSSID: aa:bb:cc:00:00:01 in the middle\n" | |
51 "bb:cc:dd:00:00:02 start of line\n" | |
52 "end of line aa:bb:cc:00:00:01\n" | |
53 "no match across lines aa:bb:cc:\n" | |
54 "dd:ee:ff two on the same line:\n" | |
55 "x bb:cc:dd:00:00:02 cc:dd:ee:00:00:03 x\n", | |
56 AnonymizeMACAddresses("BSSID: aa:bb:cc:dd:ee:ff in the middle\n" | |
57 "bb:cc:dd:ee:ff:00 start of line\n" | |
58 "end of line aa:bb:cc:dd:ee:ff\n" | |
59 "no match across lines aa:bb:cc:\n" | |
60 "dd:ee:ff two on the same line:\n" | |
61 "x bb:cc:dd:ee:ff:00 cc:dd:ee:ff:00:11 x\n")); | |
62 EXPECT_EQ("Remember bb:cc:dd:00:00:02?", | |
63 AnonymizeMACAddresses("Remember bB:Cc:DD:ee:ff:00?")); | |
64 } | |
65 | |
66 TEST_F(AnonymizerToolTest, AnonymizeCustomPatterns) { | |
67 EXPECT_EQ("", AnonymizeCustomPatterns("")); | |
68 | |
69 EXPECT_EQ("Cell ID: '1'", AnonymizeCustomPatterns("Cell ID: 'A1B2'")); | |
70 EXPECT_EQ("Cell ID: '2'", AnonymizeCustomPatterns("Cell ID: 'C1D2'")); | |
71 EXPECT_EQ("foo Cell ID: '1' bar", | |
72 AnonymizeCustomPatterns("foo Cell ID: 'A1B2' bar")); | |
73 | |
74 EXPECT_EQ("foo Location area code: '1' bar", | |
75 AnonymizeCustomPatterns("foo Location area code: 'A1B2' bar")); | |
76 | |
77 EXPECT_EQ("foo\na SSID='1' b\n'", | |
78 AnonymizeCustomPatterns("foo\na SSID='Joe's' b\n'")); | |
79 EXPECT_EQ("ssid '2'", AnonymizeCustomPatterns("ssid 'My AP'")); | |
80 EXPECT_EQ("bssid 'aa:bb'", AnonymizeCustomPatterns("bssid 'aa:bb'")); | |
81 | |
82 EXPECT_EQ("Scan SSID - hexdump(len=6): 1\nfoo", | |
83 AnonymizeCustomPatterns( | |
84 "Scan SSID - hexdump(len=6): 47 6f 6f 67 6c 65\nfoo")); | |
85 | |
86 EXPECT_EQ( | |
87 "a\nb [SSID=1] [SSID=2] [SSID=foo\nbar] b", | |
88 AnonymizeCustomPatterns("a\nb [SSID=foo] [SSID=bar] [SSID=foo\nbar] b")); | |
89 } | |
90 | |
91 TEST_F(AnonymizerToolTest, AnonymizeCustomPattern) { | |
vasilii
2015/12/17 12:40:37
The name is almost identical to the previous one.
battre
2015/12/17 13:24:24
I think the name reflects what is being tested.
| |
92 static const char kPattern[] = "(\\b(?i)id:? ')(\\d+)(')"; | |
vasilii
2015/12/17 12:40:37
Get rid of static.
battre
2015/12/17 13:24:24
Done.
| |
93 map<string, string> space; | |
94 EXPECT_EQ("", AnonymizeCustomPattern("", kPattern, &space)); | |
95 EXPECT_EQ("foo\nbar\n", | |
96 AnonymizeCustomPattern("foo\nbar\n", kPattern, &space)); | |
97 EXPECT_EQ("id '1'", AnonymizeCustomPattern("id '2345'", kPattern, &space)); | |
98 EXPECT_EQ("id '2'", AnonymizeCustomPattern("id '1234'", kPattern, &space)); | |
99 EXPECT_EQ("id: '2'", AnonymizeCustomPattern("id: '1234'", kPattern, &space)); | |
100 EXPECT_EQ("ID: '1'", AnonymizeCustomPattern("ID: '2345'", kPattern, &space)); | |
101 EXPECT_EQ("x1 id '1' 1x id '2'\nid '1'\n", | |
102 AnonymizeCustomPattern("x1 id '2345' 1x id '1234'\nid '2345'\n", | |
103 kPattern, &space)); | |
104 space.clear(); | |
105 EXPECT_EQ("id '1'", AnonymizeCustomPattern("id '1234'", kPattern, &space)); | |
106 | |
107 space.clear(); | |
108 EXPECT_EQ("x1z", AnonymizeCustomPattern("xyz", "()(y+)()", &space)); | |
109 } | |
110 | |
111 } // namespace feedback | |
OLD | NEW |