blob: 0ef72cc53708dc6685b8705ecf57773d884a52eb [file] [log] [blame]
Rouslan Solomakhinde012532017-09-20 15:18:341// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/payments/content/manifest_verifier.h"
6
7#include <stdint.h>
8#include <utility>
9
10#include "base/bind.h"
11#include "chrome/browser/profiles/profile_manager.h"
12#include "chrome/browser/ui/browser.h"
13#include "chrome/browser/ui/tabs/tab_strip_model.h"
14#include "chrome/browser/web_data_service_factory.h"
15#include "chrome/test/base/in_process_browser_test.h"
Rouslan Solomakhinde012532017-09-20 15:18:3416#include "components/payments/content/payment_manifest_web_data_service.h"
Jay Civellia7d22b42017-10-24 18:38:0717#include "components/payments/content/utility/payment_manifest_parser.h"
Rouslan Solomakhinde012532017-09-20 15:18:3418#include "components/payments/core/payment_manifest_downloader.h"
19#include "content/public/browser/browser_context.h"
20#include "content/public/browser/storage_partition.h"
21#include "net/test/embedded_test_server/embedded_test_server.h"
22#include "net/url_request/url_request_context_getter.h"
23#include "testing/gtest/include/gtest/gtest.h"
24#include "url/gurl.h"
25
26namespace payments {
27namespace {
28
29// Downloads everything from the test server.
30class TestDownloader : public PaymentMethodManifestDownloaderInterface {
31 public:
32 explicit TestDownloader(
33 const scoped_refptr<net::URLRequestContextGetter>& context)
34 : impl_(context) {}
35
36 ~TestDownloader() override {}
37
38 // PaymentMethodManifestDownloaderInterface implementation.
39 void DownloadPaymentMethodManifest(
40 const GURL& url,
41 PaymentManifestDownloadCallback callback) override {
42 // The length of "https://" URL prefix.
43 static const size_t kHttpsPrefixLength = 8;
44 impl_.DownloadPaymentMethodManifest(
45 GURL(test_server_url_.spec() + url.spec().substr(kHttpsPrefixLength)),
46 std::move(callback));
47 }
48
49 void set_test_server_url(const GURL& url) { test_server_url_ = url; }
50
51 private:
52 // The actual downloader.
53 PaymentManifestDownloader impl_;
54
55 // The base URL of the test server, e.g., "https://127.0.0.1:8080/".
56 GURL test_server_url_;
57
58 DISALLOW_COPY_AND_ASSIGN(TestDownloader);
59};
60
61// Tests for the manifest verifier.
62class ManifestVerifierBrowserTest : public InProcessBrowserTest {
63 public:
64 ManifestVerifierBrowserTest() {}
65 ~ManifestVerifierBrowserTest() override {}
66
67 // Starts the HTTPS test server on localhost.
68 void SetUpOnMainThread() override {
69 https_server_ = std::make_unique<net::EmbeddedTestServer>(
70 net::EmbeddedTestServer::TYPE_HTTPS);
71 ASSERT_TRUE(https_server_->InitializeAndListen());
72 https_server_->ServeFilesFromSourceDirectory(
73 "components/test/data/payments");
74 https_server_->StartAcceptingConnections();
75 }
76
77 // Runs the verifier on the |apps| and blocks until the verifier has finished
78 // using all resources.
79 void Verify(content::PaymentAppProvider::PaymentApps apps) {
80 auto downloader = std::make_unique<TestDownloader>(
81 content::BrowserContext::GetDefaultStoragePartition(
82 browser()
83 ->tab_strip_model()
84 ->GetActiveWebContents()
85 ->GetBrowserContext())
86 ->GetURLRequestContext());
87 downloader->set_test_server_url(https_server_->GetURL("/"));
88
89 ManifestVerifier verifier(
90 std::move(downloader),
Jay Civellia7d22b42017-10-24 18:38:0791 std::make_unique<payments::PaymentManifestParser>(),
Rouslan Solomakhinde012532017-09-20 15:18:3492 WebDataServiceFactory::GetPaymentManifestWebDataForProfile(
93 ProfileManager::GetActiveUserProfile(),
94 ServiceAccessType::EXPLICIT_ACCESS));
95
96 base::RunLoop run_loop;
97 finished_using_resources_closure_ = run_loop.QuitClosure();
98
99 verifier.Verify(
100 std::move(apps),
101 base::BindOnce(&ManifestVerifierBrowserTest::OnPaymentAppsVerified,
102 base::Unretained(this)),
103 base::BindOnce(&ManifestVerifierBrowserTest::OnFinishedUsingResources,
104 base::Unretained(this)));
105
106 run_loop.Run();
107 }
108
109 // Returns the apps that have been verified by the Verify() method.
110 const content::PaymentAppProvider::PaymentApps& verified_apps() const {
111 return verified_apps_;
112 }
113
114 // Expects that the verified payment app with |id| has the |expected_scope|
115 // and the |expected_methods|.
116 void ExpectApp(int64_t id,
117 const std::string& expected_scope,
118 const std::set<std::string>& expected_methods) {
119 ASSERT_NE(verified_apps().end(), verified_apps().find(id));
120 EXPECT_EQ(GURL(expected_scope), verified_apps().find(id)->second->scope);
121 std::set<std::string> actual_methods(
122 verified_apps().find(id)->second->enabled_methods.begin(),
123 verified_apps().find(id)->second->enabled_methods.end());
124 EXPECT_EQ(expected_methods, actual_methods);
125 }
126
127 private:
128 // Called by the verifier upon completed verification. These |apps| have only
129 // valid payment methods.
130 void OnPaymentAppsVerified(content::PaymentAppProvider::PaymentApps apps) {
131 verified_apps_ = std::move(apps);
132 }
133
134 // Called by the verifier upon saving the manifests in cache.
135 void OnFinishedUsingResources() { finished_using_resources_closure_.Run(); }
136
137 // Serves the payment method manifest files.
138 std::unique_ptr<net::EmbeddedTestServer> https_server_;
139
140 // The apps that have been verified by the Verify() method.
141 content::PaymentAppProvider::PaymentApps verified_apps_;
142
143 // Used to stop blocking the Verify() method and continue the test.
144 base::Closure finished_using_resources_closure_;
145
146 DISALLOW_COPY_AND_ASSIGN(ManifestVerifierBrowserTest);
147};
148
149// Absence of payment handlers should result in absence of verified payment
150// handlers.
151IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoApps) {
152 {
153 Verify(content::PaymentAppProvider::PaymentApps());
154
155 EXPECT_TRUE(verified_apps().empty());
156 }
157
158 // Repeat verifications should have identical results.
159 {
160 Verify(content::PaymentAppProvider::PaymentApps());
161
162 EXPECT_TRUE(verified_apps().empty());
163 }
164}
165
166// A payment handler without any payment method names is not valid.
167IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoMethods) {
168 {
169 content::PaymentAppProvider::PaymentApps apps;
170 apps[0] = std::make_unique<content::StoredPaymentApp>();
171 apps[0]->scope = GURL("https://bobpay.com/webpay");
172
173 Verify(std::move(apps));
174
175 EXPECT_TRUE(verified_apps().empty());
176 }
177
178 // Repeat verifications should have identical results.
179 {
180 content::PaymentAppProvider::PaymentApps apps;
181 apps[0] = std::make_unique<content::StoredPaymentApp>();
182 apps[0]->scope = GURL("https://bobpay.com/webpay");
183
184 Verify(std::move(apps));
185
186 EXPECT_TRUE(verified_apps().empty());
187 }
188}
189
190// A payment handler with an unknown non-URL payment method name is not valid.
191IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
192 UnknownPaymentMethodNameIsRemoved) {
193 {
194 content::PaymentAppProvider::PaymentApps apps;
195 apps[0] = std::make_unique<content::StoredPaymentApp>();
196 apps[0]->scope = GURL("https://bobpay.com/webpay");
197 apps[0]->enabled_methods.push_back("unknown");
198
199 Verify(std::move(apps));
200
201 EXPECT_TRUE(verified_apps().empty());
202 }
203
204 // Repeat verifications should have identical results.
205 {
206 content::PaymentAppProvider::PaymentApps apps;
207 apps[0] = std::make_unique<content::StoredPaymentApp>();
208 apps[0]->scope = GURL("https://bobpay.com/webpay");
209 apps[0]->enabled_methods.push_back("unknown");
210
211 Verify(std::move(apps));
212
213 EXPECT_TRUE(verified_apps().empty());
214 }
215}
216
217// A payment handler with "basic-card" payment method name is valid.
218IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, KnownPaymentMethodName) {
219 {
220 content::PaymentAppProvider::PaymentApps apps;
221 apps[0] = std::make_unique<content::StoredPaymentApp>();
222 apps[0]->scope = GURL("https://bobpay.com/webpay");
223 apps[0]->enabled_methods.push_back("basic-card");
224
225 Verify(std::move(apps));
226
227 EXPECT_EQ(1U, verified_apps().size());
228 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"});
229 }
230
231 // Repeat verifications should have identical results.
232 {
233 content::PaymentAppProvider::PaymentApps apps;
234 apps[0] = std::make_unique<content::StoredPaymentApp>();
235 apps[0]->scope = GURL("https://bobpay.com/webpay");
236 apps[0]->enabled_methods.push_back("basic-card");
237
238 Verify(std::move(apps));
239
240 EXPECT_EQ(1U, verified_apps().size());
241 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"});
242 }
243}
244
245// A payment handler with both "basic-card" and "interledger" payment method
246// names is valid.
247IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
248 TwoKnownPaymentMethodNames) {
249 {
250 content::PaymentAppProvider::PaymentApps apps;
251 apps[0] = std::make_unique<content::StoredPaymentApp>();
252 apps[0]->scope = GURL("https://bobpay.com/webpay");
253 apps[0]->enabled_methods.push_back("basic-card");
254 apps[0]->enabled_methods.push_back("interledger");
255
256 Verify(std::move(apps));
257
258 EXPECT_EQ(1U, verified_apps().size());
259 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"});
260 }
261
262 // Repeat verifications should have identical results.
263 {
264 content::PaymentAppProvider::PaymentApps apps;
265 apps[0] = std::make_unique<content::StoredPaymentApp>();
266 apps[0]->scope = GURL("https://bobpay.com/webpay");
267 apps[0]->enabled_methods.push_back("basic-card");
268 apps[0]->enabled_methods.push_back("interledger");
269
270 Verify(std::move(apps));
271
272 EXPECT_EQ(1U, verified_apps().size());
273 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"});
274 }
275}
276
277// Two payment handlers with "basic-card" payment method names are both valid.
278IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
279 TwoAppsWithKnownPaymentMethodNames) {
280 {
281 content::PaymentAppProvider::PaymentApps apps;
282 apps[0] = std::make_unique<content::StoredPaymentApp>();
283 apps[0]->scope = GURL("https://bobpay.com/webpay");
284 apps[0]->enabled_methods.push_back("basic-card");
285 apps[1] = std::make_unique<content::StoredPaymentApp>();
286 apps[1]->scope = GURL("https://alicepay.com/webpay");
287 apps[1]->enabled_methods.push_back("basic-card");
288
289 Verify(std::move(apps));
290
291 EXPECT_EQ(2U, verified_apps().size());
292 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"});
293 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"});
294 }
295
296 // Repeat verifications should have identical results.
297 {
298 content::PaymentAppProvider::PaymentApps apps;
299 apps[0] = std::make_unique<content::StoredPaymentApp>();
300 apps[0]->scope = GURL("https://bobpay.com/webpay");
301 apps[0]->enabled_methods.push_back("basic-card");
302 apps[1] = std::make_unique<content::StoredPaymentApp>();
303 apps[1]->scope = GURL("https://alicepay.com/webpay");
304 apps[1]->enabled_methods.push_back("basic-card");
305 Verify(std::move(apps));
306
307 EXPECT_EQ(2U, verified_apps().size());
308 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"});
309 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"});
310 }
311}
312
313// Verify that a payment handler from https://bobpay.com/webpay can use the
314// payment method name https://frankpay.com/webpay, because
315// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
316IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
317 BobPayHandlerCanUseMethodThatSupportsAllOrigins) {
318 {
319 content::PaymentAppProvider::PaymentApps apps;
320 apps[0] = std::make_unique<content::StoredPaymentApp>();
321 apps[0]->scope = GURL("https://bobpay.com/webpay");
322 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
323
324 Verify(std::move(apps));
325
326 EXPECT_EQ(1U, verified_apps().size());
327 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"});
328 }
329
330 // Repeat verifications should have identical results.
331 {
332 content::PaymentAppProvider::PaymentApps apps;
333 apps[0] = std::make_unique<content::StoredPaymentApp>();
334 apps[0]->scope = GURL("https://bobpay.com/webpay");
335 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
336 Verify(std::move(apps));
337
338 EXPECT_EQ(1U, verified_apps().size());
339 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"});
340 }
341}
342
343// Verify that a payment handler from an unreachable website can use the payment
344// method name https://frankpay.com/webpay, because
345// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
346IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
347 Handler404CanUseMethodThatSupportsAllOrigins) {
348 {
349 content::PaymentAppProvider::PaymentApps apps;
350 apps[0] = std::make_unique<content::StoredPaymentApp>();
351 apps[0]->scope = GURL("https://404.com/webpay");
352 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
353
354 Verify(std::move(apps));
355
356 EXPECT_EQ(1U, verified_apps().size());
357 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"});
358 }
359
360 // Repeat verifications should have identical results.
361 {
362 content::PaymentAppProvider::PaymentApps apps;
363 apps[0] = std::make_unique<content::StoredPaymentApp>();
364 apps[0]->scope = GURL("https://404.com/webpay");
365 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
366 Verify(std::move(apps));
367
368 EXPECT_EQ(1U, verified_apps().size());
369 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"});
370 }
371}
372
373// Verify that a payment handler from anywhere on https://bobpay.com can use the
374// payment method name from anywhere else on https://bobpay.com, because of the
375// origin match.
376IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
377 BobPayCanUseAnyMethodOnOwnOrigin) {
378 {
379 content::PaymentAppProvider::PaymentApps apps;
380 apps[0] = std::make_unique<content::StoredPaymentApp>();
381 apps[0]->scope = GURL("https://bobpay.com/anything/here");
382 apps[0]->enabled_methods.push_back(
383 "https://bobpay.com/does/not/matter/whats/here");
384
385 Verify(std::move(apps));
386
387 EXPECT_EQ(1U, verified_apps().size());
388 ExpectApp(0, "https://bobpay.com/anything/here",
389 {"https://bobpay.com/does/not/matter/whats/here"});
390 }
391
392 // Repeat verifications should have identical results.
393 {
394 content::PaymentAppProvider::PaymentApps apps;
395 apps[0] = std::make_unique<content::StoredPaymentApp>();
396 apps[0]->scope = GURL("https://bobpay.com/anything/here");
397 apps[0]->enabled_methods.push_back(
398 "https://bobpay.com/does/not/matter/whats/here");
399 Verify(std::move(apps));
400
401 EXPECT_EQ(1U, verified_apps().size());
402 ExpectApp(0, "https://bobpay.com/anything/here",
403 {"https://bobpay.com/does/not/matter/whats/here"});
404 }
405}
406
407// Verify that a payment handler from anywhere on an unreachable website can use
408// the payment method name from anywhere else on the same unreachable website,
409// because they have identical origin.
410IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
411 Handler404CanUseAnyMethodOnOwnOrigin) {
412 {
413 content::PaymentAppProvider::PaymentApps apps;
414 apps[0] = std::make_unique<content::StoredPaymentApp>();
415 apps[0]->scope = GURL("https://404.com/anything/here");
416 apps[0]->enabled_methods.push_back(
417 "https://404.com/does/not/matter/whats/here");
418
419 Verify(std::move(apps));
420
421 EXPECT_EQ(1U, verified_apps().size());
422 ExpectApp(0, "https://404.com/anything/here",
423 {"https://404.com/does/not/matter/whats/here"});
424 }
425
426 // Repeat verifications should have identical results.
427 {
428 content::PaymentAppProvider::PaymentApps apps;
429 apps[0] = std::make_unique<content::StoredPaymentApp>();
430 apps[0]->scope = GURL("https://404.com/anything/here");
431 apps[0]->enabled_methods.push_back(
432 "https://404.com/does/not/matter/whats/here");
433 Verify(std::move(apps));
434
435 EXPECT_EQ(1U, verified_apps().size());
436 ExpectApp(0, "https://404.com/anything/here",
437 {"https://404.com/does/not/matter/whats/here"});
438 }
439}
440
441// Verify that only the payment handler from https://alicepay.com/webpay can use
442// payment methods https://georgepay.com/webpay and https://ikepay.com/webpay,
443// because both https://georgepay.com/payment-manifest.json and
444// https://ikepay.com/payment-manifest.json contain "supported_origins":
445// ["https://alicepay.com"]. The payment handler from https://bobpay.com/webpay
446// cannot use these payment methods, however.
447IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, OneSupportedOrigin) {
448 {
449 content::PaymentAppProvider::PaymentApps apps;
450 apps[0] = std::make_unique<content::StoredPaymentApp>();
451 apps[0]->scope = GURL("https://alicepay.com/webpay");
452 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
453 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
454 apps[1] = std::make_unique<content::StoredPaymentApp>();
455 apps[1]->scope = GURL("https://bobpay.com/webpay");
456 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
457 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
458
459 Verify(std::move(apps));
460
461 EXPECT_EQ(1U, verified_apps().size());
462 ExpectApp(0, "https://alicepay.com/webpay",
463 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"});
464 }
465
466 // Repeat verifications should have identical results.
467 {
468 content::PaymentAppProvider::PaymentApps apps;
469 apps[0] = std::make_unique<content::StoredPaymentApp>();
470 apps[0]->scope = GURL("https://alicepay.com/webpay");
471 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
472 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
473 apps[1] = std::make_unique<content::StoredPaymentApp>();
474 apps[1]->scope = GURL("https://bobpay.com/webpay");
475 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
476 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
477
478 Verify(std::move(apps));
479
480 EXPECT_EQ(1U, verified_apps().size());
481 ExpectApp(0, "https://alicepay.com/webpay",
482 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"});
483 }
484}
485
486// Verify that a payment handler from https://alicepay.com/webpay can use all
487// three of non-URL payment method name, same-origin URL payment method name,
488// and different-origin URL payment method name.
489IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, ThreeTypesOfMethods) {
490 {
491 content::PaymentAppProvider::PaymentApps apps;
492 apps[0] = std::make_unique<content::StoredPaymentApp>();
493 apps[0]->scope = GURL("https://alicepay.com/webpay");
494 apps[0]->enabled_methods.push_back("basic-card");
495 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
496 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
497
498 Verify(std::move(apps));
499
500 EXPECT_EQ(1U, verified_apps().size());
501 ExpectApp(0, "https://alicepay.com/webpay",
502 {"basic-card", "https://alicepay.com/webpay2",
503 "https://ikepay.com/webpay"});
504 }
505
506 // Repeat verifications should have identical results.
507 {
508 content::PaymentAppProvider::PaymentApps apps;
509 apps[0] = std::make_unique<content::StoredPaymentApp>();
510 apps[0]->scope = GURL("https://alicepay.com/webpay");
511 apps[0]->enabled_methods.push_back("basic-card");
512 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
513 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
514
515 Verify(std::move(apps));
516
517 EXPECT_EQ(1U, verified_apps().size());
518 ExpectApp(0, "https://alicepay.com/webpay",
519 {"basic-card", "https://alicepay.com/webpay2",
520 "https://ikepay.com/webpay"});
521 }
522}
523
524// Verify that a payment handler from https://bobpay.com/webpay cannot use
525// payment method names that are unreachable websites, the origin of which does
526// not match that of the payment handler.
527IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, PaymentMethodName404) {
528 {
529 content::PaymentAppProvider::PaymentApps apps;
530 apps[0] = std::make_unique<content::StoredPaymentApp>();
531 apps[0]->scope = GURL("https://bobpay.com/webpay");
532 apps[0]->enabled_methods.push_back("https://404.com/webpay");
533 apps[0]->enabled_methods.push_back("https://404aswell.com/webpay");
534
535 Verify(std::move(apps));
536
537 EXPECT_TRUE(verified_apps().empty());
538 }
539
540 // Repeat verifications should have identical results.
541 {
542 content::PaymentAppProvider::PaymentApps apps;
543 apps[0] = std::make_unique<content::StoredPaymentApp>();
544 apps[0]->scope = GURL("https://bobpay.com/webpay");
545 apps[0]->enabled_methods.push_back("https://404.com/webpay");
546 apps[0]->enabled_methods.push_back("https://404aswell.com/webpay");
547
548 Verify(std::move(apps));
549
550 EXPECT_TRUE(verified_apps().empty());
551 }
552}
553
554} // namespace
555} // namespace payments