| OLD | NEW |
| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 {"http://www.google.com.../", "www.google.com", "/", ""}, | 198 {"http://www.google.com.../", "www.google.com", "/", ""}, |
| 199 {"http://www.google.com/q?", "www.google.com", "/q", ""}, | 199 {"http://www.google.com/q?", "www.google.com", "/q", ""}, |
| 200 {"http://www.google.com/q?r?", "www.google.com", "/q", "r?"}, | 200 {"http://www.google.com/q?r?", "www.google.com", "/q", "r?"}, |
| 201 {"http://www.google.com/q?r?s", "www.google.com", "/q", "r?s"}, | 201 {"http://www.google.com/q?r?s", "www.google.com", "/q", "r?s"}, |
| 202 {"http://evil.com/foo#bar#baz", "evil.com", "/foo", ""}, | 202 {"http://evil.com/foo#bar#baz", "evil.com", "/foo", ""}, |
| 203 {"http://evil.com/foo;", "evil.com", "/foo;", ""}, | 203 {"http://evil.com/foo;", "evil.com", "/foo;", ""}, |
| 204 {"http://evil.com/foo?bar;", "evil.com", "/foo", "bar;"}, | 204 {"http://evil.com/foo?bar;", "evil.com", "/foo", "bar;"}, |
| 205 {"http://notrailingslash.com", "notrailingslash.com", "/", ""}, | 205 {"http://notrailingslash.com", "notrailingslash.com", "/", ""}, |
| 206 {"http://www.gotaport.com:1234/", "www.gotaport.com", "/", ""}, | 206 {"http://www.gotaport.com:1234/", "www.gotaport.com", "/", ""}, |
| 207 {" http://www.google.com/ ", "www.google.com", "/", ""}, | 207 {" http://www.google.com/ ", "www.google.com", "/", ""}, |
| 208 {"http:// leadingspace.com/", "%20leadingspace.com", "/", ""}, | |
| 209 {"http://%20leadingspace.com/", "%20leadingspace.com", "/", ""}, | |
| 210 {"https://www.securesite.com/", "www.securesite.com", "/", ""}, | 208 {"https://www.securesite.com/", "www.securesite.com", "/", ""}, |
| 211 {"http://host.com/ab%23cd", "host.com", "/ab%23cd", ""}, | 209 {"http://host.com/ab%23cd", "host.com", "/ab%23cd", ""}, |
| 212 {"http://host%3e.com//twoslashes?more//slashes", "host>.com", | 210 {"http://host%5A.com//twoslashes?more//slashes", "hostz.com", |
| 213 "/twoslashes", "more//slashes"}, | 211 "/twoslashes", "more//slashes"}, |
| 214 {"http://host.com/abc?val=xyz#anything", "host.com", "/abc", "val=xyz"}, | 212 {"http://host.com/abc?val=xyz#anything", "host.com", "/abc", "val=xyz"}, |
| 215 {"http://abc:def@host.com/xyz", "host.com", "/xyz", ""}, | 213 {"http://abc:def@host.com/xyz", "host.com", "/xyz", ""}, |
| 216 {"http://host%3e.com/abc/%2e%2e%2fdef", "host>.com", "/def", ""}, | 214 {"http://host%5a.com/abc/%2e%2e%2fdef", "hostz.com", "/def", ""}, |
| 217 {"http://.......host...com.....//abc/////def%2F%2F%2Fxyz", "host.com", | 215 {"http://.......host...com.....//abc/////def%2F%2F%2Fxyz", "host.com", |
| 218 "/abc/def/xyz", ""}, | 216 "/abc/def/xyz", ""}, |
| 219 {"ftp://host.com/foo?bar", "host.com", "/foo", "bar"}, | 217 {"ftp://host.com/foo?bar", "host.com", "/foo", "bar"}, |
| 220 {"data:text/html;charset=utf-8,%0D%0A", "", "", ""}, | 218 {"data:text/html;charset=utf-8,%0D%0A", "", "", ""}, |
| 221 {"javascript:alert()", "", "", ""}, | 219 {"javascript:alert()", "", "", ""}, |
| 222 {"mailto:abc@example.com", "", "", ""}, | 220 {"mailto:abc@example.com", "", "", ""}, |
| 223 }; | 221 }; |
| 224 for (size_t i = 0; i < arraysize(tests); ++i) { | 222 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 225 SCOPED_TRACE(base::StringPrintf("Test: %s", tests[i].input_url)); | 223 SCOPED_TRACE(base::StringPrintf("Test: %s", tests[i].input_url)); |
| 226 GURL url(tests[i].input_url); | 224 GURL url(tests[i].input_url); |
| 227 | 225 |
| 228 std::string canonicalized_hostname; | 226 std::string canonicalized_hostname; |
| 229 std::string canonicalized_path; | 227 std::string canonicalized_path; |
| 230 std::string canonicalized_query; | 228 std::string canonicalized_query; |
| 231 V4ProtocolManagerUtil::CanonicalizeUrl(url, &canonicalized_hostname, | 229 V4ProtocolManagerUtil::CanonicalizeUrl(url, &canonicalized_hostname, |
| 232 &canonicalized_path, | 230 &canonicalized_path, |
| 233 &canonicalized_query); | 231 &canonicalized_query); |
| 234 | 232 |
| 235 EXPECT_EQ(tests[i].expected_canonicalized_hostname, canonicalized_hostname); | 233 EXPECT_EQ(tests[i].expected_canonicalized_hostname, canonicalized_hostname); |
| 236 EXPECT_EQ(tests[i].expected_canonicalized_path, canonicalized_path); | 234 EXPECT_EQ(tests[i].expected_canonicalized_path, canonicalized_path); |
| 237 EXPECT_EQ(tests[i].expected_canonicalized_query, canonicalized_query); | 235 EXPECT_EQ(tests[i].expected_canonicalized_query, canonicalized_query); |
| 238 } | 236 } |
| 239 } | 237 } |
| 240 | 238 |
| 241 } // namespace safe_browsing | 239 } // namespace safe_browsing |
| OLD | NEW |