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

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

Issue 2689363003: CSP: Add test: Allow port upgrade without scheme upgrade and vice versa. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 CSPSource::NoWildcard, CSPSource::HasWildcard); 134 CSPSource::NoWildcard, CSPSource::HasWildcard);
135 135
136 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"))); 136 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/")));
137 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/"))); 137 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/")));
138 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/"))); 138 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/")));
139 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:8000/"))); 139 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:8000/")));
140 } 140 }
141 141
142 TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort) { 142 TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort) {
143 KURL base; 143 KURL base;
144 CSPSource source(csp.get(), "http", "example.com", 80, "/",
145 CSPSource::NoWildcard, CSPSource::NoWildcard);
146 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/")));
147 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:80/")));
148 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443/")));
149 EXPECT_TRUE(source.matches(KURL(base, "https://example.com/")));
150 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:80/")));
151 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443/")));
152 144
153 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8443/"))); 145 // source scheme is "http"
154 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8443/"))); 146 {
147 CSPSource source(csp.get(), "http", "example.com", 80, "/",
148 CSPSource::NoWildcard, CSPSource::NoWildcard);
149 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/")));
150 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:80/")));
151 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443/")));
Mike West 2017/02/15 06:40:02 Here too. :)
arthursonzogni 2017/02/15 12:17:51 Done. BUG=692499
152 EXPECT_TRUE(source.matches(KURL(base, "https://example.com/")));
153 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:80/")));
Mike West 2017/02/15 06:40:02 Also here.
arthursonzogni 2017/02/15 12:17:51 Done. BUG=692499
154 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443/")));
155 155
156 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com/"))); 156 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8443/")));
157 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:80/"))); 157 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8443/")));
158 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:443/"))); 158
159 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com/"))); 159 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com/")));
160 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:80/"))); 160 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:80/")));
161 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:443/"))); 161 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:443/")));
162 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com/")));
163 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:80/")));
164 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:443/")));
165 }
166
167 // source scheme is empty
168 {
169 Persistent<ContentSecurityPolicy> csp(ContentSecurityPolicy::create());
170 csp->setupSelf(*SecurityOrigin::createFromString("http://example.com"));
171 CSPSource source(csp.get(), "", "example.com", 80, "/",
172 CSPSource::NoWildcard, CSPSource::NoWildcard);
173 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/")));
174 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443")));
175 // This is strange, the port is upgraded, even if the scheme is not https.
176 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443")));
Mike West 2017/02/15 06:40:02 Please file a bug and turn this into a TODO.
arthursonzogni 2017/02/15 12:17:51 Done. BUG=692499
177 }
162 } 178 }
163 179
164 TEST_F(CSPSourceTest, DoesNotSubsume) { 180 TEST_F(CSPSourceTest, DoesNotSubsume) {
165 struct Source { 181 struct Source {
166 const char* scheme; 182 const char* scheme;
167 const char* host; 183 const char* host;
168 const char* path; 184 const char* path;
169 const int port; 185 const int port;
170 }; 186 };
171 struct TestCase { 187 struct TestCase {
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 normalized = B->intersect(A); 796 normalized = B->intersect(A);
781 Source intersectBA = { 797 Source intersectBA = {
782 normalized->m_scheme, normalized->m_host, 798 normalized->m_scheme, normalized->m_host,
783 normalized->m_path, normalized->m_port, 799 normalized->m_path, normalized->m_port,
784 normalized->m_hostWildcard, normalized->m_portWildcard}; 800 normalized->m_hostWildcard, normalized->m_portWildcard};
785 EXPECT_TRUE(equalSources(intersectBA, test.normalized)); 801 EXPECT_TRUE(equalSources(intersectBA, test.normalized));
786 } 802 }
787 } 803 }
788 804
789 } // namespace blink 805 } // namespace blink
OLDNEW
« 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