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

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

Issue 2125873003: CSP: Allow ':80' to match ':443' in source expressions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/frame/csp/CSPSource.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/frame/csp/CSPSource.h" 5 #include "core/frame/csp/CSPSource.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/csp/ContentSecurityPolicy.h" 8 #include "core/frame/csp/ContentSecurityPolicy.h"
9 #include "platform/network/ResourceRequest.h" 9 #include "platform/network/ResourceRequest.h"
10 #include "platform/weborigin/KURL.h" 10 #include "platform/weborigin/KURL.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 CSPSource source(csp.get(), "http", "example.com", 8000, "/bar/", CSPSource: :NoWildcard, CSPSource::NoWildcard); 64 CSPSource source(csp.get(), "http", "example.com", 8000, "/bar/", CSPSource: :NoWildcard, CSPSource::NoWildcard);
65 65
66 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"), ResourceR equest::RedirectStatus::FollowedRedirect)); 66 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"), ResourceR equest::RedirectStatus::FollowedRedirect));
67 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/foo"), Resour ceRequest::RedirectStatus::FollowedRedirect)); 67 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/foo"), Resour ceRequest::RedirectStatus::FollowedRedirect));
68 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/foo"), Resou rceRequest::RedirectStatus::FollowedRedirect)); 68 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/foo"), Resou rceRequest::RedirectStatus::FollowedRedirect));
69 69
70 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/foo"), R esourceRequest::RedirectStatus::FollowedRedirect)); 70 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/foo"), R esourceRequest::RedirectStatus::FollowedRedirect));
71 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"), Reso urceRequest::RedirectStatus::NoRedirect)); 71 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"), Reso urceRequest::RedirectStatus::NoRedirect));
72 } 72 }
73 73
74 TEST_F(CSPSourceTest, InsecureSourceMatchesSecure) 74 TEST_F(CSPSourceTest, InsecureSchemeMatchesSecureScheme)
75 { 75 {
76 KURL base; 76 KURL base;
77 CSPSource source(csp.get(), "http", "", 0, "/", CSPSource::NoWildcard, CSPSo urce::HasWildcard); 77 CSPSource source(csp.get(), "http", "", 0, "/", CSPSource::NoWildcard, CSPSo urce::HasWildcard);
78 78
79 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"))); 79 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/")));
80 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/"))); 80 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/")));
81 EXPECT_TRUE(source.matches(KURL(base, "http://not-example.com:8000/"))); 81 EXPECT_TRUE(source.matches(KURL(base, "http://not-example.com:8000/")));
82 EXPECT_TRUE(source.matches(KURL(base, "https://not-example.com:8000/"))); 82 EXPECT_TRUE(source.matches(KURL(base, "https://not-example.com:8000/")));
83 EXPECT_FALSE(source.matches(KURL(base, "ftp://example.com:8000/"))); 83 EXPECT_FALSE(source.matches(KURL(base, "ftp://example.com:8000/")));
84 } 84 }
85 85
86 TEST_F(CSPSourceTest, InsecureHostMatchesSecure) 86 TEST_F(CSPSourceTest, InsecureHostSchemeMatchesSecureScheme)
87 { 87 {
88 KURL base; 88 KURL base;
89 CSPSource source(csp.get(), "http", "example.com", 0, "/", CSPSource::NoWild card, CSPSource::HasWildcard); 89 CSPSource source(csp.get(), "http", "example.com", 0, "/", CSPSource::NoWild card, CSPSource::HasWildcard);
90 90
91 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"))); 91 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/")));
92 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/"))); 92 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/")));
93 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/"))); 93 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/")));
94 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:8000/"))); 94 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:8000/")));
95 } 95 }
96 96
97 TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort)
98 {
99 KURL base;
100 CSPSource source(csp.get(), "http", "example.com", 80, "/", CSPSource::NoWil dcard, CSPSource::NoWildcard);
101 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/")));
102 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:80/")));
103 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443/")));
104 EXPECT_TRUE(source.matches(KURL(base, "https://example.com/")));
105 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:80/")));
106 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443/")));
107
108 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8443/")));
109 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8443/")));
110
111 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com/")));
112 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:80/")));
113 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:443/")));
114 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com/")));
115 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:80/")));
116 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:443/")));
117 }
118
119
120
97 } // namespace blink 121 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/csp/CSPSource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698