| Index: components/safe_browsing_db/v4_protocol_manager_util_unittest.cc
|
| diff --git a/components/safe_browsing_db/v4_protocol_manager_util_unittest.cc b/components/safe_browsing_db/v4_protocol_manager_util_unittest.cc
|
| index f3effaba41374b9759b7eae74be751070db02a86..0680d3cc060eea2bf1c9b9702abd8363667663dd 100644
|
| --- a/components/safe_browsing_db/v4_protocol_manager_util_unittest.cc
|
| +++ b/components/safe_browsing_db/v4_protocol_manager_util_unittest.cc
|
| @@ -238,4 +238,35 @@ TEST_F(V4ProtocolManagerUtilTest, CanonicalizeUrl) {
|
| }
|
| }
|
|
|
| +TEST_F(V4ProtocolManagerUtilTest, TestIPAddressToEncodedIPV6) {
|
| + // To verify the test values, here's the python code:
|
| + // >> import socket, hashlib, binascii
|
| + // >> hashlib.sha1(socket.inet_pton(socket.AF_INET6, input)).digest() +
|
| + // chr(128)
|
| + // For example:
|
| + // >>> hashlib.sha1(socket.inet_pton(socket.AF_INET6,
|
| + // '::ffff:192.168.1.1')).digest() + chr(128)
|
| + // 'X\xf8\xa1\x17I\xe6Pl\xfd\xdb\xbb\xa0\x0c\x02\x9d#\n|\xe7\xcd\x80'
|
| + std::vector<std::tuple<bool, std::string, std::string>> test_cases = {
|
| + std::make_tuple(false, "", ""),
|
| + std::make_tuple(
|
| + true, "192.168.1.1",
|
| + "X\xF8\xA1\x17I\xE6Pl\xFD\xDB\xBB\xA0\f\x2\x9D#\n|\xE7\xCD\x80"),
|
| + std::make_tuple(
|
| + true, "::",
|
| + "\xE1)\xF2|Q\x3\xBC\\\xC4K\xCD\xF0\xA1^\x16\rDPf\xFF\x80")};
|
| + for (size_t i = 0; i < test_cases.size(); i++) {
|
| + DVLOG(1) << "Running case: " << i;
|
| + bool success = std::get<0>(test_cases[i]);
|
| + const auto& input = std::get<1>(test_cases[i]);
|
| + const auto& expected_output = std::get<2>(test_cases[i]);
|
| + std::string encoded_ip;
|
| + ASSERT_EQ(success, V4ProtocolManagerUtil::IPAddressToEncodedIPV6Hash(
|
| + input, &encoded_ip));
|
| + if (success) {
|
| + ASSERT_EQ(expected_output, encoded_ip);
|
| + }
|
| + }
|
| +}
|
| +
|
| } // namespace safe_browsing
|
|
|