authentication-accepted.https.html (4209B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Test for the 'secure-payment-confirmation' payment method authentication - accepted case</title> 4 <link rel="help" href="https://w3c.github.io/secure-payment-confirmation#sctn-authentication"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <script src="utils.sub.js"></script> 10 <script> 11 'use strict'; 12 13 const kChallenge = 'server challenge'; 14 const kPayeeOrigin = 'https://merchant.com'; 15 const kInstrumentDisplayName = 'Troycard'; 16 17 async function triggerSpc(t, instrumentDetails, paymentEntitiesLogos) { 18 const authenticator = await window.test_driver.add_virtual_authenticator( 19 AUTHENTICATOR_OPTS); 20 t.add_cleanup(() => { 21 return window.test_driver.remove_virtual_authenticator(authenticator); 22 }); 23 24 await window.test_driver.set_spc_transaction_mode("autoAccept"); 25 t.add_cleanup(() => { 26 return window.test_driver.set_spc_transaction_mode("none"); 27 }); 28 29 const credential = await createCredential(); 30 31 let data = { 32 credentialIds: [credential.rawId], 33 challenge: Uint8Array.from(kChallenge, c => c.charCodeAt(0)), 34 payeeOrigin: kPayeeOrigin, 35 rpId: window.location.hostname, 36 timeout: 60000, 37 instrument: { 38 displayName: kInstrumentDisplayName, 39 icon: ICON_URL, 40 }, 41 }; 42 43 if (instrumentDetails !== undefined) { 44 data.instrument.details = instrumentDetails; 45 } 46 47 if (paymentEntitiesLogos !== undefined) { 48 data.paymentEntitiesLogos = paymentEntitiesLogos; 49 } 50 51 const request = new PaymentRequest([{ 52 supportedMethods: 'secure-payment-confirmation', data 53 }], PAYMENT_DETAILS); 54 55 await test_driver.bless('user activation'); 56 const responsePromise = request.show(); 57 58 const response = await responsePromise; 59 await response.complete('success'); 60 61 const cred = response.details; 62 assert_equals(cred.id, credential.id); 63 64 return JSON.parse(arrayBufferToString(cred.response.clientDataJSON)); 65 } 66 67 promise_test(async t => { 68 const clientDataJSON = await triggerSpc(t); 69 70 assert_equals(clientDataJSON.type, 'payment.get'); 71 assert_equals(clientDataJSON.challenge, base64UrlEncode(kChallenge)); 72 assert_equals(clientDataJSON.origin, window.location.origin); 73 assert_false(clientDataJSON.crossOrigin); 74 75 // Payment-specific information. 76 assert_equals(clientDataJSON.payment.rpId, window.location.hostname); 77 assert_equals(clientDataJSON.payment.topOrigin, window.location.origin); 78 assert_equals(clientDataJSON.payment.payeeOrigin, kPayeeOrigin); 79 assert_equals(clientDataJSON.payment.total.value, PAYMENT_DETAILS.total.amount.value); 80 assert_equals(clientDataJSON.payment.total.currency, PAYMENT_DETAILS.total.amount.currency); 81 assert_equals(clientDataJSON.payment.instrument.icon, ICON_URL); 82 assert_equals(clientDataJSON.payment.instrument.displayName, kInstrumentDisplayName); 83 84 // If the User Agent still supports the legacy 'rp' output parameter, it 85 // should be identical to the 'rpId' output parameter. See 86 // https://github.com/w3c/secure-payment-confirmation/pull/198 87 if ('rp' in clientDataJSON.payment) { 88 assert_equals(clientDataJSON.payment.rp, clientDataJSON.payment.rpId); 89 } 90 91 // TODO: Verify cred.response.signature, to validate that it covers all fields 92 // from clientDataJSON. 93 }, 'Successful SPC authentication - mandatory fields'); 94 95 promise_test(async t => { 96 const instrumentDetails = '***1234'; 97 const paymentEntityLogoLabel = 'Sync Network'; 98 const paymentEntitiesLogos = [{ 99 url: PAYMENT_ENTITY_LOGO_URL, 100 label: paymentEntityLogoLabel, 101 }]; 102 const clientDataJSON = await triggerSpc(t, instrumentDetails, paymentEntitiesLogos); 103 104 // Payment-specific information. 105 assert_equals(clientDataJSON.payment.instrument.details, instrumentDetails); 106 assert_equals(clientDataJSON.payment.paymentEntitiesLogos.length, 1); 107 assert_equals(clientDataJSON.payment.paymentEntitiesLogos[0].url, PAYMENT_ENTITY_LOGO_URL); 108 assert_equals(clientDataJSON.payment.paymentEntitiesLogos[0].label, paymentEntityLogoLabel); 109 }, 'Successful SPC authentication - optional fields'); 110 </script>