Commit e2378696 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] Very long instrumentId string test.

This patch adds a test for JSON serialization of a very long string
being passed into PaymentRequest API.

Bug: 1110324, 1115091
Change-Id: Ia6690b2f41ff99190afed4431854515b167056b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2348411
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarNick Burris <nburris@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#797165}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359155
Cr-Commit-Position: refs/heads/master@{#803617}
parent 45b9e7f3
...@@ -419,8 +419,8 @@ void StringifyAndParseMethodSpecificData(ExecutionContext& execution_context, ...@@ -419,8 +419,8 @@ void StringifyAndParseMethodSpecificData(ExecutionContext& execution_context,
PaymentMethodDataPtr& output, PaymentMethodDataPtr& output,
ExceptionState& exception_state) { ExceptionState& exception_state) {
PaymentsValidators::ValidateAndStringifyObject( PaymentsValidators::ValidateAndStringifyObject(
execution_context.GetIsolate(), "Payment method data", input, execution_context.GetIsolate(), input, output->stringified_data,
output->stringified_data, exception_state); exception_state);
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
...@@ -634,9 +634,7 @@ void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate* input, ...@@ -634,9 +634,7 @@ void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate* input,
if (input->hasPaymentMethodErrors()) { if (input->hasPaymentMethodErrors()) {
PaymentsValidators::ValidateAndStringifyObject( PaymentsValidators::ValidateAndStringifyObject(
execution_context.GetIsolate(), "Payment method errors", execution_context.GetIsolate(), input->paymentMethodErrors(),
input->paymentMethodErrors(),
output->stringified_payment_method_errors, exception_state); output->stringified_payment_method_errors, exception_state);
} }
} }
......
...@@ -208,7 +208,7 @@ ScriptPromise PaymentRequestEvent::changePaymentMethod( ...@@ -208,7 +208,7 @@ ScriptPromise PaymentRequestEvent::changePaymentMethod(
if (!method_details.IsNull()) { if (!method_details.IsNull()) {
DCHECK(!method_details.IsEmpty()); DCHECK(!method_details.IsEmpty());
PaymentsValidators::ValidateAndStringifyObject( PaymentsValidators::ValidateAndStringifyObject(
script_state->GetIsolate(), "Method details", method_details, script_state->GetIsolate(), method_details,
method_data->stringified_data, exception_state); method_data->stringified_data, exception_state);
if (exception_state.HadException()) if (exception_state.HadException())
return ScriptPromise(); return ScriptPromise();
......
...@@ -177,7 +177,6 @@ bool PaymentsValidators::IsValidMethodFormat(const String& identifier) { ...@@ -177,7 +177,6 @@ bool PaymentsValidators::IsValidMethodFormat(const String& identifier) {
void PaymentsValidators::ValidateAndStringifyObject( void PaymentsValidators::ValidateAndStringifyObject(
v8::Isolate* isolate, v8::Isolate* isolate,
const String& input_name,
const ScriptValue& input, const ScriptValue& input,
String& output, String& output,
ExceptionState& exception_state) { ExceptionState& exception_state) {
...@@ -186,8 +185,8 @@ void PaymentsValidators::ValidateAndStringifyObject( ...@@ -186,8 +185,8 @@ void PaymentsValidators::ValidateAndStringifyObject(
!v8::JSON::Stringify(isolate->GetCurrentContext(), !v8::JSON::Stringify(isolate->GetCurrentContext(),
input.V8Value().As<v8::Object>()) input.V8Value().As<v8::Object>())
.ToLocal(&value)) { .ToLocal(&value)) {
exception_state.ThrowTypeError(input_name + exception_state.ThrowTypeError(
" should be a JSON-serializable object"); "PaymentRequest objects should be JSON-serializable objects");
return; return;
} }
...@@ -197,9 +196,10 @@ void PaymentsValidators::ValidateAndStringifyObject( ...@@ -197,9 +196,10 @@ void PaymentsValidators::ValidateAndStringifyObject(
static constexpr size_t kMaxJSONStringLength = 1024 * 1024; static constexpr size_t kMaxJSONStringLength = 1024 * 1024;
if (output.length() > kMaxJSONStringLength) { if (output.length() > kMaxJSONStringLength) {
exception_state.ThrowTypeError(String::Format( exception_state.ThrowTypeError(
"JSON serialization of %s should be no longer than %zu characters", String::Format("JSON serialization of PaymentRequest objects should be "
input_name.Characters8(), kMaxJSONStringLength)); "no longer than %zu characters",
kMaxJSONStringLength));
} }
} }
......
...@@ -70,10 +70,9 @@ class MODULES_EXPORT PaymentsValidators final { ...@@ -70,10 +70,9 @@ class MODULES_EXPORT PaymentsValidators final {
// //
// If the |input| is valid, the JSON serialization is saved in |output|. // If the |input| is valid, the JSON serialization is saved in |output|.
// //
// If the |input| is invalid, throws a TypeError through the |exception_state| // If the |input| is invalid, throws a TypeError through the
// and uses the |input_name| to better describe what was being validated. // |exception_state|.
static void ValidateAndStringifyObject(v8::Isolate* isolate, static void ValidateAndStringifyObject(v8::Isolate* isolate,
const String& input_name,
const ScriptValue& input, const ScriptValue& input,
String& output, String& output,
ExceptionState& exception_state); ExceptionState& exception_state);
......
...@@ -265,4 +265,20 @@ test(() => { ...@@ -265,4 +265,20 @@ test(() => {
}], details); }], details);
}); });
}, 'Timeout longer than 1 hour throws exception.'); }, 'Timeout longer than 1 hour throws exception.');
test(() => {
assert_throws_js(TypeError, () => {
new PaymentRequest([{
supportedMethods: 'secure-payment-confirmation',
data: {
action: 'authenticate',
// Large instrumentId value.
instrumentId: 'x'.repeat(1024 * 1024),
networkData: Uint8Array.from('x', c => c.charCodeAt(0)),
timeout: 60000,
fallbackUrl: 'https://fallback.example/url'
},
}], details);
});
}, 'Large instrumentId value throws exception.');
</script> </script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment