blob: c0a89c69bba45bf1a72ed2ab6aba866f7dd4018b [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
Sebastien Marchandf1349f52019-01-25 03:16:4110#include "base/bind.h"
Rouslan Solomakhin438d8c92017-10-26 21:33:1811#include "base/run_loop.h"
12#include "chrome/browser/profiles/profile.h"
Rouslan Solomakhinde012532017-09-20 15:18:3413#include "chrome/browser/ui/browser.h"
14#include "chrome/browser/ui/tabs/tab_strip_model.h"
15#include "chrome/browser/web_data_service_factory.h"
16#include "chrome/test/base/in_process_browser_test.h"
Rouslan Solomakhinde012532017-09-20 15:18:3417#include "components/payments/content/payment_manifest_web_data_service.h"
Jay Civellia7d22b42017-10-24 18:38:0718#include "components/payments/content/utility/payment_manifest_parser.h"
Rouslan Solomakhin438d8c92017-10-26 21:33:1819#include "components/payments/core/test_payment_manifest_downloader.h"
Rouslan Solomakhinde012532017-09-20 15:18:3420#include "content/public/browser/browser_context.h"
21#include "content/public/browser/storage_partition.h"
22#include "net/test/embedded_test_server/embedded_test_server.h"
23#include "net/url_request/url_request_context_getter.h"
24#include "testing/gtest/include/gtest/gtest.h"
Rouslan Solomakhind5dcc322019-07-11 21:47:2025#include "third_party/re2/src/re2/re2.h"
Rouslan Solomakhinde012532017-09-20 15:18:3426
27namespace payments {
28namespace {
29
Rouslan Solomakhinde012532017-09-20 15:18:3430// Tests for the manifest verifier.
31class ManifestVerifierBrowserTest : public InProcessBrowserTest {
32 public:
33 ManifestVerifierBrowserTest() {}
34 ~ManifestVerifierBrowserTest() override {}
35
36 // Starts the HTTPS test server on localhost.
37 void SetUpOnMainThread() override {
38 https_server_ = std::make_unique<net::EmbeddedTestServer>(
39 net::EmbeddedTestServer::TYPE_HTTPS);
40 ASSERT_TRUE(https_server_->InitializeAndListen());
41 https_server_->ServeFilesFromSourceDirectory(
42 "components/test/data/payments");
43 https_server_->StartAcceptingConnections();
44 }
45
46 // Runs the verifier on the |apps| and blocks until the verifier has finished
47 // using all resources.
48 void Verify(content::PaymentAppProvider::PaymentApps apps) {
Rouslan Solomakhindbf593d92017-11-21 19:20:5749 content::WebContents* web_contents =
50 browser()->tab_strip_model()->GetActiveWebContents();
51 content::BrowserContext* context = web_contents->GetBrowserContext();
Rouslan Solomakhinde012532017-09-20 15:18:3452 auto downloader = std::make_unique<TestDownloader>(
Rouslan Solomakhin438d8c92017-10-26 21:33:1853 content::BrowserContext::GetDefaultStoragePartition(context)
John Abd-El-Malekaef36cb2018-06-26 17:18:2354 ->GetURLLoaderFactoryForBrowserProcess());
Rouslan Solomakhin438d8c92017-10-26 21:33:1855 downloader->AddTestServerURL("https://", https_server_->GetURL("/"));
Rouslan Solomakhine2537212018-11-14 17:07:2956 auto parser = std::make_unique<payments::PaymentManifestParser>(
57 std::make_unique<ErrorLogger>());
gogerald84ae6262018-02-06 06:21:4658 auto cache = WebDataServiceFactory::GetPaymentManifestWebDataForProfile(
59 Profile::FromBrowserContext(context),
60 ServiceAccessType::EXPLICIT_ACCESS);
Rouslan Solomakhinde012532017-09-20 15:18:3461
gogerald84ae6262018-02-06 06:21:4662 ManifestVerifier verifier(web_contents, downloader.get(), parser.get(),
63 cache.get());
Rouslan Solomakhinde012532017-09-20 15:18:3464
65 base::RunLoop run_loop;
Rouslan Solomakhinde012532017-09-20 15:18:3466 verifier.Verify(
67 std::move(apps),
68 base::BindOnce(&ManifestVerifierBrowserTest::OnPaymentAppsVerified,
69 base::Unretained(this)),
Rouslan Solomakhin438d8c92017-10-26 21:33:1870 run_loop.QuitClosure());
Rouslan Solomakhinde012532017-09-20 15:18:3471 run_loop.Run();
72 }
73
74 // Returns the apps that have been verified by the Verify() method.
75 const content::PaymentAppProvider::PaymentApps& verified_apps() const {
76 return verified_apps_;
77 }
78
Rouslan Solomakhind5dcc322019-07-11 21:47:2079 const std::string& error_message() const { return error_message_; }
80
Rouslan Solomakhinde012532017-09-20 15:18:3481 // Expects that the verified payment app with |id| has the |expected_scope|
gogeralda74f9dec2018-04-10 00:33:4782 // and the |expected_methods| and the
83 // |expect_has_explicitly_verified_methods|.
Rouslan Solomakhinde012532017-09-20 15:18:3484 void ExpectApp(int64_t id,
85 const std::string& expected_scope,
gogeralda74f9dec2018-04-10 00:33:4786 const std::set<std::string>& expected_methods,
87 bool expect_has_explicitly_verified_methods) {
Rouslan Solomakhin478d93e32017-10-27 17:06:3788 const auto& it = verified_apps().find(id);
89 ASSERT_NE(verified_apps().end(), it);
90 EXPECT_EQ(GURL(expected_scope), it->second->scope);
91 std::set<std::string> actual_methods(it->second->enabled_methods.begin(),
92 it->second->enabled_methods.end());
Rouslan Solomakhinde012532017-09-20 15:18:3493 EXPECT_EQ(expected_methods, actual_methods);
gogeralda74f9dec2018-04-10 00:33:4794 EXPECT_EQ(expect_has_explicitly_verified_methods,
95 it->second->has_explicitly_verified_methods);
Rouslan Solomakhind5dcc322019-07-11 21:47:2096 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:3497 }
98
99 private:
100 // Called by the verifier upon completed verification. These |apps| have only
101 // valid payment methods.
Rouslan Solomakhind5dcc322019-07-11 21:47:20102 void OnPaymentAppsVerified(content::PaymentAppProvider::PaymentApps apps,
103 const std::string& error_message) {
Rouslan Solomakhinde012532017-09-20 15:18:34104 verified_apps_ = std::move(apps);
Rouslan Solomakhind5dcc322019-07-11 21:47:20105 error_message_ = error_message;
Rouslan Solomakhinde012532017-09-20 15:18:34106 }
107
Rouslan Solomakhinde012532017-09-20 15:18:34108 // Serves the payment method manifest files.
109 std::unique_ptr<net::EmbeddedTestServer> https_server_;
110
111 // The apps that have been verified by the Verify() method.
112 content::PaymentAppProvider::PaymentApps verified_apps_;
113
Rouslan Solomakhind5dcc322019-07-11 21:47:20114 std::string error_message_;
115
Rouslan Solomakhinde012532017-09-20 15:18:34116 DISALLOW_COPY_AND_ASSIGN(ManifestVerifierBrowserTest);
117};
118
119// Absence of payment handlers should result in absence of verified payment
120// handlers.
121IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoApps) {
122 {
123 Verify(content::PaymentAppProvider::PaymentApps());
124
125 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20126 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34127 }
128
129 // Repeat verifications should have identical results.
130 {
131 Verify(content::PaymentAppProvider::PaymentApps());
132
133 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20134 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34135 }
136}
137
138// A payment handler without any payment method names is not valid.
139IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoMethods) {
140 {
141 content::PaymentAppProvider::PaymentApps apps;
142 apps[0] = std::make_unique<content::StoredPaymentApp>();
143 apps[0]->scope = GURL("https://bobpay.com/webpay");
144
145 Verify(std::move(apps));
146
147 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20148 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34149 }
150
151 // Repeat verifications should have identical results.
152 {
153 content::PaymentAppProvider::PaymentApps apps;
154 apps[0] = std::make_unique<content::StoredPaymentApp>();
155 apps[0]->scope = GURL("https://bobpay.com/webpay");
156
157 Verify(std::move(apps));
158
159 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20160 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34161 }
162}
163
164// A payment handler with an unknown non-URL payment method name is not valid.
165IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
166 UnknownPaymentMethodNameIsRemoved) {
167 {
168 content::PaymentAppProvider::PaymentApps apps;
169 apps[0] = std::make_unique<content::StoredPaymentApp>();
170 apps[0]->scope = GURL("https://bobpay.com/webpay");
171 apps[0]->enabled_methods.push_back("unknown");
172
173 Verify(std::move(apps));
174
175 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20176 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34177 }
178
179 // Repeat verifications should have identical results.
180 {
181 content::PaymentAppProvider::PaymentApps apps;
182 apps[0] = std::make_unique<content::StoredPaymentApp>();
183 apps[0]->scope = GURL("https://bobpay.com/webpay");
184 apps[0]->enabled_methods.push_back("unknown");
185
186 Verify(std::move(apps));
187
188 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20189 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34190 }
191}
192
193// A payment handler with "basic-card" payment method name is valid.
194IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, KnownPaymentMethodName) {
195 {
196 content::PaymentAppProvider::PaymentApps apps;
197 apps[0] = std::make_unique<content::StoredPaymentApp>();
198 apps[0]->scope = GURL("https://bobpay.com/webpay");
199 apps[0]->enabled_methods.push_back("basic-card");
200
201 Verify(std::move(apps));
202
203 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47204 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20205 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34206 }
207
208 // Repeat verifications should have identical results.
209 {
210 content::PaymentAppProvider::PaymentApps apps;
211 apps[0] = std::make_unique<content::StoredPaymentApp>();
212 apps[0]->scope = GURL("https://bobpay.com/webpay");
213 apps[0]->enabled_methods.push_back("basic-card");
214
215 Verify(std::move(apps));
216
217 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47218 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20219 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34220 }
221}
222
223// A payment handler with both "basic-card" and "interledger" payment method
224// names is valid.
225IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
226 TwoKnownPaymentMethodNames) {
227 {
228 content::PaymentAppProvider::PaymentApps apps;
229 apps[0] = std::make_unique<content::StoredPaymentApp>();
230 apps[0]->scope = GURL("https://bobpay.com/webpay");
231 apps[0]->enabled_methods.push_back("basic-card");
232 apps[0]->enabled_methods.push_back("interledger");
233
234 Verify(std::move(apps));
235
236 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47237 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"},
238 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20239 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34240 }
241
242 // Repeat verifications should have identical results.
243 {
244 content::PaymentAppProvider::PaymentApps apps;
245 apps[0] = std::make_unique<content::StoredPaymentApp>();
246 apps[0]->scope = GURL("https://bobpay.com/webpay");
247 apps[0]->enabled_methods.push_back("basic-card");
248 apps[0]->enabled_methods.push_back("interledger");
249
250 Verify(std::move(apps));
251
252 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47253 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"},
254 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20255 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34256 }
257}
258
259// Two payment handlers with "basic-card" payment method names are both valid.
260IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
261 TwoAppsWithKnownPaymentMethodNames) {
262 {
263 content::PaymentAppProvider::PaymentApps apps;
264 apps[0] = std::make_unique<content::StoredPaymentApp>();
265 apps[0]->scope = GURL("https://bobpay.com/webpay");
266 apps[0]->enabled_methods.push_back("basic-card");
267 apps[1] = std::make_unique<content::StoredPaymentApp>();
268 apps[1]->scope = GURL("https://alicepay.com/webpay");
269 apps[1]->enabled_methods.push_back("basic-card");
270
271 Verify(std::move(apps));
272
273 EXPECT_EQ(2U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47274 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
275 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20276 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34277 }
278
279 // Repeat verifications should have identical results.
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 Verify(std::move(apps));
289
290 EXPECT_EQ(2U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47291 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
292 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20293 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34294 }
295}
296
297// Verify that a payment handler from https://bobpay.com/webpay can use the
298// payment method name https://frankpay.com/webpay, because
299// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
300IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
301 BobPayHandlerCanUseMethodThatSupportsAllOrigins) {
302 {
303 content::PaymentAppProvider::PaymentApps apps;
304 apps[0] = std::make_unique<content::StoredPaymentApp>();
305 apps[0]->scope = GURL("https://bobpay.com/webpay");
306 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
307
308 Verify(std::move(apps));
309
310 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47311 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"},
312 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20313 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34314 }
315
316 // Repeat verifications should have identical results.
317 {
318 content::PaymentAppProvider::PaymentApps apps;
319 apps[0] = std::make_unique<content::StoredPaymentApp>();
320 apps[0]->scope = GURL("https://bobpay.com/webpay");
321 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
322 Verify(std::move(apps));
323
324 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47325 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"},
326 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20327 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34328 }
329}
330
331// Verify that a payment handler from an unreachable website can use the payment
332// method name https://frankpay.com/webpay, because
333// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
334IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
335 Handler404CanUseMethodThatSupportsAllOrigins) {
336 {
337 content::PaymentAppProvider::PaymentApps apps;
338 apps[0] = std::make_unique<content::StoredPaymentApp>();
339 apps[0]->scope = GURL("https://404.com/webpay");
340 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
341
342 Verify(std::move(apps));
343
344 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47345 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"},
346 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20347 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34348 }
349
350 // Repeat verifications should have identical results.
351 {
352 content::PaymentAppProvider::PaymentApps apps;
353 apps[0] = std::make_unique<content::StoredPaymentApp>();
354 apps[0]->scope = GURL("https://404.com/webpay");
355 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
356 Verify(std::move(apps));
357
358 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47359 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"},
360 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20361 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34362 }
363}
364
365// Verify that a payment handler from anywhere on https://bobpay.com can use the
366// payment method name from anywhere else on https://bobpay.com, because of the
367// origin match.
368IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
369 BobPayCanUseAnyMethodOnOwnOrigin) {
370 {
371 content::PaymentAppProvider::PaymentApps apps;
372 apps[0] = std::make_unique<content::StoredPaymentApp>();
373 apps[0]->scope = GURL("https://bobpay.com/anything/here");
374 apps[0]->enabled_methods.push_back(
375 "https://bobpay.com/does/not/matter/whats/here");
376
377 Verify(std::move(apps));
378
379 EXPECT_EQ(1U, verified_apps().size());
380 ExpectApp(0, "https://bobpay.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47381 {"https://bobpay.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20382 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34383 }
384
385 // Repeat verifications should have identical results.
386 {
387 content::PaymentAppProvider::PaymentApps apps;
388 apps[0] = std::make_unique<content::StoredPaymentApp>();
389 apps[0]->scope = GURL("https://bobpay.com/anything/here");
390 apps[0]->enabled_methods.push_back(
391 "https://bobpay.com/does/not/matter/whats/here");
392 Verify(std::move(apps));
393
394 EXPECT_EQ(1U, verified_apps().size());
395 ExpectApp(0, "https://bobpay.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47396 {"https://bobpay.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20397 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34398 }
399}
400
401// Verify that a payment handler from anywhere on an unreachable website can use
402// the payment method name from anywhere else on the same unreachable website,
403// because they have identical origin.
404IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
405 Handler404CanUseAnyMethodOnOwnOrigin) {
406 {
407 content::PaymentAppProvider::PaymentApps apps;
408 apps[0] = std::make_unique<content::StoredPaymentApp>();
409 apps[0]->scope = GURL("https://404.com/anything/here");
410 apps[0]->enabled_methods.push_back(
411 "https://404.com/does/not/matter/whats/here");
412
413 Verify(std::move(apps));
414
415 EXPECT_EQ(1U, verified_apps().size());
416 ExpectApp(0, "https://404.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47417 {"https://404.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20418 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34419 }
420
421 // Repeat verifications should have identical results.
422 {
423 content::PaymentAppProvider::PaymentApps apps;
424 apps[0] = std::make_unique<content::StoredPaymentApp>();
425 apps[0]->scope = GURL("https://404.com/anything/here");
426 apps[0]->enabled_methods.push_back(
427 "https://404.com/does/not/matter/whats/here");
428 Verify(std::move(apps));
429
430 EXPECT_EQ(1U, verified_apps().size());
431 ExpectApp(0, "https://404.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47432 {"https://404.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20433 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34434 }
435}
436
437// Verify that only the payment handler from https://alicepay.com/webpay can use
438// payment methods https://georgepay.com/webpay and https://ikepay.com/webpay,
439// because both https://georgepay.com/payment-manifest.json and
440// https://ikepay.com/payment-manifest.json contain "supported_origins":
441// ["https://alicepay.com"]. The payment handler from https://bobpay.com/webpay
442// cannot use these payment methods, however.
443IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, OneSupportedOrigin) {
444 {
445 content::PaymentAppProvider::PaymentApps apps;
446 apps[0] = std::make_unique<content::StoredPaymentApp>();
447 apps[0]->scope = GURL("https://alicepay.com/webpay");
448 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
449 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
450 apps[1] = std::make_unique<content::StoredPaymentApp>();
451 apps[1]->scope = GURL("https://bobpay.com/webpay");
452 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
453 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
454
455 Verify(std::move(apps));
456
457 EXPECT_EQ(1U, verified_apps().size());
458 ExpectApp(0, "https://alicepay.com/webpay",
gogeralda74f9dec2018-04-10 00:33:47459 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"},
460 true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20461 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34462 }
463
464 // Repeat verifications should have identical results.
465 {
466 content::PaymentAppProvider::PaymentApps apps;
467 apps[0] = std::make_unique<content::StoredPaymentApp>();
468 apps[0]->scope = GURL("https://alicepay.com/webpay");
469 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
470 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
471 apps[1] = std::make_unique<content::StoredPaymentApp>();
472 apps[1]->scope = GURL("https://bobpay.com/webpay");
473 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
474 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
475
476 Verify(std::move(apps));
477
478 EXPECT_EQ(1U, verified_apps().size());
479 ExpectApp(0, "https://alicepay.com/webpay",
gogeralda74f9dec2018-04-10 00:33:47480 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"},
481 true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20482 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34483 }
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",
gogeralda74f9dec2018-04-10 00:33:47503 "https://ikepay.com/webpay"},
504 true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20505 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34506 }
507
508 // Repeat verifications should have identical results.
509 {
510 content::PaymentAppProvider::PaymentApps apps;
511 apps[0] = std::make_unique<content::StoredPaymentApp>();
512 apps[0]->scope = GURL("https://alicepay.com/webpay");
513 apps[0]->enabled_methods.push_back("basic-card");
514 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
515 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
516
517 Verify(std::move(apps));
518
519 EXPECT_EQ(1U, verified_apps().size());
520 ExpectApp(0, "https://alicepay.com/webpay",
521 {"basic-card", "https://alicepay.com/webpay2",
gogeralda74f9dec2018-04-10 00:33:47522 "https://ikepay.com/webpay"},
523 true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20524 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34525 }
526}
527
528// Verify that a payment handler from https://bobpay.com/webpay cannot use
529// payment method names that are unreachable websites, the origin of which does
530// not match that of the payment handler.
Rouslan Solomakhind5dcc322019-07-11 21:47:20531IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
532 SinglePaymentMethodName404) {
533 std::string expected_pattern =
534 "Unable to make a HEAD request to "
535 "\"https://127.0.0.1:\\d+/404.test/webpay\" for payment method manifest.";
Rouslan Solomakhinde012532017-09-20 15:18:34536 {
537 content::PaymentAppProvider::PaymentApps apps;
538 apps[0] = std::make_unique<content::StoredPaymentApp>();
Rouslan Solomakhind5dcc322019-07-11 21:47:20539 apps[0]->scope = GURL("https://bobpay.test/webpay");
540 apps[0]->enabled_methods.push_back("https://404.test/webpay");
Rouslan Solomakhinde012532017-09-20 15:18:34541
542 Verify(std::move(apps));
543
544 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20545 EXPECT_TRUE(RE2::FullMatch(error_message(), expected_pattern))
546 << "Actual error message \"" << error_message()
547 << "\" did not match expected pattern \"" << expected_pattern << "\".";
Rouslan Solomakhinde012532017-09-20 15:18:34548 }
549
550 // Repeat verifications should have identical results.
551 {
552 content::PaymentAppProvider::PaymentApps apps;
553 apps[0] = std::make_unique<content::StoredPaymentApp>();
Rouslan Solomakhind5dcc322019-07-11 21:47:20554 apps[0]->scope = GURL("https://bobpay.test/webpay");
555 apps[0]->enabled_methods.push_back("https://404.test/webpay");
Rouslan Solomakhinde012532017-09-20 15:18:34556
557 Verify(std::move(apps));
558
559 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20560 EXPECT_TRUE(RE2::FullMatch(error_message(), expected_pattern))
561 << "Actual error message \"" << error_message()
562 << "\" did not match expected pattern \"" << expected_pattern << "\".";
563 }
564}
565
566// Verify that a payment handler from https://bobpay.com/webpay cannot use
567// payment method names that are unreachable websites, the origin of which does
568// not match that of the payment handler. Since multiple downloads fail, the
569// error message will describe the first failure.
570IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
571 MultiplePaymentMethodName404) {
572 std::string expected_pattern =
573 "Unable to make a HEAD request to "
574 "\"https://127.0.0.1:\\d+/404(aswell)?.test/webpay\" for payment method "
575 "manifest.";
576 {
577 content::PaymentAppProvider::PaymentApps apps;
578 apps[0] = std::make_unique<content::StoredPaymentApp>();
579 apps[0]->scope = GURL("https://bobpay.test/webpay");
580 apps[0]->enabled_methods.push_back("https://404.test/webpay");
581 apps[0]->enabled_methods.push_back("https://404aswell.test/webpay");
582
583 Verify(std::move(apps));
584
585 EXPECT_TRUE(verified_apps().empty());
586 EXPECT_TRUE(RE2::FullMatch(error_message(), expected_pattern))
587 << "Actual error message \"" << error_message()
588 << "\" did not match expected pattern \"" << expected_pattern << "\".";
589 }
590
591 // Repeat verifications should have identical results.
592 {
593 content::PaymentAppProvider::PaymentApps apps;
594 apps[0] = std::make_unique<content::StoredPaymentApp>();
595 apps[0]->scope = GURL("https://bobpay.test/webpay");
596 apps[0]->enabled_methods.push_back("https://404.test/webpay");
597 apps[0]->enabled_methods.push_back("https://404aswell.test/webpay");
598
599 Verify(std::move(apps));
600
601 EXPECT_TRUE(verified_apps().empty());
602 EXPECT_TRUE(RE2::FullMatch(error_message(), expected_pattern))
603 << "Actual error message \"" << error_message()
604 << "\" did not match expected pattern \"" << expected_pattern << "\".";
Rouslan Solomakhinde012532017-09-20 15:18:34605 }
606}
607
Rouslan Solomakhin478d93e32017-10-27 17:06:37608// All known payment method names are valid.
609IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
610 AllKnownPaymentMethodNames) {
611 {
612 content::PaymentAppProvider::PaymentApps apps;
613 apps[0] = std::make_unique<content::StoredPaymentApp>();
614 apps[0]->scope = GURL("https://bobpay.com/webpay");
615 apps[0]->enabled_methods.push_back("basic-card");
616 apps[0]->enabled_methods.push_back("interledger");
617 apps[0]->enabled_methods.push_back("payee-credit-transfer");
618 apps[0]->enabled_methods.push_back("payer-credit-transfer");
Rouslan Solomakhin901a1842018-07-30 22:25:37619 apps[0]->enabled_methods.push_back("tokenized-card");
Rouslan Solomakhin478d93e32017-10-27 17:06:37620 apps[0]->enabled_methods.push_back("not-supported");
621
622 Verify(std::move(apps));
623
624 EXPECT_EQ(1U, verified_apps().size());
625 ExpectApp(0, "https://bobpay.com/webpay",
626 {"basic-card", "interledger", "payee-credit-transfer",
Rouslan Solomakhin901a1842018-07-30 22:25:37627 "payer-credit-transfer", "tokenized-card"},
gogeralda74f9dec2018-04-10 00:33:47628 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20629 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhin478d93e32017-10-27 17:06:37630 }
631
632 // Repeat verifications should have identical results.
633 {
634 content::PaymentAppProvider::PaymentApps apps;
635 apps[0] = std::make_unique<content::StoredPaymentApp>();
636 apps[0]->scope = GURL("https://bobpay.com/webpay");
637 apps[0]->enabled_methods.push_back("basic-card");
638 apps[0]->enabled_methods.push_back("interledger");
639 apps[0]->enabled_methods.push_back("payee-credit-transfer");
640 apps[0]->enabled_methods.push_back("payer-credit-transfer");
Rouslan Solomakhin901a1842018-07-30 22:25:37641 apps[0]->enabled_methods.push_back("tokenized-card");
Rouslan Solomakhin478d93e32017-10-27 17:06:37642 apps[0]->enabled_methods.push_back("not-supported");
643
644 Verify(std::move(apps));
645
646 EXPECT_EQ(1U, verified_apps().size());
647 ExpectApp(0, "https://bobpay.com/webpay",
648 {"basic-card", "interledger", "payee-credit-transfer",
Rouslan Solomakhin901a1842018-07-30 22:25:37649 "payer-credit-transfer", "tokenized-card"},
gogeralda74f9dec2018-04-10 00:33:47650 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20651 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhin478d93e32017-10-27 17:06:37652 }
653}
654
Rouslan Solomakhinde012532017-09-20 15:18:34655} // namespace
656} // namespace payments