summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-20 18:42:04 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-20 18:42:04 +0000
commit675a1d5db6ce8c9fced0b201d784e1cf94e32a7a (patch)
tree8bc637b5bd6fd423a46bff477d41c5eb1a5b2c27
parent510e854f122deaedd5ba31af188105131a4c3b7d (diff)
downloadchromium_src-675a1d5db6ce8c9fced0b201d784e1cf94e32a7a.zip
chromium_src-675a1d5db6ce8c9fced0b201d784e1cf94e32a7a.tar.gz
chromium_src-675a1d5db6ce8c9fced0b201d784e1cf94e32a7a.tar.bz2
Correct SDCH enforcement of PathMatch for dictionaries
r=openvcdiff Review URL: http://codereview.chromium.org/67286 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14041 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/sdch_filter_unittest.cc40
-rw-r--r--net/base/sdch_manager.cc2
-rw-r--r--net/base/sdch_manager.h3
3 files changed, 43 insertions, 2 deletions
diff --git a/net/base/sdch_filter_unittest.cc b/net/base/sdch_filter_unittest.cc
index a48b67f..ca6b266 100644
--- a/net/base/sdch_filter_unittest.cc
+++ b/net/base/sdch_filter_unittest.cc
@@ -1144,3 +1144,43 @@ TEST_F(SdchFilterTest, DictionaryTooLarge) {
EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text,
GURL("http://" + dictionary_domain)));
}
+
+TEST_F(SdchFilterTest, PathMatch) {
+ bool (*PathMatch)(const std::string& path, const std::string& restriction) =
+ SdchManager::Dictionary::PathMatch;
+ // Perfect match is supported.
+ EXPECT_TRUE(PathMatch("/search", "/search"));
+ EXPECT_TRUE(PathMatch("/search/", "/search/"));
+
+ // Prefix only works if last character of restriction is a slash, or first
+ // character in path after a match is a slash. Validate each case separately.
+
+ // Rely on the slash in the path (not at the end of the restriction).
+ EXPECT_TRUE(PathMatch("/search/something", "/search"));
+ EXPECT_TRUE(PathMatch("/search/s", "/search"));
+ EXPECT_TRUE(PathMatch("/search/other", "/search"));
+ EXPECT_TRUE(PathMatch("/search/something", "/search"));
+
+ // Rely on the slash at the end of the restriction.
+ EXPECT_TRUE(PathMatch("/search/something", "/search/"));
+ EXPECT_TRUE(PathMatch("/search/s", "/search/"));
+ EXPECT_TRUE(PathMatch("/search/other", "/search/"));
+ EXPECT_TRUE(PathMatch("/search/something", "/search/"));
+
+ // Make sure less that sufficient prefix match is false.
+ EXPECT_FALSE(PathMatch("/sear", "/search"));
+ EXPECT_FALSE(PathMatch("/", "/search"));
+ EXPECT_FALSE(PathMatch("", "/search"));
+
+ // Add examples with several levels of direcories in the restriction.
+ EXPECT_FALSE(PathMatch("/search/something", "search/s"));
+ EXPECT_FALSE(PathMatch("/search/", "/search/s"));
+
+ // Make sure adding characters to path will also fail.
+ EXPECT_FALSE(PathMatch("/searching", "/search/"));
+ EXPECT_FALSE(PathMatch("/searching", "/search"));
+
+ // Make sure we're case sensitive.
+ EXPECT_FALSE(PathMatch("/ABC", "/abc"));
+ EXPECT_FALSE(PathMatch("/abc", "/ABC"));
+}
diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc
index a56f4d5..c6bf950 100644
--- a/net/base/sdch_manager.cc
+++ b/net/base/sdch_manager.cc
@@ -496,7 +496,7 @@ bool SdchManager::Dictionary::PathMatch(const std::string& path,
size_t prefix_length = restriction.size();
if (prefix_length > path.size())
return false; // Can't be a prefix.
- if (0 != restriction.compare(0, prefix_length, path))
+ if (0 != path.compare(0, prefix_length, restriction))
return false;
return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/';
}
diff --git a/net/base/sdch_manager.h b/net/base/sdch_manager.h
index 3c585c3..6524e7a 100644
--- a/net/base/sdch_manager.h
+++ b/net/base/sdch_manager.h
@@ -28,7 +28,7 @@
#include "base/scoped_ptr.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
-
+#include "testing/gtest/include/gtest/gtest_prod.h"
//------------------------------------------------------------------------------
// Create a public interface to help us load SDCH dictionaries.
@@ -155,6 +155,7 @@ class SdchManager {
private:
friend class SdchManager; // Only manager can construct an instance.
+ FRIEND_TEST(SdchFilterTest, PathMatch);
// Construct a vc-diff usable dictionary from the dictionary_text starting
// at the given offset. The supplied client_hash should be used to