tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

payment-request-ctor-pmi-handling.https.sub.html (4550B)


      1 <!DOCTYPE html>
      2 <!-- Copyright © 2017 Mozilla and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
      3 <meta charset="utf-8">
      4 <title>Test for validity of payment method identifiers during construction</title>
      5 <link rel="help" href="https://w3c.github.io/browser-payment-api/#constructor">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script>
      9 "use strict";
     10 const validAmount = Object.freeze({
     11  currency: "USD",
     12  value: "1.0",
     13 });
     14 const validTotal = Object.freeze({
     15  label: "Default Total",
     16  amount: validAmount,
     17 });
     18 const defaultDetails = Object.freeze({
     19  total: validTotal,
     20 });
     21 
     22 test(() => {
     23  const validMethods = [
     24    "https://wpt",
     25    "https://{{domains[nonexistent]}}/",
     26    "https://{{domains[nonexistent]}}/payment",
     27    "https://{{domains[nonexistent]}}/payment-request",
     28    "https://{{domains[nonexistent]}}/payment-request?",
     29    "https://{{domains[nonexistent]}}/payment-request?this=is",
     30    "https://{{domains[nonexistent]}}/payment-request?this=is&totally",
     31    "https://{{domains[nonexistent]}}:443/payment-request?this=is&totally",
     32    "https://{{domains[nonexistent]}}:443/payment-request?this=is&totally#fine",
     33    "https://:@{{domains[nonexistent]}}:443/payment-request?this=is&totally#👍",
     34    " \thttps://wpt\n ",
     35    "https://xn--c1yn36f",
     36    "https://點看",
     37  ];
     38  for (const validMethod of validMethods) {
     39    try {
     40      const methods = [{ supportedMethods: validMethod }];
     41      new PaymentRequest(methods, defaultDetails);
     42    } catch (err) {
     43      assert_unreached(
     44        `Unexpected exception with valid standardized PMI: ${validMethod}. ${err}`
     45      );
     46    }
     47  }
     48 }, "Must support valid standard URL PMIs");
     49 
     50 test(() => {
     51  const validMethods = [
     52    "e",
     53    "n6jzof05mk2g4lhxr-u-q-w1-c-i-pa-ty-bdvs9-ho-ae7-p-md8-s-wq3-h-qd-e-q-sa",
     54    "a-b-q-n-s-pw0",
     55    "m-u",
     56    "s-l5",
     57    "k9-f",
     58    "m-l",
     59    "u4-n-t",
     60    "i488jh6-g18-fck-yb-v7-i",
     61    "x-x-t-t-c34-o",
     62    "secure-payment-confirmation",
     63    // gets coerced to "secure-payment-confirmation", for compat with old version of spec
     64    ["secure-payment-confirmation"],
     65  ];
     66  for (const validMethod of validMethods) {
     67    try {
     68      const methods = [{ supportedMethods: validMethod }];
     69      new PaymentRequest(methods, defaultDetails);
     70    } catch (err) {
     71      assert_unreached(
     72        `Unexpected exception with valid standardized PMI: ${validMethod}. ${err}`
     73      );
     74    }
     75  }
     76 }, "Must not throw on syntactically valid standardized payment method identifiers, even if they are not supported");
     77 
     78 test(() => {
     79  const invalidMethods = [
     80    "secure-💳",
     81    "¡secure-*-payment-confirmation!",
     82    "Secure-Payment-Confirmation",
     83    "0",
     84    "-",
     85    "--",
     86    "a--b",
     87    "-a--b",
     88    "a-b-",
     89    "0-",
     90    "0-a",
     91    "a0--",
     92    "A-",
     93    "A-B",
     94    "A-b",
     95    "a-0",
     96    "a-0b",
     97    " a-b",
     98    "\t\na-b",
     99    "a-b ",
    100    "a-b\n\t",
    101    "secure-payment-confirmation?not-really",
    102    "secure-payment-confirmation://not-ok",
    103    "secure payment confirmation",
    104    "/secure payment confirmation/",
    105    "SeCuRePaYmEnTcOnFiRmAtIoN",
    106    "SECURE-PAYMENT-CONFIRMATION",
    107    " secure-payment-confirmation ",
    108    "this is not supported",
    109    " ",
    110    "foo,var",
    111    ["visa","mastercard"], // stringifies to "visa,mastercard"
    112  ];
    113  for (const invalidMethod of invalidMethods) {
    114    assert_throws_js(
    115      RangeError,
    116      () => {
    117        const methods = [{ supportedMethods: invalidMethod }];
    118        new PaymentRequest(methods, defaultDetails);
    119      },
    120      `expected RangeError processing invalid standardized PMI "${invalidMethod}"`
    121    );
    122  }
    123 }, "Must throw on syntactically invalid standardized payment method identifiers");
    124 
    125 test(() => {
    126  const invalidMethods = [
    127    "https://username@example.com/pay",
    128    "https://:password@example.com/pay",
    129    "https://username:password@example.com/pay",
    130    "http://username:password@example.com/pay",
    131    "http://foo.com:100000000/pay",
    132    "not-https://{{domains[nonexistent]}}/payment-request",
    133    "../realitive/url",
    134    "/absolute/../path?",
    135    "https://",
    136  ];
    137  for (const invalidMethod of invalidMethods) {
    138    assert_throws_js(
    139      RangeError,
    140      () => {
    141        const methods = [{ supportedMethods: invalidMethod }];
    142        new PaymentRequest(methods, defaultDetails);
    143      },
    144      `expected RangeError processing invalid URL PMI "${invalidMethod}"`
    145    );
    146  }
    147 }, "Constructor MUST throw if given an invalid URL-based payment method identifier");
    148 
    149 </script>