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

Unified Diff: third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp

Issue 2697853002: Content-Security-Policy: Backporting test of hostmatches in CSPSource. (Closed)
Patch Set: Rebase. Created 3 years, 10 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp b/third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp
index b73a578c110e4442bc0543236050ea78c69b5535..36590e967f0e74f4dc1ee7c7612860e6909f09eb 100644
--- a/third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp
@@ -239,6 +239,46 @@ TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort) {
}
}
+TEST_F(CSPSourceTest, HostMatches) {
+ KURL base;
+ Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create());
+ csp->setupSelf(*SecurityOrigin::createFromString("http://a.com"));
+
+ // Host is * (source-expression = "http://*")
+ {
+ CSPSource source(csp.get(), "http", "", 0, "", CSPSource::HasWildcard,
+ CSPSource::NoWildcard);
+ EXPECT_TRUE(source.matches(KURL(base, "http://a.com")));
+ EXPECT_TRUE(source.matches(KURL(base, "http://.")));
+ }
+
+ // Host is *.foo.bar
+ {
+ CSPSource source(csp.get(), "", "foo.bar", 0, "", CSPSource::HasWildcard,
+ CSPSource::NoWildcard);
+ EXPECT_FALSE(source.matches(KURL(base, "http://a.com")));
+ EXPECT_FALSE(source.matches(KURL(base, "http://bar")));
+ EXPECT_FALSE(source.matches(KURL(base, "http://foo.bar")));
+ EXPECT_FALSE(source.matches(KURL(base, "http://o.bar")));
+ EXPECT_TRUE(source.matches(KURL(base, "http://*.foo.bar")));
+ EXPECT_TRUE(source.matches(KURL(base, "http://sub.foo.bar")));
+ EXPECT_TRUE(source.matches(KURL(base, "http://sub.sub.foo.bar")));
+ // Please see http://crbug.com/692505
+ EXPECT_TRUE(source.matches(KURL(base, "http://.foo.bar")));
+ }
+
+ // Host is exact.
+ {
+ CSPSource source(csp.get(), "", "foo.bar", 0, "", CSPSource::NoWildcard,
+ CSPSource::NoWildcard);
+ EXPECT_TRUE(source.matches(KURL(base, "http://foo.bar")));
+ EXPECT_FALSE(source.matches(KURL(base, "http://sub.foo.bar")));
+ EXPECT_FALSE(source.matches(KURL(base, "http://bar")));
+ // Please see http://crbug.com/692505
+ EXPECT_FALSE(source.matches(KURL(base, "http://.foo.bar")));
+ }
+}
+
TEST_F(CSPSourceTest, DoesNotSubsume) {
struct Source {
const char* scheme;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698