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

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

Issue 2148793008: CSP: Allow ':80' to match ':443' in source expressions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
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/weborigin/KURL.h" 9 #include "platform/weborigin/KURL.h"
10 #include "platform/weborigin/SecurityOrigin.h" 10 #include "platform/weborigin/SecurityOrigin.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 CSPSource source(csp.get(), "http", "example.com", 8000, "/bar/", CSPSource: :NoWildcard, CSPSource::NoWildcard); 63 CSPSource source(csp.get(), "http", "example.com", 8000, "/bar/", CSPSource: :NoWildcard, CSPSource::NoWildcard);
64 64
65 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"), ContentSe curityPolicy::DidRedirect)); 65 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"), ContentSe curityPolicy::DidRedirect));
66 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/foo"), Conten tSecurityPolicy::DidRedirect)); 66 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/foo"), Conten tSecurityPolicy::DidRedirect));
67 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/foo"), Conte ntSecurityPolicy::DidRedirect)); 67 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/foo"), Conte ntSecurityPolicy::DidRedirect));
68 68
69 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/foo"), C ontentSecurityPolicy::DidRedirect)); 69 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/foo"), C ontentSecurityPolicy::DidRedirect));
70 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"), Cont entSecurityPolicy::DidNotRedirect)); 70 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:9000/foo/"), Cont entSecurityPolicy::DidNotRedirect));
71 } 71 }
72 72
73 TEST_F(CSPSourceTest, InsecureSourceMatchesSecure) 73 TEST_F(CSPSourceTest, InsecureSchemeMatchesSecureScheme)
74 { 74 {
75 KURL base; 75 KURL base;
76 CSPSource source(csp.get(), "http", "", 0, "/", CSPSource::NoWildcard, CSPSo urce::HasWildcard); 76 CSPSource source(csp.get(), "http", "", 0, "/", CSPSource::NoWildcard, CSPSo urce::HasWildcard);
77 77
78 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"))); 78 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/")));
79 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/"))); 79 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/")));
80 EXPECT_TRUE(source.matches(KURL(base, "http://not-example.com:8000/"))); 80 EXPECT_TRUE(source.matches(KURL(base, "http://not-example.com:8000/")));
81 EXPECT_TRUE(source.matches(KURL(base, "https://not-example.com:8000/"))); 81 EXPECT_TRUE(source.matches(KURL(base, "https://not-example.com:8000/")));
82 EXPECT_FALSE(source.matches(KURL(base, "ftp://example.com:8000/"))); 82 EXPECT_FALSE(source.matches(KURL(base, "ftp://example.com:8000/")));
83 } 83 }
84 84
85 TEST_F(CSPSourceTest, InsecureHostMatchesSecure) 85 TEST_F(CSPSourceTest, InsecureHostSchemeMatchesSecureScheme)
86 { 86 {
87 KURL base; 87 KURL base;
88 CSPSource source(csp.get(), "http", "example.com", 0, "/", CSPSource::NoWild card, CSPSource::HasWildcard); 88 CSPSource source(csp.get(), "http", "example.com", 0, "/", CSPSource::NoWild card, CSPSource::HasWildcard);
89 89
90 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/"))); 90 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:8000/")));
91 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/"))); 91 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:8000/")));
92 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/"))); 92 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:8000/")));
93 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:8000/"))); 93 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:8000/")));
94 } 94 }
95 95
96 TEST_F(CSPSourceTest, InsecureHostSchemePortMatchesSecurePort)
97 {
98 KURL base;
99 CSPSource source(csp.get(), "http", "example.com", 80, "/", CSPSource::NoWil dcard, CSPSource::NoWildcard);
100 EXPECT_TRUE(source.matches(KURL(base, "http://example.com/")));
101 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:80/")));
102 EXPECT_TRUE(source.matches(KURL(base, "http://example.com:443/")));
103 EXPECT_TRUE(source.matches(KURL(base, "https://example.com/")));
104 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:80/")));
105 EXPECT_TRUE(source.matches(KURL(base, "https://example.com:443/")));
106
107 EXPECT_FALSE(source.matches(KURL(base, "http://example.com:8443/")));
108 EXPECT_FALSE(source.matches(KURL(base, "https://example.com:8443/")));
109
110 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com/")));
111 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:80/")));
112 EXPECT_FALSE(source.matches(KURL(base, "http://not-example.com:443/")));
113 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com/")));
114 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:80/")));
115 EXPECT_FALSE(source.matches(KURL(base, "https://not-example.com:443/")));
116 }
117
118
119
96 } // namespace blink 120 } // 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