Changeset 223163 in webkit
- Timestamp:
- Oct 10, 2017 7:57:12 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r223160 r223163 1 2017-10-10 Andy Estes <aestes@apple.com> 2 3 [Payment Request] Validate that all PaymentCurrencyAmounts use the same currency code when using Apple Pay 4 https://bugs.webkit.org/show_bug.cgi?id=178150 5 6 Reviewed by Tim Horton. 7 8 * http/tests/paymentrequest/payment-request-abort-method.https.html: 9 * http/tests/paymentrequest/payment-request-canmakepayment-method.https.html: 10 * http/tests/paymentrequest/payment-request-show-method.https.html: 11 * http/tests/ssl/applepay/PaymentRequest.https-expected.txt: 12 * http/tests/ssl/applepay/PaymentRequest.https.html: 13 1 14 2017-10-10 Andy Estes <aestes@apple.com> 2 15 -
trunk/LayoutTests/http/tests/paymentrequest/payment-request-abort-method.https.html
r223160 r223163 23 23 supportedNetworks: ['visa', 'masterCard'], 24 24 countryCode: 'US', 25 currencyCode: 'USD',26 25 }, 27 26 }); -
trunk/LayoutTests/http/tests/paymentrequest/payment-request-canmakepayment-method.https.html
r223160 r223163 17 17 supportedNetworks: ["visa", "masterCard"], 18 18 countryCode: "US", 19 currencyCode: "USD",20 19 } 21 20 }); -
trunk/LayoutTests/http/tests/paymentrequest/payment-request-show-method.https.html
r223160 r223163 18 18 supportedNetworks: ['visa', 'masterCard'], 19 19 countryCode: 'US', 20 currencyCode: 'USD',21 20 }, 22 21 }); -
trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https-expected.txt
r222921 r223163 29 29 PASS request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show() rejected promise with TypeError: "7" is not a valid country code.. 30 30 31 Testing ApplePayRequest.currencyCode32 33 SETUP: paymentMethod = validPaymentMethod(); delete paymentMethod.data.currencyCode;34 PASS request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show() rejected promise with TypeError: Member ApplePayRequest.currencyCode is required and must be an instance of DOMString.35 36 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = 'invalid';37 PASS request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show() rejected promise with TypeError: "invalid" is not a valid currency code..38 39 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = '';40 PASS request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show() rejected promise with TypeError: "" is not a valid currency code..41 42 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = null;43 PASS request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show() rejected promise with TypeError: "null" is not a valid currency code..44 45 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = undefined;46 PASS request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show() rejected promise with TypeError: Member ApplePayRequest.currencyCode is required and must be an instance of DOMString.47 48 SETUP: paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = 7;49 PASS request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show() rejected promise with TypeError: "7" is not a valid currency code..50 51 31 Testing ApplePayRequest.supportedNetworks 52 32 … … 219 199 PASS request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show() threw exception TypeError: Type error. 220 200 201 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: { currency: 'EUR', value: '10.00' } }]; 202 PASS request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show() rejected promise with TypeError: "EUR" does not match the expected currency of "USD". Apple Pay requires all PaymentCurrencyAmounts to use the same currency code.. 221 203 Testing PaymentDetails.shippingOptions 222 204 … … 254 236 PASS request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show() threw exception TypeError: Type error. 255 237 238 SETUP: paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }]; 239 PASS request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show() rejected promise with TypeError: "EUR" does not match the expected currency of "USD". Apple Pay requires all PaymentCurrencyAmounts to use the same currency code.. 256 240 Testing PaymentOptions 257 241 -
trunk/LayoutTests/http/tests/ssl/applepay/PaymentRequest.https.html
r223160 r223163 19 19 merchantIdentifier: '', 20 20 countryCode: 'US', 21 currencyCode: 'USD',22 21 supportedNetworks: ['visa', 'masterCard'], 23 22 merchantCapabilities: ['supports3DS'], … … 72 71 debug("") 73 72 await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.countryCode = 7;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()") 74 debug("")75 76 debug("Testing ApplePayRequest.currencyCode")77 debug("")78 await logAndShouldReject("paymentMethod = validPaymentMethod(); delete paymentMethod.data.currencyCode;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")79 debug("")80 await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = 'invalid';", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")81 debug("")82 await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = '';", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")83 debug("")84 await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = null;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")85 debug("")86 await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = undefined;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")87 debug("")88 await logAndShouldReject("paymentMethod = validPaymentMethod(); paymentMethod.data.currencyCode = 7;", "request = new PaymentRequest([paymentMethod], validPaymentDetails()); request.show()")89 73 debug("") 90 74 … … 191 175 logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()") 192 176 logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: '10.00', type: 'invalid' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()") 193 177 await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.displayItems = [{ label: 'label', amount: { currency: 'EUR', value: '10.00' } }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()") 178 194 179 debug("Testing PaymentDetails.shippingOptions") 195 180 debug(""); … … 205 190 logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '', detail: '', identifier: '', label: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()") 206 191 logAndShouldThrow("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: '-1', detail: '', identifier: '', label: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()") 192 await logAndShouldReject("paymentDetails = validPaymentDetails(); paymentDetails.shippingOptions = [{ amount: { currency: 'EUR', value: '10.00' }, id: '', label: '' }];", "request = new PaymentRequest([validPaymentMethod()], paymentDetails); request.show()") 207 193 208 194 debug("Testing PaymentOptions") -
trunk/Source/WebCore/ChangeLog
r223160 r223163 1 2017-10-10 Andy Estes <aestes@apple.com> 2 3 [Payment Request] Validate that all PaymentCurrencyAmounts use the same currency code when using Apple Pay 4 https://bugs.webkit.org/show_bug.cgi?id=178150 5 6 Reviewed by Tim Horton. 7 8 Apple Pay requires a single currency code, but the Payment Request API allows the client to 9 specify a currency code for each PaymentCurrencyAmount. 10 11 Instead of having a required currencyCode property on ApplePayRequest and ignoring the 12 currency property on PaymentCurrencyAmount, validate that all PaymentCurrencyAmounts use the 13 same currency code and use that as ApplePaySessionPaymentRequest's currencyCode. 14 15 Added test cases to http/tests/ssl/applepay/PaymentRequest.https.html. 16 17 * Modules/applepay/ApplePayPaymentRequest.h: 18 * Modules/applepay/ApplePayPaymentRequest.idl: 19 * Modules/applepay/ApplePayRequestBase.cpp: 20 (WebCore::convertAndValidate): 21 * Modules/applepay/ApplePayRequestBase.h: 22 * Modules/applepay/ApplePayRequestBase.idl: 23 * Modules/applepay/ApplePaySession.cpp: 24 (WebCore::convertAndValidate): 25 * Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp: 26 (WebCore::validate): 27 (WebCore::convertAndValidate): 28 (WebCore::ApplePayPaymentHandler::show): 29 * Modules/applepay/paymentrequest/ApplePayRequest.idl: 30 1 31 2017-10-10 Andy Estes <aestes@apple.com> 2 32 -
trunk/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.h
r222921 r223163 30 30 #include "ApplePayLineItem.h" 31 31 #include "ApplePayPaymentContact.h" 32 #include "ApplePayRequest .h"32 #include "ApplePayRequestBase.h" 33 33 #include "ApplePaySessionPaymentRequest.h" 34 34 #include "ApplePayShippingMethod.h" … … 36 36 namespace WebCore { 37 37 38 struct ApplePayPaymentRequest : ApplePayRequest {38 struct ApplePayPaymentRequest : ApplePayRequestBase { 39 39 using ShippingType = ApplePaySessionPaymentRequest::ShippingType; 40 41 String currencyCode; 40 42 41 43 std::optional<Vector<ApplePayContactField>> requiredShippingContactFields; -
trunk/Source/WebCore/Modules/applepay/ApplePayPaymentRequest.idl
r222921 r223163 39 39 sequence<ApplePayLineItem> lineItems; 40 40 41 required DOMString currencyCode; 42 41 43 sequence<ApplePayContactField> requiredShippingContactFields; 42 44 ApplePayPaymentContact shippingContact; -
trunk/Source/WebCore/Modules/applepay/ApplePayRequestBase.cpp
r222921 r223163 47 47 { 48 48 ApplePaySessionPaymentRequest result; 49 50 49 result.setCountryCode(request.countryCode); 51 result.setCurrencyCode(request.currencyCode);52 50 53 51 auto merchantCapabilities = convertAndValidate(request.merchantCapabilities); -
trunk/Source/WebCore/Modules/applepay/ApplePayRequestBase.h
r222921 r223163 38 38 Vector<String> supportedNetworks; 39 39 String countryCode; 40 String currencyCode;41 40 42 41 std::optional<Vector<ApplePayContactField>> requiredBillingContactFields; -
trunk/Source/WebCore/Modules/applepay/ApplePayRequestBase.idl
r222921 r223163 30 30 required sequence<DOMString> supportedNetworks; // FIXME: Should this be an sequence of enums? 31 31 required DOMString countryCode; 32 required DOMString currencyCode;33 32 34 33 sequence<ApplePayContactField> requiredBillingContactFields; -
trunk/Source/WebCore/Modules/applepay/ApplePaySession.cpp
r222921 r223163 214 214 215 215 auto result = convertedRequest.releaseReturnValue(); 216 result.setCurrencyCode(paymentRequest.currencyCode); 216 217 217 218 auto total = convertAndValidateTotal(WTFMove(paymentRequest.total)); -
trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayPaymentHandler.cpp
r223160 r223163 68 68 } 69 69 70 static ApplePaySessionPaymentRequest::LineItem convert(const PaymentItem& item) 71 { 70 static ExceptionOr<void> validate(const PaymentCurrencyAmount& amount, const String& expectedCurrency) 71 { 72 if (amount.currency != expectedCurrency) 73 return Exception { TypeError, makeString("\"", amount.currency, "\" does not match the expected currency of \"", expectedCurrency, "\". Apple Pay requires all PaymentCurrencyAmounts to use the same currency code.") }; 74 return { }; 75 } 76 77 static ExceptionOr<ApplePaySessionPaymentRequest::LineItem> convertAndValidate(const PaymentItem& item, const String& expectedCurrency) 78 { 79 auto exception = validate(item.amount, expectedCurrency); 80 if (exception.hasException()) 81 return exception.releaseException(); 82 72 83 ApplePaySessionPaymentRequest::LineItem lineItem; 73 84 lineItem.amount = item.amount.value; … … 77 88 } 78 89 79 static Vector<ApplePaySessionPaymentRequest::LineItem> convert(const Vector<PaymentItem>& lineItems)90 static ExceptionOr<Vector<ApplePaySessionPaymentRequest::LineItem>> convertAndValidate(const Vector<PaymentItem>& lineItems, const String& expectedCurrency) 80 91 { 81 92 Vector<ApplePaySessionPaymentRequest::LineItem> result; 82 93 result.reserveInitialCapacity(lineItems.size()); 83 for (auto& lineItem : lineItems) 84 result.uncheckedAppend(convert(lineItem)); 94 for (auto& lineItem : lineItems) { 95 auto convertedLineItem = convertAndValidate(lineItem, expectedCurrency); 96 if (convertedLineItem.hasException()) 97 return convertedLineItem.releaseException(); 98 result.uncheckedAppend(convertedLineItem.releaseReturnValue()); 99 } 85 100 return result; 86 101 } … … 111 126 } 112 127 113 static ApplePaySessionPaymentRequest::ShippingMethod convert(const PaymentShippingOption& shippingOption) 114 { 128 static ExceptionOr<ApplePaySessionPaymentRequest::ShippingMethod> convertAndValidate(const PaymentShippingOption& shippingOption, const String& expectedCurrency) 129 { 130 auto exception = validate(shippingOption.amount, expectedCurrency); 131 if (exception.hasException()) 132 return exception.releaseException(); 133 115 134 ApplePaySessionPaymentRequest::ShippingMethod result; 116 135 result.amount = shippingOption.amount.value; … … 138 157 139 158 ApplePaySessionPaymentRequest request = validatedRequest.releaseReturnValue(); 140 request.setTotal(convert(m_paymentRequest->paymentDetails().total)); 141 142 auto lineItems = convert(m_paymentRequest->paymentDetails().displayItems); 159 160 String expectedCurrency = m_paymentRequest->paymentDetails().total.amount.currency; 161 request.setCurrencyCode(expectedCurrency); 162 163 auto total = convertAndValidate(m_paymentRequest->paymentDetails().total, expectedCurrency); 164 ASSERT(!total.hasException()); 165 request.setTotal(total.releaseReturnValue()); 166 167 auto convertedLineItems = convertAndValidate(m_paymentRequest->paymentDetails().displayItems, expectedCurrency); 168 if (convertedLineItems.hasException()) 169 return convertedLineItems.releaseException(); 170 171 auto lineItems = convertedLineItems.releaseReturnValue(); 143 172 for (auto& modifier : m_paymentRequest->paymentDetails().modifiers) { 144 173 auto convertedIdentifier = convertAndValidatePaymentMethodIdentifier(modifier.supportedMethods); 145 if (convertedIdentifier && handlesIdentifier(*convertedIdentifier)) 146 lineItems.appendVector(convert(modifier.additionalDisplayItems)); 174 if (!convertedIdentifier || !handlesIdentifier(*convertedIdentifier)) 175 continue; 176 177 auto additionalDisplayItems = convertAndValidate(modifier.additionalDisplayItems, expectedCurrency); 178 if (additionalDisplayItems.hasException()) 179 return additionalDisplayItems.releaseException(); 180 181 lineItems.appendVector(additionalDisplayItems.releaseReturnValue()); 147 182 } 148 183 request.setLineItems(lineItems); … … 154 189 Vector<ApplePaySessionPaymentRequest::ShippingMethod> shippingMethods; 155 190 shippingMethods.reserveInitialCapacity(m_paymentRequest->paymentDetails().shippingOptions.size()); 156 for (auto& shippingOption : m_paymentRequest->paymentDetails().shippingOptions) 157 shippingMethods.uncheckedAppend(convert(shippingOption)); 191 for (auto& shippingOption : m_paymentRequest->paymentDetails().shippingOptions) { 192 auto convertedShippingOption = convertAndValidate(shippingOption, expectedCurrency); 193 if (convertedShippingOption.hasException()) 194 return convertedShippingOption.releaseException(); 195 shippingMethods.uncheckedAppend(convertedShippingOption.releaseReturnValue()); 196 } 158 197 request.setShippingMethods(shippingMethods); 159 198 -
trunk/Source/WebCore/Modules/applepay/paymentrequest/ApplePayRequest.idl
r223160 r223163 30 30 required DOMString merchantIdentifier; 31 31 }; 32
Note: See TracChangeset
for help on using the changeset viewer.