Home | History | Annotate | Download | only in wallet
      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
      3 // found in the LICENSE file.
      4 
      5 #include "base/command_line.h"
      6 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
      7 #include "components/autofill/core/common/autofill_switches.h"
      8 #include "content/public/common/content_switches.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 #include "url/gurl.h"
     11 
     12 namespace autofill {
     13 namespace wallet {
     14 
     15 TEST(WalletServiceSandboxUrl, CheckSandboxUrls) {
     16   CommandLine::ForCurrentProcess()->AppendSwitchASCII(
     17       switches::kWalletServiceUseSandbox, "1");
     18 
     19   EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
     20             "autocheckout/v1/getWalletItemsJwtless",
     21            GetGetWalletItemsUrl(1).spec());
     22   EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/1/"
     23             "autocheckout/v1/getFullWalletJwtless?s7e=otp",
     24             GetGetFullWalletUrl(1).spec());
     25   EXPECT_EQ("https://wallet-web.sandbox.google.com/manage/w/1/paymentMethods",
     26             GetManageInstrumentsUrl(1).spec());
     27   EXPECT_EQ("https://wallet-web.sandbox.google.com/manage/w/1/settings/"
     28             "addresses",
     29             GetManageAddressesUrl(1).spec());
     30   EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
     31             "autocheckout/v1/acceptLegalDocument",
     32             GetAcceptLegalDocumentsUrl(1).spec());
     33   EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/2/"
     34             "autocheckout/v1/authenticateInstrument?s7e=cvn",
     35             GetAuthenticateInstrumentUrl(2).spec());
     36   EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
     37             "autocheckout/v1/reportStatus",
     38             GetSendStatusUrl(1).spec());
     39   EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
     40             "autocheckout/v1/saveToWallet",
     41             GetSaveToWalletNoEscrowUrl(1).spec());
     42   EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/1/"
     43             "autocheckout/v1/saveToWallet?s7e=card_number%3Bcvn",
     44             GetSaveToWalletUrl(1).spec());
     45   EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/"
     46             "passiveauth?isChromePayments=true",
     47             GetPassiveAuthUrl(1).spec());
     48 }
     49 
     50 TEST(WalletServiceSandboxUrl, CheckProdUrls) {
     51   CommandLine::ForCurrentProcess()->AppendSwitchASCII(
     52       switches::kWalletServiceUseSandbox, "0");
     53 
     54   EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
     55             "autocheckout/v1/getWalletItemsJwtless",
     56             GetGetWalletItemsUrl(1).spec());
     57   EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/1/"
     58             "autocheckout/v1/getFullWalletJwtless?s7e=otp",
     59             GetGetFullWalletUrl(1).spec());
     60   EXPECT_EQ("https://wallet.google.com/manage/w/1/paymentMethods",
     61             GetManageInstrumentsUrl(1).spec());
     62   EXPECT_EQ("https://wallet.google.com/manage/w/1/settings/addresses",
     63             GetManageAddressesUrl(1).spec());
     64   EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
     65             "autocheckout/v1/acceptLegalDocument",
     66             GetAcceptLegalDocumentsUrl(1).spec());
     67   EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/4/"
     68             "autocheckout/v1/authenticateInstrument?s7e=cvn",
     69             GetAuthenticateInstrumentUrl(4).spec());
     70   EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
     71             "autocheckout/v1/reportStatus",
     72             GetSendStatusUrl(1).spec());
     73   EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
     74             "autocheckout/v1/saveToWallet",
     75             GetSaveToWalletNoEscrowUrl(1).spec());
     76   EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/1/"
     77             "autocheckout/v1/saveToWallet?s7e=card_number%3Bcvn",
     78             GetSaveToWalletUrl(1).spec());
     79   EXPECT_EQ("https://wallet.google.com/online/v2/u/1/"
     80             "passiveauth?isChromePayments=true",
     81             GetPassiveAuthUrl(1).spec());
     82 }
     83 
     84 TEST(WalletServiceUrl, DefaultsToProd) {
     85 #if defined(GOOGLE_CHROME_BUILD)
     86   EXPECT_TRUE(IsUsingProd());
     87 #else
     88   EXPECT_FALSE(IsUsingProd());
     89 #endif
     90 
     91   CommandLine* command_line = CommandLine::ForCurrentProcess();
     92   command_line->AppendSwitch(::switches::kReduceSecurityForTesting);
     93   EXPECT_FALSE(IsUsingProd());
     94 
     95   command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "0");
     96   EXPECT_TRUE(IsUsingProd());
     97 }
     98 
     99 TEST(WalletServiceUrl, IsUsingProd) {
    100   CommandLine* command_line = CommandLine::ForCurrentProcess();
    101   command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "1");
    102   EXPECT_FALSE(IsUsingProd());
    103 
    104   const GURL sandbox_get_items_url = GetGetWalletItemsUrl(0);
    105   const GURL fake_service_url = GURL("http://goo.gl");
    106   command_line->AppendSwitchASCII(switches::kWalletServiceUrl,
    107                                   fake_service_url.spec());
    108 
    109   const GURL flag_get_items_url = GetGetWalletItemsUrl(0);
    110   EXPECT_NE(sandbox_get_items_url, flag_get_items_url);
    111   EXPECT_EQ(fake_service_url.GetOrigin(), flag_get_items_url.GetOrigin());
    112 }
    113 
    114 TEST(WalletServiceUrl, IsSignInContinueUrl) {
    115   EXPECT_TRUE(GetSignInContinueUrl().SchemeIsSecure());
    116 
    117   CommandLine* command_line = CommandLine::ForCurrentProcess();
    118   command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "1");
    119 
    120   // authuser query param is respected.
    121   const char sign_in_url[] = "https://wallet-web.sandbox.google.com/online/v2/"
    122       "u/0/passiveauth?isChromePayments=true&authuser=4";
    123   size_t user_index = 100;
    124   EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url), &user_index));
    125   EXPECT_EQ(4U, user_index);
    126 
    127   // No authuser query param means 0 is assumed.
    128   user_index = 101;
    129   const char sign_in_url_no_user[] = "https://wallet-web.sandbox.google.com/"
    130       "online/v2/u/0/passiveauth?isChromePayments=true";
    131   EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url_no_user), &user_index));
    132   EXPECT_EQ(0U, user_index);
    133 
    134   // A authuser query param that doesn't parse means 0 is assumed.
    135   user_index = 102;
    136   const char sign_in_url_bad_user[] = "https://wallet-web.sandbox.google.com/"
    137       "online/v2/u/0/passiveauth?isChromePayments=true&authuser=yolo";
    138   EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url_bad_user), &user_index));
    139   EXPECT_EQ(0U, user_index);
    140 
    141   const char not_a_sign_in_url[] = "https://wallet-web.sandbox.google.com/"
    142       "online/v2/u/0/example";
    143   EXPECT_FALSE(IsSignInContinueUrl(GURL(not_a_sign_in_url), &user_index));
    144 }
    145 
    146 TEST(WalletServiceUrl, IsSignInRelatedUrl) {
    147   EXPECT_TRUE(IsSignInRelatedUrl(GetSignInUrl()));
    148   EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.youtube.com")));
    149   EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.youtube.com/")));
    150   EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.google.com")));
    151   EXPECT_FALSE(IsSignInRelatedUrl(GURL("http://google.com")));
    152 }
    153 
    154 }  // namespace wallet
    155 }  // namespace autofill
    156