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,
PaymentMethodDataPtr& output,
ExceptionState& exception_state) {
PaymentsValidators::ValidateAndStringifyObject(
execution_context.GetIsolate(), "Payment method data", input,
output->stringified_data, exception_state);
execution_context.GetIsolate(), input, output->stringified_data,
exception_state);
if (exception_state.HadException())
return;
......@@ -634,9 +634,7 @@ void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate* input,
if (input->hasPaymentMethodErrors()) {
PaymentsValidators::ValidateAndStringifyObject(
execution_context.GetIsolate(), "Payment method errors",
input->paymentMethodErrors(),
execution_context.GetIsolate(), input->paymentMethodErrors(),
output->stringified_payment_method_errors, exception_state);
}
}
......
......@@ -208,7 +208,7 @@ ScriptPromise PaymentRequestEvent::changePaymentMethod(
if (!method_details.IsNull()) {
DCHECK(!method_details.IsEmpty());
PaymentsValidators::ValidateAndStringifyObject(
script_state->GetIsolate(), "Method details", method_details,
script_state->GetIsolate(), method_details,
method_data->stringified_data, exception_state);
if (exception_state.HadException())
return ScriptPromise();
......
......@@ -177,7 +177,6 @@ bool PaymentsValidators::IsValidMethodFormat(const String& identifier) {
void PaymentsValidators::ValidateAndStringifyObject(
v8::Isolate* isolate,
const String& input_name,
const ScriptValue& input,
String& output,
ExceptionState& exception_state) {
......@@ -186,8 +185,8 @@ void PaymentsValidators::ValidateAndStringifyObject(
!v8::JSON::Stringify(isolate->GetCurrentContext(),
input.V8Value().As<v8::Object>())
.ToLocal(&value)) {
exception_state.ThrowTypeError(input_name +
" should be a JSON-serializable object");
exception_state.ThrowTypeError(
"PaymentRequest objects should be JSON-serializable objects");
return;
}
......@@ -197,9 +196,10 @@ void PaymentsValidators::ValidateAndStringifyObject(
static constexpr size_t kMaxJSONStringLength = 1024 * 1024;
if (output.length() > kMaxJSONStringLength) {
exception_state.ThrowTypeError(String::Format(
"JSON serialization of %s should be no longer than %zu characters",
input_name.Characters8(), kMaxJSONStringLength));
exception_state.ThrowTypeError(
String::Format("JSON serialization of PaymentRequest objects should be "
"no longer than %zu characters",
kMaxJSONStringLength));
}
}
......
......@@ -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 invalid, throws a TypeError through the |exception_state|
// and uses the |input_name| to better describe what was being validated.
// If the |input| is invalid, throws a TypeError through the
// |exception_state|.
static void ValidateAndStringifyObject(v8::Isolate* isolate,
const String& input_name,
const ScriptValue& input,
String& output,
ExceptionState& exception_state);
......
......@@ -265,4 +265,20 @@ test(() => {
}], details);
});
}, '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>
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