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

Unified Diff: chrome/common/content_settings_pattern_unittest.cc

Issue 8676020: Detect invalid content settings pattern that were not detected yet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move one more check to the Validate method Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/content_settings_pattern_unittest.cc
diff --git a/chrome/common/content_settings_pattern_unittest.cc b/chrome/common/content_settings_pattern_unittest.cc
index 8bad3eab8a8d671a976d53f334ff1d20c6e34666..6853507911a33f03b7871b04347f3b208ea51974 100644
--- a/chrome/common/content_settings_pattern_unittest.cc
+++ b/chrome/common/content_settings_pattern_unittest.cc
@@ -172,13 +172,19 @@ TEST(ContentSettingsPatternTest, FromString_WithNoWildcards) {
}
TEST(ContentSettingsPatternTest, FromString_FilePatterns) {
- EXPECT_TRUE(Pattern("file:///").IsValid());
- EXPECT_STREQ("file:///",
- Pattern("file:///").ToString().c_str());
- EXPECT_TRUE(Pattern("file:///").Matches(
- GURL("file:///")));
- EXPECT_FALSE(Pattern("file:///").Matches(
- GURL("file:///tmp/test.html")));
+ EXPECT_FALSE(Pattern("file:///").IsValid());
+
+ // Non-empty domains aren't allowed in file patterns.
+ EXPECT_FALSE(Pattern("file://foo/").IsValid());
+
+ // Domain wildcards aren't allowed in file patterns.
+ EXPECT_FALSE(Pattern("file://*/").IsValid());
+ EXPECT_FALSE(Pattern("file://[*.]/").IsValid());
+
+ // These specify a path that contains '*', which isn't allowed to avoid
+ // user confusion.
+ EXPECT_FALSE(Pattern("file:///*").IsValid());
+ EXPECT_FALSE(Pattern("file:///foo/bar/*").IsValid());
EXPECT_TRUE(Pattern("file:///tmp/test.html").IsValid());
EXPECT_STREQ("file:///tmp/file.html",
@@ -208,6 +214,10 @@ TEST(ContentSettingsPatternTest, FromString_WithIPAdresses) {
EXPECT_TRUE(Pattern("https://192.168.0.1:8080").IsValid());
EXPECT_STREQ("https://192.168.0.1:8080",
Pattern("https://192.168.0.1:8080").ToString().c_str());
+
+ // Subdomain wildcards should be only valid for hosts, not for IP addresses.
+ EXPECT_FALSE(Pattern("[*.]127.0.0.1").IsValid());
+
// IPv6
EXPECT_TRUE(Pattern("[::1]").IsValid());
EXPECT_STREQ("[::1]", Pattern("[::1]").ToString().c_str());
@@ -269,6 +279,8 @@ TEST(ContentSettingsPatternTest, FromString_WithWildcards) {
GURL("http://example.org/")));
// Patterns with domain wildcard.
+ EXPECT_FALSE(Pattern("[*.]").IsValid());
+ EXPECT_FALSE(Pattern("http://[*.]").IsValid());
EXPECT_TRUE(Pattern("[*.]example.com").IsValid());
EXPECT_STREQ("[*.]example.com",
Pattern("[*.]example.com").ToString().c_str());

Powered by Google App Engine
This is Rietveld 408576698