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

Unified Diff: components/safe_browsing_db/util_unittest.cc

Issue 2229533002: Revert of Simple: Move PVer4 related code from util.* to v4_protocol_manager_util.* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/safe_browsing_db/util.cc ('k') | components/safe_browsing_db/v4_local_database_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing_db/util_unittest.cc
diff --git a/components/safe_browsing_db/util_unittest.cc b/components/safe_browsing_db/util_unittest.cc
index c105c4a27e3252ba5da1bc88d839db48aae81c1d..85f32a9146d93939d297cc50cae7d5e6ccb38b5c 100644
--- a/components/safe_browsing_db/util_unittest.cc
+++ b/components/safe_browsing_db/util_unittest.cc
@@ -13,6 +13,273 @@
#include "url/gurl.h"
namespace safe_browsing {
+
+namespace {
+
+bool VectorContains(const std::vector<std::string>& data,
+ const std::string& str) {
+ return std::find(data.begin(), data.end(), str) != data.end();
+}
+
+} // namespace
+
+// Tests that we generate the required host/path combinations for testing
+// according to the Safe Browsing spec.
+// See section 6.2 in
+// http://code.google.com/p/google-safe-browsing/wiki/Protocolv2Spec.
+TEST(SafeBrowsingDbUtilTest, UrlParsing) {
+ std::vector<std::string> hosts, paths;
+
+ GURL url("http://a.b.c/1/2.html?param=1");
+ GenerateHostsToCheck(url, &hosts);
+ GeneratePathsToCheck(url, &paths);
+ EXPECT_EQ(hosts.size(), static_cast<size_t>(2));
+ EXPECT_EQ(paths.size(), static_cast<size_t>(4));
+ EXPECT_EQ(hosts[0], "b.c");
+ EXPECT_EQ(hosts[1], "a.b.c");
+
+ EXPECT_TRUE(VectorContains(paths, "/1/2.html?param=1"));
+ EXPECT_TRUE(VectorContains(paths, "/1/2.html"));
+ EXPECT_TRUE(VectorContains(paths, "/1/"));
+ EXPECT_TRUE(VectorContains(paths, "/"));
+
+ url = GURL("http://a.b.c.d.e.f.g/1.html");
+ GenerateHostsToCheck(url, &hosts);
+ GeneratePathsToCheck(url, &paths);
+ EXPECT_EQ(hosts.size(), static_cast<size_t>(5));
+ EXPECT_EQ(paths.size(), static_cast<size_t>(2));
+ EXPECT_EQ(hosts[0], "f.g");
+ EXPECT_EQ(hosts[1], "e.f.g");
+ EXPECT_EQ(hosts[2], "d.e.f.g");
+ EXPECT_EQ(hosts[3], "c.d.e.f.g");
+ EXPECT_EQ(hosts[4], "a.b.c.d.e.f.g");
+ EXPECT_TRUE(VectorContains(paths, "/1.html"));
+ EXPECT_TRUE(VectorContains(paths, "/"));
+
+ url = GURL("http://a.b/saw-cgi/eBayISAPI.dll/");
+ GeneratePathsToCheck(url, &paths);
+ EXPECT_EQ(paths.size(), static_cast<size_t>(3));
+ EXPECT_TRUE(VectorContains(paths, "/saw-cgi/eBayISAPI.dll/"));
+ EXPECT_TRUE(VectorContains(paths, "/saw-cgi/"));
+ EXPECT_TRUE(VectorContains(paths, "/"));
+}
+
+// Tests the url canonicalization according to the Safe Browsing spec.
+// See section 6.1 in
+// http://code.google.com/p/google-safe-browsing/wiki/Protocolv2Spec.
+TEST(SafeBrowsingDbUtilTest, CanonicalizeUrl) {
+ struct {
+ const char* input_url;
+ const char* expected_canonicalized_hostname;
+ const char* expected_canonicalized_path;
+ const char* expected_canonicalized_query;
+ } tests[] = {
+ {
+ "http://host/%25%32%35",
+ "host",
+ "/%25",
+ ""
+ }, {
+ "http://host/%25%32%35%25%32%35",
+ "host",
+ "/%25%25",
+ ""
+ }, {
+ "http://host/%2525252525252525",
+ "host",
+ "/%25",
+ ""
+ }, {
+ "http://host/asdf%25%32%35asd",
+ "host",
+ "/asdf%25asd",
+ ""
+ }, {
+ "http://host/%%%25%32%35asd%%",
+ "host",
+ "/%25%25%25asd%25%25",
+ ""
+ }, {
+ "http://host/%%%25%32%35asd%%",
+ "host",
+ "/%25%25%25asd%25%25",
+ ""
+ }, {
+ "http://www.google.com/",
+ "www.google.com",
+ "/",
+ ""
+ }, {
+ "http://%31%36%38%2e%31%38%38%2e%39%39%2e%32%36/%2E%73%65%63%75%72%65/%77"
+ "%77%77%2E%65%62%61%79%2E%63%6F%6D/",
+ "168.188.99.26",
+ "/.secure/www.ebay.com/",
+ ""
+ }, {
+ "http://195.127.0.11/uploads/%20%20%20%20/.verify/.eBaysecure=updateuserd"
+ "ataxplimnbqmn-xplmvalidateinfoswqpcmlx=hgplmcx/",
+ "195.127.0.11",
+ "/uploads/%20%20%20%20/.verify/.eBaysecure=updateuserdataxplimnbqmn-xplmv"
+ "alidateinfoswqpcmlx=hgplmcx/",
+ ""
+ }, {
+ "http://host.com/%257Ea%2521b%2540c%2523d%2524e%25f%255E00%252611%252A"
+ "22%252833%252944_55%252B",
+ "host.com",
+ "/~a!b@c%23d$e%25f^00&11*22(33)44_55+",
+ ""
+ }, {
+ "http://3279880203/blah",
+ "195.127.0.11",
+ "/blah",
+ ""
+ }, {
+ "http://www.google.com/blah/..",
+ "www.google.com",
+ "/",
+ ""
+ }, {
+ "http://www.google.com/blah#fraq",
+ "www.google.com",
+ "/blah",
+ ""
+ }, {
+ "http://www.GOOgle.com/",
+ "www.google.com",
+ "/",
+ ""
+ }, {
+ "http://www.google.com.../",
+ "www.google.com",
+ "/",
+ ""
+ }, {
+ "http://www.google.com/q?",
+ "www.google.com",
+ "/q",
+ ""
+ }, {
+ "http://www.google.com/q?r?",
+ "www.google.com",
+ "/q",
+ "r?"
+ }, {
+ "http://www.google.com/q?r?s",
+ "www.google.com",
+ "/q",
+ "r?s"
+ }, {
+ "http://evil.com/foo#bar#baz",
+ "evil.com",
+ "/foo",
+ ""
+ }, {
+ "http://evil.com/foo;",
+ "evil.com",
+ "/foo;",
+ ""
+ }, {
+ "http://evil.com/foo?bar;",
+ "evil.com",
+ "/foo",
+ "bar;"
+ }, {
+ "http://notrailingslash.com",
+ "notrailingslash.com",
+ "/",
+ ""
+ }, {
+ "http://www.gotaport.com:1234/",
+ "www.gotaport.com",
+ "/",
+ ""
+ }, {
+ " http://www.google.com/ ",
+ "www.google.com",
+ "/",
+ ""
+ }, {
+ "http:// leadingspace.com/",
+ "%20leadingspace.com",
+ "/",
+ ""
+ }, {
+ "http://%20leadingspace.com/",
+ "%20leadingspace.com",
+ "/",
+ ""
+ }, {
+ "https://www.securesite.com/",
+ "www.securesite.com",
+ "/",
+ ""
+ }, {
+ "http://host.com/ab%23cd",
+ "host.com",
+ "/ab%23cd",
+ ""
+ }, {
+ "http://host%3e.com//twoslashes?more//slashes",
+ "host>.com",
+ "/twoslashes",
+ "more//slashes"
+ }, {
+ "http://host.com/abc?val=xyz#anything",
+ "host.com",
+ "/abc",
+ "val=xyz"
+ }, {
+ "http://abc:def@host.com/xyz",
+ "host.com",
+ "/xyz",
+ ""
+ }, {
+ "http://host%3e.com/abc/%2e%2e%2fdef",
+ "host>.com",
+ "/def",
+ ""
+ }, {
+ "http://.......host...com.....//abc/////def%2F%2F%2Fxyz",
+ "host.com",
+ "/abc/def/xyz",
+ ""
+ }, {
+ "ftp://host.com/foo?bar",
+ "host.com",
+ "/foo",
+ "bar"
+ }, {
+ "data:text/html;charset=utf-8,%0D%0A",
+ "",
+ "",
+ ""
+ }, {
+ "javascript:alert()",
+ "",
+ "",
+ ""
+ }, {
+ "mailto:abc@example.com",
+ "",
+ "",
+ ""
+ },
+ };
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ SCOPED_TRACE(base::StringPrintf("Test: %s", tests[i].input_url));
+ GURL url(tests[i].input_url);
+
+ std::string canonicalized_hostname;
+ std::string canonicalized_path;
+ std::string canonicalized_query;
+ CanonicalizeUrl(url, &canonicalized_hostname, &canonicalized_path,
+ &canonicalized_query);
+
+ EXPECT_EQ(tests[i].expected_canonicalized_hostname, canonicalized_hostname);
+ EXPECT_EQ(tests[i].expected_canonicalized_path, canonicalized_path);
+ EXPECT_EQ(tests[i].expected_canonicalized_query, canonicalized_query);
+ }
+}
TEST(SafeBrowsingDbUtilTest, UrlToFullHashes) {
std::vector<SBFullHash> results;
« no previous file with comments | « components/safe_browsing_db/util.cc ('k') | components/safe_browsing_db/v4_local_database_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698