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

Side by Side Diff: content/common/service_worker/service_worker_utils_unittest.cc

Issue 1259213002: Move Service Worker %2f path validation logic from browser into Blink (1) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix remaining nits. Created 5 years, 4 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 | « content/common/service_worker/service_worker_utils.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_utils.h" 5 #include "content/common/service_worker/service_worker_utils.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace content { 8 namespace content {
9 9
10 namespace { 10 namespace {
11 11
12 bool IsPathRestrictionSatisfied( 12 bool IsPathRestrictionSatisfied(const GURL& scope, const GURL& script_url) {
13 const GURL& scope, const GURL& script_url) {
14 std::string error_message; 13 std::string error_message;
15 return ServiceWorkerUtils::IsPathRestrictionSatisfied( 14 return ServiceWorkerUtils::IsPathRestrictionSatisfied(
16 scope, script_url, nullptr, &error_message); 15 scope, script_url, nullptr, &error_message);
17 } 16 }
18 17
19 bool IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader( 18 bool IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader(
20 const GURL& scope, 19 const GURL& scope,
21 const GURL& script_url, 20 const GURL& script_url,
22 const std::string& service_worker_allowed) { 21 const std::string& service_worker_allowed) {
23 std::string error_message; 22 std::string error_message;
24 return ServiceWorkerUtils::IsPathRestrictionSatisfied( 23 return ServiceWorkerUtils::IsPathRestrictionSatisfied(
25 scope, script_url, &service_worker_allowed, &error_message); 24 scope, script_url, &service_worker_allowed, &error_message);
26 } 25 }
27 26
28 } // namespace 27 } // namespace
29 28
30 TEST(ServiceWorkerUtilsTest, ScopeMatches) { 29 TEST(ServiceWorkerUtilsTest, ScopeMatches) {
31 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 30 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
32 GURL("http://www.example.com/"), GURL("http://www.example.com/"))); 31 GURL("http://www.example.com/"), GURL("http://www.example.com/")));
33 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 32 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
34 GURL("http://www.example.com/"), 33 GURL("http://www.example.com/"),
35 GURL("http://www.example.com/page.html"))); 34 GURL("http://www.example.com/page.html")));
36 35
37 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 36 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
38 GURL("http://www.example.com/"), GURL("https://www.example.com/"))); 37 GURL("http://www.example.com/"), GURL("https://www.example.com/")));
39 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 38 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
40 GURL("http://www.example.com/"), 39 GURL("http://www.example.com/"),
41 GURL("https://www.example.com/page.html"))); 40 GURL("https://www.example.com/page.html")));
42 41
43 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 42 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/"),
44 GURL("http://www.example.com/"), GURL("http://www.foo.com/"))); 43 GURL("http://www.foo.com/")));
45 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 44 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
46 GURL("http://www.example.com/"), GURL("https://www.foo.com/page.html"))); 45 GURL("http://www.example.com/"), GURL("https://www.foo.com/page.html")));
47 46
48 // '*' is not a wildcard. 47 // '*' is not a wildcard.
49 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 48 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
50 GURL("http://www.example.com/*"), GURL("http://www.example.com/x"))); 49 GURL("http://www.example.com/*"), GURL("http://www.example.com/x")));
51 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 50 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
52 GURL("http://www.example.com/*"), GURL("http://www.example.com/"))); 51 GURL("http://www.example.com/*"), GURL("http://www.example.com/")));
53 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 52 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
54 GURL("http://www.example.com/*"), GURL("http://www.example.com/xx"))); 53 GURL("http://www.example.com/*"), GURL("http://www.example.com/xx")));
(...skipping 18 matching lines...) Expand all
73 GURL("http://www.example.com/?"), GURL("http://www.example.com/"))); 72 GURL("http://www.example.com/?"), GURL("http://www.example.com/")));
74 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches( 73 ASSERT_FALSE(ServiceWorkerUtils::ScopeMatches(
75 GURL("http://www.example.com/?"), GURL("http://www.example.com/xx"))); 74 GURL("http://www.example.com/?"), GURL("http://www.example.com/xx")));
76 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 75 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
77 GURL("http://www.example.com/?"), GURL("http://www.example.com/?"))); 76 GURL("http://www.example.com/?"), GURL("http://www.example.com/?")));
78 77
79 // Query string is part of the resource. 78 // Query string is part of the resource.
80 ASSERT_TRUE( 79 ASSERT_TRUE(
81 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=b"), 80 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a=b"),
82 GURL("http://www.example.com/?a=b"))); 81 GURL("http://www.example.com/?a=b")));
83 ASSERT_TRUE( 82 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
84 ServiceWorkerUtils::ScopeMatches(GURL("http://www.example.com/?a="), 83 GURL("http://www.example.com/?a="), GURL("http://www.example.com/?a=b")));
85 GURL("http://www.example.com/?a=b")));
86 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 84 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
87 GURL("http://www.example.com/"), GURL("http://www.example.com/?a=b"))); 85 GURL("http://www.example.com/"), GURL("http://www.example.com/?a=b")));
88 86
89 // URLs canonicalize \ to / so this is equivalent to "...//x" 87 // URLs canonicalize \ to / so this is equivalent to "...//x"
90 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches( 88 ASSERT_TRUE(ServiceWorkerUtils::ScopeMatches(
91 GURL("http://www.example.com/\\x"), GURL("http://www.example.com//x"))); 89 GURL("http://www.example.com/\\x"), GURL("http://www.example.com//x")));
92 } 90 }
93 91
94 TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch) { 92 TEST(ServiceWorkerUtilsTest, FindLongestScopeMatch) {
95 LongestScopeMatcher matcher(GURL("http://www.example.com/xxx")); 93 LongestScopeMatcher matcher(GURL("http://www.example.com/xxx"));
96 94
97 // "/xx" should be matched longest. 95 // "/xx" should be matched longest.
98 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/x"))); 96 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/x")));
99 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/"))); 97 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/")));
100 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xx"))); 98 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xx")));
101 99
102 // "/xxx" should be matched longer than "/xx". 100 // "/xxx" should be matched longer than "/xx".
103 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xxx"))); 101 ASSERT_TRUE(matcher.MatchLongest(GURL("http://www.example.com/xxx")));
104 102
105 // The second call with the same URL should return false. 103 // The second call with the same URL should return false.
106 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxx"))); 104 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxx")));
107 105
108 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxxx"))); 106 ASSERT_FALSE(matcher.MatchLongest(GURL("http://www.example.com/xxxx")));
109 } 107 }
110 108
111 TEST(ServiceWorkerUtilsTest, PathRestriction_Basic) { 109 TEST(ServiceWorkerUtilsTest, PathRestriction_Basic) {
112 EXPECT_TRUE(IsPathRestrictionSatisfied( 110 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/"),
113 GURL("http://example.com/"), 111 GURL("http://example.com/sw.js")));
114 GURL("http://example.com/sw.js"))); 112 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/foo/"),
115 EXPECT_TRUE(IsPathRestrictionSatisfied( 113 GURL("http://example.com/sw.js")));
116 GURL("http://example.com/foo/"), 114 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/foo/"),
117 GURL("http://example.com/sw.js"))); 115 GURL("http://example.com/foo/sw.js")));
118 EXPECT_TRUE(IsPathRestrictionSatisfied( 116 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar"),
119 GURL("http://example.com/foo/"), 117 GURL("http://example.com/foo/sw.js")));
120 GURL("http://example.com/foo/sw.js")));
121 EXPECT_TRUE(IsPathRestrictionSatisfied(
122 GURL("http://example.com/foo/bar"),
123 GURL("http://example.com/foo/sw.js")));
124 EXPECT_FALSE(IsPathRestrictionSatisfied( 118 EXPECT_FALSE(IsPathRestrictionSatisfied(
125 GURL("http://example.com/"), 119 GURL("http://example.com/"), GURL("http://example.com/foo/sw.js")));
126 GURL("http://example.com/foo/sw.js")));
127 EXPECT_FALSE(IsPathRestrictionSatisfied( 120 EXPECT_FALSE(IsPathRestrictionSatisfied(
128 GURL("http://example.com/bar/"), 121 GURL("http://example.com/bar/"), GURL("http://example.com/foo/sw.js")));
129 GURL("http://example.com/foo/sw.js")));
130 122
131 // The scope is under the script directory, but that doesn't have the trailing 123 // The scope is under the script directory, but that doesn't have the trailing
132 // slash. In this case, the check should be failed. 124 // slash. In this case, the check should be failed.
133 EXPECT_FALSE(IsPathRestrictionSatisfied( 125 EXPECT_FALSE(IsPathRestrictionSatisfied(
134 GURL("http://example.com/foo"), 126 GURL("http://example.com/foo"), GURL("http://example.com/foo/sw.js")));
135 GURL("http://example.com/foo/sw.js")));
136 127
137 // Query parameters should not affect the path restriction. 128 // Query parameters should not affect the path restriction.
138 EXPECT_TRUE(IsPathRestrictionSatisfied( 129 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/?query"),
139 GURL("http://example.com/?query"), 130 GURL("http://example.com/sw.js")));
140 GURL("http://example.com/sw.js"))); 131 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/foo/?query"),
141 EXPECT_TRUE(IsPathRestrictionSatisfied( 132 GURL("http://example.com/sw.js")));
142 GURL("http://example.com/foo/?query"), 133 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/foo/?query"),
143 GURL("http://example.com/sw.js"))); 134 GURL("http://example.com/foo/sw.js")));
144 EXPECT_TRUE(IsPathRestrictionSatisfied(
145 GURL("http://example.com/foo/?query"),
146 GURL("http://example.com/foo/sw.js")));
147 EXPECT_FALSE(IsPathRestrictionSatisfied( 135 EXPECT_FALSE(IsPathRestrictionSatisfied(
148 GURL("http://example.com/?query"), 136 GURL("http://example.com/?query"), GURL("http://example.com/foo/sw.js")));
149 GURL("http://example.com/foo/sw.js"))); 137 EXPECT_FALSE(
150 EXPECT_FALSE(IsPathRestrictionSatisfied( 138 IsPathRestrictionSatisfied(GURL("http://example.com/bar/query?"),
151 GURL("http://example.com/bar/query?"), 139 GURL("http://example.com/foo/sw.js")));
152 GURL("http://example.com/foo/sw.js")));
153 140
154 EXPECT_TRUE(IsPathRestrictionSatisfied( 141 EXPECT_TRUE(IsPathRestrictionSatisfied(
155 GURL("http://example.com/"), 142 GURL("http://example.com/"), GURL("http://example.com/sw.js?query")));
156 GURL("http://example.com/sw.js?query")));
157 EXPECT_TRUE(IsPathRestrictionSatisfied( 143 EXPECT_TRUE(IsPathRestrictionSatisfied(
158 GURL("http://example.com/foo/"), 144 GURL("http://example.com/foo/"), GURL("http://example.com/sw.js?query")));
159 GURL("http://example.com/sw.js?query"))); 145 EXPECT_TRUE(
160 EXPECT_TRUE(IsPathRestrictionSatisfied( 146 IsPathRestrictionSatisfied(GURL("http://example.com/foo/"),
161 GURL("http://example.com/foo/"), 147 GURL("http://example.com/foo/sw.js?query")));
162 GURL("http://example.com/foo/sw.js?query")));
163 EXPECT_FALSE(IsPathRestrictionSatisfied( 148 EXPECT_FALSE(IsPathRestrictionSatisfied(
164 GURL("http://example.com/"), 149 GURL("http://example.com/"), GURL("http://example.com/foo/sw.js?query")));
165 GURL("http://example.com/foo/sw.js?query"))); 150 EXPECT_FALSE(
166 EXPECT_FALSE(IsPathRestrictionSatisfied( 151 IsPathRestrictionSatisfied(GURL("http://example.com/bar/"),
167 GURL("http://example.com/bar/"), 152 GURL("http://example.com/foo/sw.js?query")));
168 GURL("http://example.com/foo/sw.js?query")));
169 153
170 // Query parameter including a slash should not affect. 154 // Query parameter including a slash should not affect.
171 EXPECT_TRUE(IsPathRestrictionSatisfied( 155 EXPECT_TRUE(IsPathRestrictionSatisfied(
172 GURL("http://example.com/foo/bar?key/value"), 156 GURL("http://example.com/foo/bar?key/value"),
173 GURL("http://example.com/foo/sw.js?key=value"))); 157 GURL("http://example.com/foo/sw.js?key=value")));
174 EXPECT_TRUE(IsPathRestrictionSatisfied( 158 EXPECT_TRUE(IsPathRestrictionSatisfied(
175 GURL("http://example.com/foo/bar?key=value"), 159 GURL("http://example.com/foo/bar?key=value"),
176 GURL("http://example.com/foo/sw.js?key/value"))); 160 GURL("http://example.com/foo/sw.js?key/value")));
177 } 161 }
178 162
179 TEST(ServiceWorkerUtils, PathRestriction_SelfReference) { 163 TEST(ServiceWorkerUtils, PathRestriction_SelfReference) {
180 // Self reference is canonicalized. 164 // Self reference is canonicalized.
181 ASSERT_EQ(GURL("http://example.com/foo/bar"), 165 ASSERT_EQ(GURL("http://example.com/foo/bar"),
182 GURL("http://example.com/././foo/bar")); 166 GURL("http://example.com/././foo/bar"));
183 EXPECT_TRUE(IsPathRestrictionSatisfied( 167 EXPECT_TRUE(
184 GURL("http://example.com/foo/"), 168 IsPathRestrictionSatisfied(GURL("http://example.com/foo/"),
185 GURL("http://example.com/././foo/sw.js"))); 169 GURL("http://example.com/././foo/sw.js")));
186 EXPECT_TRUE(IsPathRestrictionSatisfied( 170 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/././foo/"),
187 GURL("http://example.com/././foo/"), 171 GURL("http://example.com/foo/sw.js")));
188 GURL("http://example.com/foo/sw.js"))); 172 EXPECT_TRUE(
189 EXPECT_TRUE(IsPathRestrictionSatisfied( 173 IsPathRestrictionSatisfied(GURL("http://example.com/foo/./"),
190 GURL("http://example.com/foo/./"), 174 GURL("http://example.com/./foo/sw.js")));
191 GURL("http://example.com/./foo/sw.js")));
192 175
193 // URL-encoded dot ('%2e') is also canonicalized. 176 // URL-encoded dot ('%2e') is also canonicalized.
194 ASSERT_EQ(GURL("http://example.com/foo/././bar"), 177 ASSERT_EQ(GURL("http://example.com/foo/././bar"),
195 GURL("http://example.com/foo/%2e/%2e/bar")); 178 GURL("http://example.com/foo/%2e/%2e/bar"));
196 EXPECT_TRUE(IsPathRestrictionSatisfied( 179 EXPECT_TRUE(
197 GURL("http://example.com/foo/%2e/%2e/bar"), 180 IsPathRestrictionSatisfied(GURL("http://example.com/foo/%2e/%2e/bar"),
198 GURL("http://example.com/foo/%2e/%2e/sw.js"))); 181 GURL("http://example.com/foo/%2e/%2e/sw.js")));
199 EXPECT_TRUE(IsPathRestrictionSatisfied( 182 EXPECT_TRUE(
200 GURL("http://example.com/foo/bar"), 183 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar"),
201 GURL("http://example.com/foo/%2e/%2e/sw.js"))); 184 GURL("http://example.com/foo/%2e/%2e/sw.js")));
202 EXPECT_TRUE(IsPathRestrictionSatisfied( 185 EXPECT_TRUE(
203 GURL("http://example.com/foo/%2e/%2e/bar"), 186 IsPathRestrictionSatisfied(GURL("http://example.com/foo/%2e/%2e/bar"),
204 GURL("http://example.com/foo/sw.js"))); 187 GURL("http://example.com/foo/sw.js")));
205 EXPECT_TRUE(IsPathRestrictionSatisfied( 188 EXPECT_TRUE(
206 GURL("http://example.com/foo/%2e/bar"), 189 IsPathRestrictionSatisfied(GURL("http://example.com/foo/%2e/bar"),
207 GURL("http://example.com/%2e/foo/sw.js"))); 190 GURL("http://example.com/%2e/foo/sw.js")));
208 191
209 // URL-encoded dot ('%2E') is also canonicalized. 192 // URL-encoded dot ('%2E') is also canonicalized.
210 ASSERT_EQ(GURL("http://example.com/foo/././bar"), 193 ASSERT_EQ(GURL("http://example.com/foo/././bar"),
211 GURL("http://example.com/foo/%2E/%2e/bar")); 194 GURL("http://example.com/foo/%2E/%2e/bar"));
212 } 195 }
213 196
214 TEST(ServiceWorkerUtilsTest, PathRestriction_ParentReference) { 197 TEST(ServiceWorkerUtilsTest, PathRestriction_ParentReference) {
215 // Parent reference is canonicalized. 198 // Parent reference is canonicalized.
216 ASSERT_EQ(GURL("http://example.com/foo/bar"), 199 ASSERT_EQ(GURL("http://example.com/foo/bar"),
217 GURL("http://example.com/foo/../foo/bar")); 200 GURL("http://example.com/foo/../foo/bar"));
218 EXPECT_TRUE(IsPathRestrictionSatisfied( 201 EXPECT_TRUE(
219 GURL("http://example.com/foo/bar"), 202 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar"),
220 GURL("http://example.com/foo/../foo/sw.js"))); 203 GURL("http://example.com/foo/../foo/sw.js")));
221 EXPECT_TRUE(IsPathRestrictionSatisfied( 204 EXPECT_TRUE(
222 GURL("http://example.com/foo/../foo/bar"), 205 IsPathRestrictionSatisfied(GURL("http://example.com/foo/../foo/bar"),
223 GURL("http://example.com/foo/sw.js"))); 206 GURL("http://example.com/foo/sw.js")));
224 EXPECT_TRUE(IsPathRestrictionSatisfied( 207 EXPECT_TRUE(
225 GURL("http://example.com/foo/bar/../bar"), 208 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar/../bar"),
226 GURL("http://example.com/../foo/sw.js"))); 209 GURL("http://example.com/../foo/sw.js")));
227 EXPECT_TRUE(IsPathRestrictionSatisfied( 210 EXPECT_TRUE(IsPathRestrictionSatisfied(
228 GURL("http://example.com/foo/../../../foo/bar"), 211 GURL("http://example.com/foo/../../../foo/bar"),
229 GURL("http://example.com/foo/sw.js"))); 212 GURL("http://example.com/foo/sw.js")));
230 EXPECT_FALSE(IsPathRestrictionSatisfied( 213 EXPECT_FALSE(
231 GURL("http://example.com/foo/../bar"), 214 IsPathRestrictionSatisfied(GURL("http://example.com/foo/../bar"),
232 GURL("http://example.com/foo/sw.js"))); 215 GURL("http://example.com/foo/sw.js")));
233 216
234 // URL-encoded dot ('%2e') is also canonicalized. 217 // URL-encoded dot ('%2e') is also canonicalized.
235 ASSERT_EQ(GURL("http://example.com/foo/../foo/bar"), 218 ASSERT_EQ(GURL("http://example.com/foo/../foo/bar"),
236 GURL("http://example.com/foo/%2e%2e/foo/bar")); 219 GURL("http://example.com/foo/%2e%2e/foo/bar"));
237 EXPECT_TRUE(IsPathRestrictionSatisfied( 220 EXPECT_TRUE(IsPathRestrictionSatisfied(
238 GURL("http://example.com/foo/bar"), 221 GURL("http://example.com/foo/bar"),
239 GURL("http://example.com/foo/%2e%2e/foo/sw.js"))); 222 GURL("http://example.com/foo/%2e%2e/foo/sw.js")));
240 EXPECT_TRUE(IsPathRestrictionSatisfied( 223 EXPECT_TRUE(
241 GURL("http://example.com/foo/%2e%2e/foo/bar"), 224 IsPathRestrictionSatisfied(GURL("http://example.com/foo/%2e%2e/foo/bar"),
242 GURL("http://example.com/foo/sw.js"))); 225 GURL("http://example.com/foo/sw.js")));
243 EXPECT_TRUE(IsPathRestrictionSatisfied( 226 EXPECT_TRUE(
244 GURL("http://example.com/foo/%2e%2e/foo/bar"), 227 IsPathRestrictionSatisfied(GURL("http://example.com/foo/%2e%2e/foo/bar"),
245 GURL("http://example.com/%2e%2e/foo/sw.js"))); 228 GURL("http://example.com/%2e%2e/foo/sw.js")));
246 EXPECT_TRUE(IsPathRestrictionSatisfied( 229 EXPECT_TRUE(IsPathRestrictionSatisfied(
247 GURL("http://example.com/foo/%2e%2e/%2e%2e/%2e%2e/foo/bar"), 230 GURL("http://example.com/foo/%2e%2e/%2e%2e/%2e%2e/foo/bar"),
248 GURL("http://example.com/foo/sw.js"))); 231 GURL("http://example.com/foo/sw.js")));
249 EXPECT_FALSE(IsPathRestrictionSatisfied( 232 EXPECT_FALSE(
250 GURL("http://example.com/foo/%2e%2e/bar"), 233 IsPathRestrictionSatisfied(GURL("http://example.com/foo/%2e%2e/bar"),
251 GURL("http://example.com/foo/sw.js"))); 234 GURL("http://example.com/foo/sw.js")));
252 235
253 // URL-encoded dot ('%2E') is also canonicalized. 236 // URL-encoded dot ('%2E') is also canonicalized.
254 ASSERT_EQ(GURL("http://example.com/foo/../foo/bar"), 237 ASSERT_EQ(GURL("http://example.com/foo/../foo/bar"),
255 GURL("http://example.com/foo/%2E%2E/foo/bar")); 238 GURL("http://example.com/foo/%2E%2E/foo/bar"));
256 } 239 }
257 240
258 TEST(ServiceWorkerUtilsTest, PathRestriction_ConsecutiveSlashes) { 241 TEST(ServiceWorkerUtilsTest, PathRestriction_ConsecutiveSlashes) {
259 // Consecutive slashes are not unified. 242 // Consecutive slashes are not unified.
260 ASSERT_NE(GURL("http://example.com/foo/bar"), 243 ASSERT_NE(GURL("http://example.com/foo/bar"),
261 GURL("http://example.com/foo///bar")); 244 GURL("http://example.com/foo///bar"));
262 EXPECT_FALSE(IsPathRestrictionSatisfied( 245 EXPECT_FALSE(
263 GURL("http://example.com/foo/bar"), 246 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar"),
264 GURL("http://example.com/foo///sw.js"))); 247 GURL("http://example.com/foo///sw.js")));
265 EXPECT_TRUE(IsPathRestrictionSatisfied( 248 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/foo///bar"),
266 GURL("http://example.com/foo///bar"), 249 GURL("http://example.com/foo/sw.js")));
267 GURL("http://example.com/foo/sw.js"))); 250 EXPECT_TRUE(
268 EXPECT_TRUE(IsPathRestrictionSatisfied( 251 IsPathRestrictionSatisfied(GURL("http://example.com/foo///bar"),
269 GURL("http://example.com/foo///bar"), 252 GURL("http://example.com/foo///sw.js")));
270 GURL("http://example.com/foo///sw.js")));
271 } 253 }
272 254
273 TEST(ServiceWorkerUtilsTest, PathRestriction_BackSlash) { 255 TEST(ServiceWorkerUtilsTest, PathRestriction_BackSlash) {
274 // A backslash is converted to a slash. 256 // A backslash is converted to a slash.
275 ASSERT_EQ(GURL("http://example.com/foo/bar"), 257 ASSERT_EQ(GURL("http://example.com/foo/bar"),
276 GURL("http://example.com/foo\\bar")); 258 GURL("http://example.com/foo\\bar"));
277 EXPECT_TRUE(IsPathRestrictionSatisfied( 259 EXPECT_TRUE(IsPathRestrictionSatisfied(GURL("http://example.com/foo\\bar"),
278 GURL("http://example.com/foo\\bar"), 260 GURL("http://example.com/foo/sw.js")));
279 GURL("http://example.com/foo/sw.js")));
280 261
281 // Consecutive back slashes should not unified. 262 // Consecutive back slashes should not unified.
282 ASSERT_NE(GURL("http://example.com/foo\\\\\\bar"), 263 ASSERT_NE(GURL("http://example.com/foo\\\\\\bar"),
283 GURL("http://example.com/foo\\bar")); 264 GURL("http://example.com/foo\\bar"));
284 EXPECT_FALSE(IsPathRestrictionSatisfied( 265 EXPECT_FALSE(
285 GURL("http://example.com/foo\\bar"), 266 IsPathRestrictionSatisfied(GURL("http://example.com/foo\\bar"),
286 GURL("http://example.com/foo\\\\\\sw.js"))); 267 GURL("http://example.com/foo\\\\\\sw.js")));
287 EXPECT_TRUE(IsPathRestrictionSatisfied( 268 EXPECT_TRUE(
288 GURL("http://example.com/foo\\\\\\bar"), 269 IsPathRestrictionSatisfied(GURL("http://example.com/foo\\\\\\bar"),
289 GURL("http://example.com/foo\\sw.js"))); 270 GURL("http://example.com/foo\\sw.js")));
290 } 271 }
291 272
292 TEST(ServiceWorkerUtilsTest, PathRestriction_DisallowedCharacter) { 273 TEST(ServiceWorkerUtilsTest, PathRestriction_DisallowedCharacter) {
293 // URL-encoded slash ('%2f') is not canonicalized. 274 // URL-encoded slash ('%2f') is not canonicalized.
294 ASSERT_NE(GURL("http://example.com/foo///bar"), 275 ASSERT_NE(GURL("http://example.com/foo///bar"),
295 GURL("http://example.com/foo/%2f/bar")); 276 GURL("http://example.com/foo/%2f/bar"));
296 EXPECT_FALSE(IsPathRestrictionSatisfied( 277 EXPECT_FALSE(
297 GURL("http://example.com/foo%2fbar/"), 278 IsPathRestrictionSatisfied(GURL("http://example.com/foo%2fbar/"),
298 GURL("http://example.com/foo/bar/sw.js"))); 279 GURL("http://example.com/foo/bar/sw.js")));
299 EXPECT_FALSE(IsPathRestrictionSatisfied( 280 EXPECT_FALSE(
300 GURL("http://example.com/foo/bar%2f"), 281 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar%2f"),
301 GURL("http://example.com/foo/bar/sw.js"))); 282 GURL("http://example.com/foo/bar/sw.js")));
302 EXPECT_FALSE(IsPathRestrictionSatisfied( 283 EXPECT_FALSE(
303 GURL("http://example.com/foo/bar/"), 284 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar/"),
304 GURL("http://example.com/foo/bar%2fsw.js"))); 285 GURL("http://example.com/foo/bar%2fsw.js")));
305 EXPECT_FALSE(IsPathRestrictionSatisfied( 286 EXPECT_FALSE(
306 GURL("http://example.com/foo/"), 287 IsPathRestrictionSatisfied(GURL("http://example.com/foo/"),
307 GURL("http://example.com/foo/bar%2fsw.js"))); 288 GURL("http://example.com/foo/bar%2fsw.js")));
308 289
309 // URL-encoded slash ('%2F') is also not canonicalized. 290 // URL-encoded slash ('%2F') is also not canonicalized.
310 ASSERT_NE(GURL("http://example.com/foo///bar"), 291 ASSERT_NE(GURL("http://example.com/foo///bar"),
311 GURL("http://example.com/foo/%2F/bar")); 292 GURL("http://example.com/foo/%2F/bar"));
312 EXPECT_FALSE(IsPathRestrictionSatisfied( 293 EXPECT_FALSE(
313 GURL("http://example.com/foo%2Fbar/"), 294 IsPathRestrictionSatisfied(GURL("http://example.com/foo%2Fbar/"),
314 GURL("http://example.com/foo/bar/sw.js"))); 295 GURL("http://example.com/foo/bar/sw.js")));
315 EXPECT_FALSE(IsPathRestrictionSatisfied( 296 EXPECT_FALSE(
316 GURL("http://example.com/foo/bar%2F"), 297 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar%2F"),
317 GURL("http://example.com/foo/bar/sw.js"))); 298 GURL("http://example.com/foo/bar/sw.js")));
318 EXPECT_FALSE(IsPathRestrictionSatisfied( 299 EXPECT_FALSE(
319 GURL("http://example.com/foo/bar/"), 300 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar/"),
320 GURL("http://example.com/foo/bar%2Fsw.js"))); 301 GURL("http://example.com/foo/bar%2Fsw.js")));
321 EXPECT_FALSE(IsPathRestrictionSatisfied( 302 EXPECT_FALSE(
322 GURL("http://example.com/foo/"), 303 IsPathRestrictionSatisfied(GURL("http://example.com/foo/"),
323 GURL("http://example.com/foo/bar%2Fsw.js"))); 304 GURL("http://example.com/foo/bar%2Fsw.js")));
324 305
325 // URL-encoded backslash ('%5c') is not canonicalized. 306 // URL-encoded backslash ('%5c') is not canonicalized.
326 ASSERT_NE(GURL("http://example.com/foo/\\/bar"), 307 ASSERT_NE(GURL("http://example.com/foo/\\/bar"),
327 GURL("http://example.com/foo/%5c/bar")); 308 GURL("http://example.com/foo/%5c/bar"));
328 EXPECT_FALSE(IsPathRestrictionSatisfied( 309 EXPECT_FALSE(
329 GURL("http://example.com/foo%5cbar/"), 310 IsPathRestrictionSatisfied(GURL("http://example.com/foo%5cbar/"),
330 GURL("http://example.com/foo/bar/sw.js"))); 311 GURL("http://example.com/foo/bar/sw.js")));
331 EXPECT_FALSE(IsPathRestrictionSatisfied( 312 EXPECT_FALSE(
332 GURL("http://example.com/foo/bar%5c"), 313 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar%5c"),
333 GURL("http://example.com/foo/bar/sw.js"))); 314 GURL("http://example.com/foo/bar/sw.js")));
334 EXPECT_FALSE(IsPathRestrictionSatisfied( 315 EXPECT_FALSE(
335 GURL("http://example.com/foo/bar/"), 316 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar/"),
336 GURL("http://example.com/foo/bar%5csw.js"))); 317 GURL("http://example.com/foo/bar%5csw.js")));
337 EXPECT_FALSE(IsPathRestrictionSatisfied( 318 EXPECT_FALSE(
338 GURL("http://example.com/foo/"), 319 IsPathRestrictionSatisfied(GURL("http://example.com/foo/"),
339 GURL("http://example.com/foo/bar%5csw.js"))); 320 GURL("http://example.com/foo/bar%5csw.js")));
340 321
341 // URL-encoded backslash ('%5C') is also not canonicalized. 322 // URL-encoded backslash ('%5C') is also not canonicalized.
342 ASSERT_NE(GURL("http://example.com/foo/\\/bar"), 323 ASSERT_NE(GURL("http://example.com/foo/\\/bar"),
343 GURL("http://example.com/foo/%5C/bar")); 324 GURL("http://example.com/foo/%5C/bar"));
344 EXPECT_FALSE(IsPathRestrictionSatisfied( 325 EXPECT_FALSE(
345 GURL("http://example.com/foo%5Cbar/"), 326 IsPathRestrictionSatisfied(GURL("http://example.com/foo%5Cbar/"),
346 GURL("http://example.com/foo/bar/sw.js"))); 327 GURL("http://example.com/foo/bar/sw.js")));
347 EXPECT_FALSE(IsPathRestrictionSatisfied( 328 EXPECT_FALSE(
348 GURL("http://example.com/foo/bar%5C"), 329 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar%5C"),
349 GURL("http://example.com/foo/bar/sw.js"))); 330 GURL("http://example.com/foo/bar/sw.js")));
350 EXPECT_FALSE(IsPathRestrictionSatisfied( 331 EXPECT_FALSE(
351 GURL("http://example.com/foo/bar/"), 332 IsPathRestrictionSatisfied(GURL("http://example.com/foo/bar/"),
352 GURL("http://example.com/foo/bar%5Csw.js"))); 333 GURL("http://example.com/foo/bar%5Csw.js")));
353 EXPECT_FALSE(IsPathRestrictionSatisfied( 334 EXPECT_FALSE(
354 GURL("http://example.com/foo/"), 335 IsPathRestrictionSatisfied(GURL("http://example.com/foo/"),
355 GURL("http://example.com/foo/bar%5Csw.js"))); 336 GURL("http://example.com/foo/bar%5Csw.js")));
356 337
357 // Query parameter should be able to have escaped characters. 338 // Query parameter should be able to have escaped characters.
358 EXPECT_TRUE(IsPathRestrictionSatisfied( 339 EXPECT_TRUE(IsPathRestrictionSatisfied(
359 GURL("http://example.com/foo/bar?key%2fvalue"), 340 GURL("http://example.com/foo/bar?key%2fvalue"),
360 GURL("http://example.com/foo/sw.js?key/value"))); 341 GURL("http://example.com/foo/sw.js?key/value")));
361 EXPECT_TRUE(IsPathRestrictionSatisfied( 342 EXPECT_TRUE(IsPathRestrictionSatisfied(
362 GURL("http://example.com/foo/bar?key/value"), 343 GURL("http://example.com/foo/bar?key/value"),
363 GURL("http://example.com/foo/sw.js?key%2fvalue"))); 344 GURL("http://example.com/foo/sw.js?key%2fvalue")));
364 EXPECT_TRUE(IsPathRestrictionSatisfied( 345 EXPECT_TRUE(IsPathRestrictionSatisfied(
365 GURL("http://example.com/foo/bar?key%5cvalue"), 346 GURL("http://example.com/foo/bar?key%5cvalue"),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 386
406 // Empty string resolves to max scope of "http://www.example.com/sw.js". 387 // Empty string resolves to max scope of "http://www.example.com/sw.js".
407 EXPECT_FALSE(IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader( 388 EXPECT_FALSE(IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader(
408 GURL("http://example.com/"), GURL("http://example.com/sw.js"), "")); 389 GURL("http://example.com/"), GURL("http://example.com/sw.js"), ""));
409 EXPECT_TRUE(IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader( 390 EXPECT_TRUE(IsPathRestrictionSatisfiedWithServiceWorkerAllowedHeader(
410 GURL("http://example.com/sw.js/hi"), GURL("http://example.com/sw.js"), 391 GURL("http://example.com/sw.js/hi"), GURL("http://example.com/sw.js"),
411 "")); 392 ""));
412 } 393 }
413 394
414 } // namespace content 395 } // namespace content
OLDNEW
« no previous file with comments | « content/common/service_worker/service_worker_utils.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698