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

Side by Side Diff: chrome/common/extensions/manifest_handlers/externally_connectable_unittest.cc

Issue 15862011: Restrict the externally_connectable manifest key to effectively a single origin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: yoz Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "chrome/common/extensions/extension_manifest_constants.h" 7 #include "chrome/common/extensions/extension_manifest_constants.h"
8 #include "chrome/common/extensions/features/feature.h" 8 #include "chrome/common/extensions/features/feature.h"
9 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" 9 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h"
10 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 10 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org/"))); 55 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org/")));
56 EXPECT_TRUE( 56 EXPECT_TRUE(
57 info->matches.MatchesURL(GURL("http://build.chromium.org/index.html"))); 57 info->matches.MatchesURL(GURL("http://build.chromium.org/index.html")));
58 EXPECT_FALSE(info->matches.MatchesURL(GURL("https://build.chromium.org"))); 58 EXPECT_FALSE(info->matches.MatchesURL(GURL("https://build.chromium.org")));
59 EXPECT_FALSE(info->matches.MatchesURL(GURL("https://build.chromium.org/"))); 59 EXPECT_FALSE(info->matches.MatchesURL(GURL("https://build.chromium.org/")));
60 EXPECT_FALSE( 60 EXPECT_FALSE(
61 info->matches.MatchesURL(GURL("http://foo.chromium.org/index.html"))); 61 info->matches.MatchesURL(GURL("http://foo.chromium.org/index.html")));
62 62
63 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com"))); 63 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com")));
64 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com/"))); 64 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com/")));
65
66 // TLD-style patterns should match just the TLD.
67 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://appspot.com/foo.html")));
68 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://com")));
69 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://go/here")));
70
71 // TLD-style patterns should *not* match any subdomains of the TLD.
72 EXPECT_FALSE(
73 info->matches.MatchesURL(GURL("http://codereview.appspot.com/foo.html")));
74 EXPECT_FALSE(
75 info->matches.MatchesURL(GURL("http://chromium.com/index.html")));
76 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://here.go/somewhere")));
77
78 // Paths that don't have any wildcards should match the exact domain, but
79 // ignore the trailing slash. This is kind of a corner case, so let's test it.
80 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://no.wildcard.path")));
81 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://no.wildcard.path/")));
82 EXPECT_FALSE(info->matches.MatchesURL(
83 GURL("http://no.wildcard.path/index.html")));
65 } 84 }
66 85
67 TEST_F(ExternallyConnectableTest, IDs) { 86 TEST_F(ExternallyConnectableTest, IDs) {
68 scoped_refptr<Extension> extension = 87 scoped_refptr<Extension> extension =
69 LoadAndExpectSuccess("externally_connectable_ids.json"); 88 LoadAndExpectSuccess("externally_connectable_ids.json");
70 ASSERT_TRUE(extension); 89 ASSERT_TRUE(extension);
71 90
72 ExternallyConnectableInfo* info = ExternallyConnectableInfo::Get(extension); 91 ExternallyConnectableInfo* info = ExternallyConnectableInfo::Get(extension);
73 ASSERT_TRUE(info); 92 ASSERT_TRUE(info);
74 93
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 166 }
148 167
149 TEST_F(ExternallyConnectableTest, ErrorBadMatches) { 168 TEST_F(ExternallyConnectableTest, ErrorBadMatches) {
150 RunTestcase( 169 RunTestcase(
151 Testcase("externally_connectable_error_bad_matches.json", 170 Testcase("externally_connectable_error_bad_matches.json",
152 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidMatchPattern, 171 ErrorUtils::FormatErrorMessage(errors::kErrorInvalidMatchPattern,
153 "www.yahoo.com")), 172 "www.yahoo.com")),
154 EXPECT_TYPE_ERROR); 173 EXPECT_TYPE_ERROR);
155 } 174 }
156 175
176 TEST_F(ExternallyConnectableTest, ErrorNoAllURLs) {
177 RunTestcase(
178 Testcase(
179 "externally_connectable_error_all_urls.json",
180 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed,
181 "<all_urls>")),
182 EXPECT_TYPE_ERROR);
183 }
184
185 TEST_F(ExternallyConnectableTest, ErrorWildcardHost) {
186 RunTestcase(
187 Testcase(
188 "externally_connectable_error_wildcard_host.json",
189 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed,
190 "http://*/*")),
191 EXPECT_TYPE_ERROR);
192 }
193
194 TEST_F(ExternallyConnectableTest, ErrorNoTLD) {
195 RunTestcase(
196 Testcase(
197 "externally_connectable_error_tld.json",
198 ErrorUtils::FormatErrorMessage(
199 errors::kErrorTopLevelDomainsNotAllowed,
200 "co.uk",
201 "http://*.co.uk/*")),
202 EXPECT_TYPE_ERROR);
203 }
204
205 TEST_F(ExternallyConnectableTest, ErrorNoEffectiveTLD) {
206 RunTestcase(
207 Testcase(
208 "externally_connectable_error_effective_tld.json",
209 ErrorUtils::FormatErrorMessage(
210 errors::kErrorTopLevelDomainsNotAllowed,
211 "appspot.com",
212 "http://*.appspot.com/*")),
213 EXPECT_TYPE_ERROR);
214 }
215
216 TEST_F(ExternallyConnectableTest, ErrorUnknownTLD) {
217 RunTestcase(
218 Testcase(
219 "externally_connectable_error_unknown_tld.json",
220 ErrorUtils::FormatErrorMessage(
221 errors::kErrorTopLevelDomainsNotAllowed,
222 "notatld",
223 "http://*.notatld/*")),
224 EXPECT_TYPE_ERROR);
225 }
226
157 } // namespace extensions 227 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698