blob: 98c1c9483688a63a3403d40e203e7a7f10b9851e [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 Solomakhinc71cca622020-01-31 22:15:3526#include "url/origin.h"
Rouslan Solomakhinde012532017-09-20 15:18:3427
28namespace payments {
29namespace {
30
Rouslan Solomakhinde012532017-09-20 15:18:3431// Tests for the manifest verifier.
32class ManifestVerifierBrowserTest : public InProcessBrowserTest {
33 public:
34 ManifestVerifierBrowserTest() {}
35 ~ManifestVerifierBrowserTest() override {}
36
37 // Starts the HTTPS test server on localhost.
38 void SetUpOnMainThread() override {
39 https_server_ = std::make_unique<net::EmbeddedTestServer>(
40 net::EmbeddedTestServer::TYPE_HTTPS);
41 ASSERT_TRUE(https_server_->InitializeAndListen());
42 https_server_->ServeFilesFromSourceDirectory(
43 "components/test/data/payments");
44 https_server_->StartAcceptingConnections();
45 }
46
47 // Runs the verifier on the |apps| and blocks until the verifier has finished
48 // using all resources.
49 void Verify(content::PaymentAppProvider::PaymentApps apps) {
Rouslan Solomakhindbf593d92017-11-21 19:20:5750 content::WebContents* web_contents =
51 browser()->tab_strip_model()->GetActiveWebContents();
52 content::BrowserContext* context = web_contents->GetBrowserContext();
Rouslan Solomakhinde012532017-09-20 15:18:3453 auto downloader = std::make_unique<TestDownloader>(
Rouslan Solomakhin438d8c92017-10-26 21:33:1854 content::BrowserContext::GetDefaultStoragePartition(context)
John Abd-El-Malekaef36cb2018-06-26 17:18:2355 ->GetURLLoaderFactoryForBrowserProcess());
Rouslan Solomakhin438d8c92017-10-26 21:33:1856 downloader->AddTestServerURL("https://", https_server_->GetURL("/"));
Rouslan Solomakhine2537212018-11-14 17:07:2957 auto parser = std::make_unique<payments::PaymentManifestParser>(
58 std::make_unique<ErrorLogger>());
gogerald84ae6262018-02-06 06:21:4659 auto cache = WebDataServiceFactory::GetPaymentManifestWebDataForProfile(
60 Profile::FromBrowserContext(context),
61 ServiceAccessType::EXPLICIT_ACCESS);
Rouslan Solomakhinde012532017-09-20 15:18:3462
Rouslan Solomakhinc71cca622020-01-31 22:15:3563 ManifestVerifier verifier(url::Origin::Create(GURL("https://chromium.org")),
64 web_contents, downloader.get(), parser.get(),
gogerald84ae6262018-02-06 06:21:4665 cache.get());
Rouslan Solomakhinde012532017-09-20 15:18:3466
67 base::RunLoop run_loop;
Rouslan Solomakhinde012532017-09-20 15:18:3468 verifier.Verify(
69 std::move(apps),
70 base::BindOnce(&ManifestVerifierBrowserTest::OnPaymentAppsVerified,
71 base::Unretained(this)),
Rouslan Solomakhin438d8c92017-10-26 21:33:1872 run_loop.QuitClosure());
Rouslan Solomakhinde012532017-09-20 15:18:3473 run_loop.Run();
74 }
75
76 // Returns the apps that have been verified by the Verify() method.
77 const content::PaymentAppProvider::PaymentApps& verified_apps() const {
78 return verified_apps_;
79 }
80
Rouslan Solomakhind5dcc322019-07-11 21:47:2081 const std::string& error_message() const { return error_message_; }
82
Rouslan Solomakhinde012532017-09-20 15:18:3483 // Expects that the verified payment app with |id| has the |expected_scope|
gogeralda74f9dec2018-04-10 00:33:4784 // and the |expected_methods| and the
85 // |expect_has_explicitly_verified_methods|.
Rouslan Solomakhinde012532017-09-20 15:18:3486 void ExpectApp(int64_t id,
87 const std::string& expected_scope,
gogeralda74f9dec2018-04-10 00:33:4788 const std::set<std::string>& expected_methods,
89 bool expect_has_explicitly_verified_methods) {
Rouslan Solomakhin478d93e32017-10-27 17:06:3790 const auto& it = verified_apps().find(id);
91 ASSERT_NE(verified_apps().end(), it);
92 EXPECT_EQ(GURL(expected_scope), it->second->scope);
93 std::set<std::string> actual_methods(it->second->enabled_methods.begin(),
94 it->second->enabled_methods.end());
Rouslan Solomakhinde012532017-09-20 15:18:3495 EXPECT_EQ(expected_methods, actual_methods);
gogeralda74f9dec2018-04-10 00:33:4796 EXPECT_EQ(expect_has_explicitly_verified_methods,
97 it->second->has_explicitly_verified_methods);
Rouslan Solomakhind5dcc322019-07-11 21:47:2098 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:3499 }
100
101 private:
102 // Called by the verifier upon completed verification. These |apps| have only
103 // valid payment methods.
Rouslan Solomakhind5dcc322019-07-11 21:47:20104 void OnPaymentAppsVerified(content::PaymentAppProvider::PaymentApps apps,
105 const std::string& error_message) {
Rouslan Solomakhinde012532017-09-20 15:18:34106 verified_apps_ = std::move(apps);
Rouslan Solomakhind5dcc322019-07-11 21:47:20107 error_message_ = error_message;
Rouslan Solomakhinde012532017-09-20 15:18:34108 }
109
Rouslan Solomakhinde012532017-09-20 15:18:34110 // Serves the payment method manifest files.
111 std::unique_ptr<net::EmbeddedTestServer> https_server_;
112
113 // The apps that have been verified by the Verify() method.
114 content::PaymentAppProvider::PaymentApps verified_apps_;
115
Rouslan Solomakhind5dcc322019-07-11 21:47:20116 std::string error_message_;
117
Rouslan Solomakhinde012532017-09-20 15:18:34118 DISALLOW_COPY_AND_ASSIGN(ManifestVerifierBrowserTest);
119};
120
121// Absence of payment handlers should result in absence of verified payment
122// handlers.
123IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoApps) {
124 {
125 Verify(content::PaymentAppProvider::PaymentApps());
126
127 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20128 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34129 }
130
131 // Repeat verifications should have identical results.
132 {
133 Verify(content::PaymentAppProvider::PaymentApps());
134
135 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20136 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34137 }
138}
139
140// A payment handler without any payment method names is not valid.
141IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, NoMethods) {
142 {
143 content::PaymentAppProvider::PaymentApps apps;
144 apps[0] = std::make_unique<content::StoredPaymentApp>();
145 apps[0]->scope = GURL("https://bobpay.com/webpay");
146
147 Verify(std::move(apps));
148
149 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20150 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34151 }
152
153 // Repeat verifications should have identical results.
154 {
155 content::PaymentAppProvider::PaymentApps apps;
156 apps[0] = std::make_unique<content::StoredPaymentApp>();
157 apps[0]->scope = GURL("https://bobpay.com/webpay");
158
159 Verify(std::move(apps));
160
161 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20162 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34163 }
164}
165
166// A payment handler with an unknown non-URL payment method name is not valid.
167IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
168 UnknownPaymentMethodNameIsRemoved) {
169 {
170 content::PaymentAppProvider::PaymentApps apps;
171 apps[0] = std::make_unique<content::StoredPaymentApp>();
172 apps[0]->scope = GURL("https://bobpay.com/webpay");
173 apps[0]->enabled_methods.push_back("unknown");
174
175 Verify(std::move(apps));
176
177 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20178 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34179 }
180
181 // Repeat verifications should have identical results.
182 {
183 content::PaymentAppProvider::PaymentApps apps;
184 apps[0] = std::make_unique<content::StoredPaymentApp>();
185 apps[0]->scope = GURL("https://bobpay.com/webpay");
186 apps[0]->enabled_methods.push_back("unknown");
187
188 Verify(std::move(apps));
189
190 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20191 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34192 }
193}
194
195// A payment handler with "basic-card" payment method name is valid.
196IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, KnownPaymentMethodName) {
197 {
198 content::PaymentAppProvider::PaymentApps apps;
199 apps[0] = std::make_unique<content::StoredPaymentApp>();
200 apps[0]->scope = GURL("https://bobpay.com/webpay");
201 apps[0]->enabled_methods.push_back("basic-card");
202
203 Verify(std::move(apps));
204
205 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47206 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20207 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34208 }
209
210 // Repeat verifications should have identical results.
211 {
212 content::PaymentAppProvider::PaymentApps apps;
213 apps[0] = std::make_unique<content::StoredPaymentApp>();
214 apps[0]->scope = GURL("https://bobpay.com/webpay");
215 apps[0]->enabled_methods.push_back("basic-card");
216
217 Verify(std::move(apps));
218
219 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47220 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20221 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34222 }
223}
224
225// A payment handler with both "basic-card" and "interledger" payment method
226// names is valid.
227IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
228 TwoKnownPaymentMethodNames) {
229 {
230 content::PaymentAppProvider::PaymentApps apps;
231 apps[0] = std::make_unique<content::StoredPaymentApp>();
232 apps[0]->scope = GURL("https://bobpay.com/webpay");
233 apps[0]->enabled_methods.push_back("basic-card");
234 apps[0]->enabled_methods.push_back("interledger");
235
236 Verify(std::move(apps));
237
238 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47239 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"},
240 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20241 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34242 }
243
244 // Repeat verifications should have identical results.
245 {
246 content::PaymentAppProvider::PaymentApps apps;
247 apps[0] = std::make_unique<content::StoredPaymentApp>();
248 apps[0]->scope = GURL("https://bobpay.com/webpay");
249 apps[0]->enabled_methods.push_back("basic-card");
250 apps[0]->enabled_methods.push_back("interledger");
251
252 Verify(std::move(apps));
253
254 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47255 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card", "interledger"},
256 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20257 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34258 }
259}
260
261// Two payment handlers with "basic-card" payment method names are both valid.
262IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
263 TwoAppsWithKnownPaymentMethodNames) {
264 {
265 content::PaymentAppProvider::PaymentApps apps;
266 apps[0] = std::make_unique<content::StoredPaymentApp>();
267 apps[0]->scope = GURL("https://bobpay.com/webpay");
268 apps[0]->enabled_methods.push_back("basic-card");
269 apps[1] = std::make_unique<content::StoredPaymentApp>();
270 apps[1]->scope = GURL("https://alicepay.com/webpay");
271 apps[1]->enabled_methods.push_back("basic-card");
272
273 Verify(std::move(apps));
274
275 EXPECT_EQ(2U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47276 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
277 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20278 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34279 }
280
281 // Repeat verifications should have identical results.
282 {
283 content::PaymentAppProvider::PaymentApps apps;
284 apps[0] = std::make_unique<content::StoredPaymentApp>();
285 apps[0]->scope = GURL("https://bobpay.com/webpay");
286 apps[0]->enabled_methods.push_back("basic-card");
287 apps[1] = std::make_unique<content::StoredPaymentApp>();
288 apps[1]->scope = GURL("https://alicepay.com/webpay");
289 apps[1]->enabled_methods.push_back("basic-card");
290 Verify(std::move(apps));
291
292 EXPECT_EQ(2U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47293 ExpectApp(0, "https://bobpay.com/webpay", {"basic-card"}, false);
294 ExpectApp(1, "https://alicepay.com/webpay", {"basic-card"}, false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20295 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34296 }
297}
298
299// Verify that a payment handler from https://bobpay.com/webpay can use the
300// payment method name https://frankpay.com/webpay, because
301// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
302IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
303 BobPayHandlerCanUseMethodThatSupportsAllOrigins) {
304 {
305 content::PaymentAppProvider::PaymentApps apps;
306 apps[0] = std::make_unique<content::StoredPaymentApp>();
307 apps[0]->scope = GURL("https://bobpay.com/webpay");
308 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
309
310 Verify(std::move(apps));
311
312 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47313 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"},
314 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20315 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34316 }
317
318 // Repeat verifications should have identical results.
319 {
320 content::PaymentAppProvider::PaymentApps apps;
321 apps[0] = std::make_unique<content::StoredPaymentApp>();
322 apps[0]->scope = GURL("https://bobpay.com/webpay");
323 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
324 Verify(std::move(apps));
325
326 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47327 ExpectApp(0, "https://bobpay.com/webpay", {"https://frankpay.com/webpay"},
328 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20329 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34330 }
331}
332
333// Verify that a payment handler from an unreachable website can use the payment
334// method name https://frankpay.com/webpay, because
335// https://frankpay.com/payment-manifest.json contains "supported_origins": "*".
336IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
337 Handler404CanUseMethodThatSupportsAllOrigins) {
338 {
339 content::PaymentAppProvider::PaymentApps apps;
340 apps[0] = std::make_unique<content::StoredPaymentApp>();
341 apps[0]->scope = GURL("https://404.com/webpay");
342 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
343
344 Verify(std::move(apps));
345
346 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47347 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"},
348 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20349 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34350 }
351
352 // Repeat verifications should have identical results.
353 {
354 content::PaymentAppProvider::PaymentApps apps;
355 apps[0] = std::make_unique<content::StoredPaymentApp>();
356 apps[0]->scope = GURL("https://404.com/webpay");
357 apps[0]->enabled_methods.push_back("https://frankpay.com/webpay");
358 Verify(std::move(apps));
359
360 EXPECT_EQ(1U, verified_apps().size());
gogeralda74f9dec2018-04-10 00:33:47361 ExpectApp(0, "https://404.com/webpay", {"https://frankpay.com/webpay"},
362 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20363 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34364 }
365}
366
367// Verify that a payment handler from anywhere on https://bobpay.com can use the
368// payment method name from anywhere else on https://bobpay.com, because of the
369// origin match.
370IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
371 BobPayCanUseAnyMethodOnOwnOrigin) {
372 {
373 content::PaymentAppProvider::PaymentApps apps;
374 apps[0] = std::make_unique<content::StoredPaymentApp>();
375 apps[0]->scope = GURL("https://bobpay.com/anything/here");
376 apps[0]->enabled_methods.push_back(
377 "https://bobpay.com/does/not/matter/whats/here");
378
379 Verify(std::move(apps));
380
381 EXPECT_EQ(1U, verified_apps().size());
382 ExpectApp(0, "https://bobpay.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47383 {"https://bobpay.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20384 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34385 }
386
387 // Repeat verifications should have identical results.
388 {
389 content::PaymentAppProvider::PaymentApps apps;
390 apps[0] = std::make_unique<content::StoredPaymentApp>();
391 apps[0]->scope = GURL("https://bobpay.com/anything/here");
392 apps[0]->enabled_methods.push_back(
393 "https://bobpay.com/does/not/matter/whats/here");
394 Verify(std::move(apps));
395
396 EXPECT_EQ(1U, verified_apps().size());
397 ExpectApp(0, "https://bobpay.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47398 {"https://bobpay.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20399 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34400 }
401}
402
403// Verify that a payment handler from anywhere on an unreachable website can use
404// the payment method name from anywhere else on the same unreachable website,
405// because they have identical origin.
406IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
407 Handler404CanUseAnyMethodOnOwnOrigin) {
408 {
409 content::PaymentAppProvider::PaymentApps apps;
410 apps[0] = std::make_unique<content::StoredPaymentApp>();
411 apps[0]->scope = GURL("https://404.com/anything/here");
412 apps[0]->enabled_methods.push_back(
413 "https://404.com/does/not/matter/whats/here");
414
415 Verify(std::move(apps));
416
417 EXPECT_EQ(1U, verified_apps().size());
418 ExpectApp(0, "https://404.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47419 {"https://404.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20420 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34421 }
422
423 // Repeat verifications should have identical results.
424 {
425 content::PaymentAppProvider::PaymentApps apps;
426 apps[0] = std::make_unique<content::StoredPaymentApp>();
427 apps[0]->scope = GURL("https://404.com/anything/here");
428 apps[0]->enabled_methods.push_back(
429 "https://404.com/does/not/matter/whats/here");
430 Verify(std::move(apps));
431
432 EXPECT_EQ(1U, verified_apps().size());
433 ExpectApp(0, "https://404.com/anything/here",
gogeralda74f9dec2018-04-10 00:33:47434 {"https://404.com/does/not/matter/whats/here"}, true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20435 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34436 }
437}
438
439// Verify that only the payment handler from https://alicepay.com/webpay can use
440// payment methods https://georgepay.com/webpay and https://ikepay.com/webpay,
441// because both https://georgepay.com/payment-manifest.json and
442// https://ikepay.com/payment-manifest.json contain "supported_origins":
443// ["https://alicepay.com"]. The payment handler from https://bobpay.com/webpay
444// cannot use these payment methods, however.
445IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, OneSupportedOrigin) {
446 {
447 content::PaymentAppProvider::PaymentApps apps;
448 apps[0] = std::make_unique<content::StoredPaymentApp>();
449 apps[0]->scope = GURL("https://alicepay.com/webpay");
450 apps[0]->enabled_methods.push_back("https://georgepay.com/webpay");
451 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
452 apps[1] = std::make_unique<content::StoredPaymentApp>();
453 apps[1]->scope = GURL("https://bobpay.com/webpay");
454 apps[1]->enabled_methods.push_back("https://georgepay.com/webpay");
455 apps[1]->enabled_methods.push_back("https://ikepay.com/webpay");
456
457 Verify(std::move(apps));
458
459 EXPECT_EQ(1U, verified_apps().size());
460 ExpectApp(0, "https://alicepay.com/webpay",
gogeralda74f9dec2018-04-10 00:33:47461 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"},
462 true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20463 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34464 }
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",
gogeralda74f9dec2018-04-10 00:33:47482 {"https://georgepay.com/webpay", "https://ikepay.com/webpay"},
483 true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20484 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34485 }
486}
487
488// Verify that a payment handler from https://alicepay.com/webpay can use all
489// three of non-URL payment method name, same-origin URL payment method name,
490// and different-origin URL payment method name.
491IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest, ThreeTypesOfMethods) {
492 {
493 content::PaymentAppProvider::PaymentApps apps;
494 apps[0] = std::make_unique<content::StoredPaymentApp>();
495 apps[0]->scope = GURL("https://alicepay.com/webpay");
496 apps[0]->enabled_methods.push_back("basic-card");
497 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
498 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
499
500 Verify(std::move(apps));
501
502 EXPECT_EQ(1U, verified_apps().size());
503 ExpectApp(0, "https://alicepay.com/webpay",
504 {"basic-card", "https://alicepay.com/webpay2",
gogeralda74f9dec2018-04-10 00:33:47505 "https://ikepay.com/webpay"},
506 true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20507 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34508 }
509
510 // Repeat verifications should have identical results.
511 {
512 content::PaymentAppProvider::PaymentApps apps;
513 apps[0] = std::make_unique<content::StoredPaymentApp>();
514 apps[0]->scope = GURL("https://alicepay.com/webpay");
515 apps[0]->enabled_methods.push_back("basic-card");
516 apps[0]->enabled_methods.push_back("https://alicepay.com/webpay2");
517 apps[0]->enabled_methods.push_back("https://ikepay.com/webpay");
518
519 Verify(std::move(apps));
520
521 EXPECT_EQ(1U, verified_apps().size());
522 ExpectApp(0, "https://alicepay.com/webpay",
523 {"basic-card", "https://alicepay.com/webpay2",
gogeralda74f9dec2018-04-10 00:33:47524 "https://ikepay.com/webpay"},
525 true);
Rouslan Solomakhind5dcc322019-07-11 21:47:20526 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhinde012532017-09-20 15:18:34527 }
528}
529
530// Verify that a payment handler from https://bobpay.com/webpay cannot use
531// payment method names that are unreachable websites, the origin of which does
532// not match that of the payment handler.
Rouslan Solomakhind5dcc322019-07-11 21:47:20533IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
534 SinglePaymentMethodName404) {
535 std::string expected_pattern =
536 "Unable to make a HEAD request to "
537 "\"https://127.0.0.1:\\d+/404.test/webpay\" for payment method manifest.";
Rouslan Solomakhinde012532017-09-20 15:18:34538 {
539 content::PaymentAppProvider::PaymentApps apps;
540 apps[0] = std::make_unique<content::StoredPaymentApp>();
Rouslan Solomakhind5dcc322019-07-11 21:47:20541 apps[0]->scope = GURL("https://bobpay.test/webpay");
542 apps[0]->enabled_methods.push_back("https://404.test/webpay");
Rouslan Solomakhinde012532017-09-20 15:18:34543
544 Verify(std::move(apps));
545
546 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20547 EXPECT_TRUE(RE2::FullMatch(error_message(), expected_pattern))
548 << "Actual error message \"" << error_message()
549 << "\" did not match expected pattern \"" << expected_pattern << "\".";
Rouslan Solomakhinde012532017-09-20 15:18:34550 }
551
552 // Repeat verifications should have identical results.
553 {
554 content::PaymentAppProvider::PaymentApps apps;
555 apps[0] = std::make_unique<content::StoredPaymentApp>();
Rouslan Solomakhind5dcc322019-07-11 21:47:20556 apps[0]->scope = GURL("https://bobpay.test/webpay");
557 apps[0]->enabled_methods.push_back("https://404.test/webpay");
Rouslan Solomakhinde012532017-09-20 15:18:34558
559 Verify(std::move(apps));
560
561 EXPECT_TRUE(verified_apps().empty());
Rouslan Solomakhind5dcc322019-07-11 21:47:20562 EXPECT_TRUE(RE2::FullMatch(error_message(), expected_pattern))
563 << "Actual error message \"" << error_message()
564 << "\" did not match expected pattern \"" << expected_pattern << "\".";
565 }
566}
567
568// Verify that a payment handler from https://bobpay.com/webpay cannot use
569// payment method names that are unreachable websites, the origin of which does
570// not match that of the payment handler. Since multiple downloads fail, the
571// error message will describe the first failure.
572IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
573 MultiplePaymentMethodName404) {
574 std::string expected_pattern =
575 "Unable to make a HEAD request to "
576 "\"https://127.0.0.1:\\d+/404(aswell)?.test/webpay\" for payment method "
577 "manifest.";
578 {
579 content::PaymentAppProvider::PaymentApps apps;
580 apps[0] = std::make_unique<content::StoredPaymentApp>();
581 apps[0]->scope = GURL("https://bobpay.test/webpay");
582 apps[0]->enabled_methods.push_back("https://404.test/webpay");
583 apps[0]->enabled_methods.push_back("https://404aswell.test/webpay");
584
585 Verify(std::move(apps));
586
587 EXPECT_TRUE(verified_apps().empty());
588 EXPECT_TRUE(RE2::FullMatch(error_message(), expected_pattern))
589 << "Actual error message \"" << error_message()
590 << "\" did not match expected pattern \"" << expected_pattern << "\".";
591 }
592
593 // Repeat verifications should have identical results.
594 {
595 content::PaymentAppProvider::PaymentApps apps;
596 apps[0] = std::make_unique<content::StoredPaymentApp>();
597 apps[0]->scope = GURL("https://bobpay.test/webpay");
598 apps[0]->enabled_methods.push_back("https://404.test/webpay");
599 apps[0]->enabled_methods.push_back("https://404aswell.test/webpay");
600
601 Verify(std::move(apps));
602
603 EXPECT_TRUE(verified_apps().empty());
604 EXPECT_TRUE(RE2::FullMatch(error_message(), expected_pattern))
605 << "Actual error message \"" << error_message()
606 << "\" did not match expected pattern \"" << expected_pattern << "\".";
Rouslan Solomakhinde012532017-09-20 15:18:34607 }
608}
609
Rouslan Solomakhin478d93e32017-10-27 17:06:37610// All known payment method names are valid.
611IN_PROC_BROWSER_TEST_F(ManifestVerifierBrowserTest,
612 AllKnownPaymentMethodNames) {
613 {
614 content::PaymentAppProvider::PaymentApps apps;
615 apps[0] = std::make_unique<content::StoredPaymentApp>();
616 apps[0]->scope = GURL("https://bobpay.com/webpay");
617 apps[0]->enabled_methods.push_back("basic-card");
618 apps[0]->enabled_methods.push_back("interledger");
619 apps[0]->enabled_methods.push_back("payee-credit-transfer");
620 apps[0]->enabled_methods.push_back("payer-credit-transfer");
Rouslan Solomakhin901a1842018-07-30 22:25:37621 apps[0]->enabled_methods.push_back("tokenized-card");
Rouslan Solomakhin478d93e32017-10-27 17:06:37622 apps[0]->enabled_methods.push_back("not-supported");
623
624 Verify(std::move(apps));
625
626 EXPECT_EQ(1U, verified_apps().size());
627 ExpectApp(0, "https://bobpay.com/webpay",
628 {"basic-card", "interledger", "payee-credit-transfer",
Rouslan Solomakhin901a1842018-07-30 22:25:37629 "payer-credit-transfer", "tokenized-card"},
gogeralda74f9dec2018-04-10 00:33:47630 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20631 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhin478d93e32017-10-27 17:06:37632 }
633
634 // Repeat verifications should have identical results.
635 {
636 content::PaymentAppProvider::PaymentApps apps;
637 apps[0] = std::make_unique<content::StoredPaymentApp>();
638 apps[0]->scope = GURL("https://bobpay.com/webpay");
639 apps[0]->enabled_methods.push_back("basic-card");
640 apps[0]->enabled_methods.push_back("interledger");
641 apps[0]->enabled_methods.push_back("payee-credit-transfer");
642 apps[0]->enabled_methods.push_back("payer-credit-transfer");
Rouslan Solomakhin901a1842018-07-30 22:25:37643 apps[0]->enabled_methods.push_back("tokenized-card");
Rouslan Solomakhin478d93e32017-10-27 17:06:37644 apps[0]->enabled_methods.push_back("not-supported");
645
646 Verify(std::move(apps));
647
648 EXPECT_EQ(1U, verified_apps().size());
649 ExpectApp(0, "https://bobpay.com/webpay",
650 {"basic-card", "interledger", "payee-credit-transfer",
Rouslan Solomakhin901a1842018-07-30 22:25:37651 "payer-credit-transfer", "tokenized-card"},
gogeralda74f9dec2018-04-10 00:33:47652 false);
Rouslan Solomakhind5dcc322019-07-11 21:47:20653 EXPECT_TRUE(error_message().empty()) << error_message();
Rouslan Solomakhin478d93e32017-10-27 17:06:37654 }
655}
656
Rouslan Solomakhinde012532017-09-20 15:18:34657} // namespace
658} // namespace payments