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

Side by Side Diff: components/safe_browsing_db/v4_protocol_manager_util_unittest.cc

Issue 2495783003: Implement support for checking bad IPs aka MatchMalwareIP (Closed)
Patch Set: shess@ and nparker@ review Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/safe_browsing_db/v4_protocol_manager_util.h" 5 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 V4ProtocolManagerUtil::CanonicalizeUrl(url, &canonicalized_hostname, 231 V4ProtocolManagerUtil::CanonicalizeUrl(url, &canonicalized_hostname,
232 &canonicalized_path, 232 &canonicalized_path,
233 &canonicalized_query); 233 &canonicalized_query);
234 234
235 EXPECT_EQ(tests[i].expected_canonicalized_hostname, canonicalized_hostname); 235 EXPECT_EQ(tests[i].expected_canonicalized_hostname, canonicalized_hostname);
236 EXPECT_EQ(tests[i].expected_canonicalized_path, canonicalized_path); 236 EXPECT_EQ(tests[i].expected_canonicalized_path, canonicalized_path);
237 EXPECT_EQ(tests[i].expected_canonicalized_query, canonicalized_query); 237 EXPECT_EQ(tests[i].expected_canonicalized_query, canonicalized_query);
238 } 238 }
239 } 239 }
240 240
241 TEST_F(V4ProtocolManagerUtilTest, TestIPAddressToEncodedIPV6) {
242 // To verify the test values, here's the python code:
243 // >> import socket, hashlib, binascii
244 // >> hashlib.sha1(socket.inet_pton(socket.AF_INET6, input)).digest() +
245 // chr(128)
246 // For example:
247 // >>> hashlib.sha1(socket.inet_pton(socket.AF_INET6,
248 // '::ffff:192.168.1.1')).digest() + chr(128)
249 // 'X\xf8\xa1\x17I\xe6Pl\xfd\xdb\xbb\xa0\x0c\x02\x9d#\n|\xe7\xcd\x80'
250 std::vector<std::tuple<bool, std::string, std::string>> test_cases = {
Nathan Parker 2016/11/15 00:54:46 Personally I think this would be simpler just writ
vakh (use Gerrit instead) 2016/11/15 01:03:41 Acknowledged.
251 std::make_tuple(false, "", ""),
252 std::make_tuple(
253 true, "192.168.1.1",
254 "X\xF8\xA1\x17I\xE6Pl\xFD\xDB\xBB\xA0\f\x2\x9D#\n|\xE7\xCD\x80"),
255 std::make_tuple(
256 true, "::",
257 "\xE1)\xF2|Q\x3\xBC\\\xC4K\xCD\xF0\xA1^\x16\rDPf\xFF\x80")};
258 for (size_t i = 0; i < test_cases.size(); i++) {
259 DVLOG(1) << "Running case: " << i;
260 bool success = std::get<0>(test_cases[i]);
261 const auto& input = std::get<1>(test_cases[i]);
262 const auto& expected_output = std::get<2>(test_cases[i]);
263 std::string encoded_ip;
264 ASSERT_EQ(success, V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(
265 input, &encoded_ip));
266 if (success) {
267 ASSERT_EQ(expected_output, encoded_ip);
268 }
269 }
270 }
271
241 } // namespace safe_browsing 272 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698