From 6016fb6bb6db06f27929936f997e4eefded0e921 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 15 Mar 2021 23:37:20 +0000 Subject: [PATCH] Bug 1455613 [wpt PR 10548] - Parsing Content-Length, a=testonly Automatic update from web-platform-tests Fetch: parsing Content-Length For https://github.com/whatwg/fetch/pull/1183. -- wpt-commits: 3a48a22074a41e7817a17dfbf5cb6c61277f8877 wpt-pr: 10548 UltraBlame original commit: 5c299636aa6340c1499f89538f61c57c9ea2c615 --- .../fetch/content-length/parsing.window.js | 161 +++++ .../resources/content-length.py | 121 ++++ .../resources/content-lengths.json | 676 ++++++++++++++++++ .../fetch/content-length/too-long.window.js | 65 ++ 4 files changed, 1023 insertions(+) create mode 100644 testing/web-platform/tests/fetch/content-length/parsing.window.js create mode 100644 testing/web-platform/tests/fetch/content-length/resources/content-length.py create mode 100644 testing/web-platform/tests/fetch/content-length/resources/content-lengths.json create mode 100644 testing/web-platform/tests/fetch/content-length/too-long.window.js diff --git a/testing/web-platform/tests/fetch/content-length/parsing.window.js b/testing/web-platform/tests/fetch/content-length/parsing.window.js new file mode 100644 index 0000000000000..0e1654defab47 --- /dev/null +++ b/testing/web-platform/tests/fetch/content-length/parsing.window.js @@ -0,0 +1,161 @@ +promise_test +( +( +) += +> +{ +return +fetch +( +" +resources +/ +content +- +lengths +. +json +" +) +. +then +( +res += +> +res +. +json +( +) +) +. +then +( +runTests +) +; +} +" +Loading +JSON +" +) +; +function +runTests +( +testUnits +) +{ +testUnits +. +forEach +( +testUnit += +> +{ +const +input += +encodeURIComponent +( +testUnit +. +input +) +; +promise_test +( +t += +> +{ +const +result += +fetch +( +" +resources +/ +content +- +length +. +py +? +length += +" ++ +input +) +; +if +( +testUnit +. +output += += += +null +) +{ +return +promise_rejects_js +( +t +TypeError +result +) +; +} +else +{ +return +result +. +then +( +res += +> +res +. +text +( +) +) +. +then +( +text += +> +{ +assert_equals +( +text +. +length +testUnit +. +output +) +; +} +) +; +} +} +input +) +; +} +) +; +} diff --git a/testing/web-platform/tests/fetch/content-length/resources/content-length.py b/testing/web-platform/tests/fetch/content-length/resources/content-length.py new file mode 100644 index 0000000000000..733d020f396b6 --- /dev/null +++ b/testing/web-platform/tests/fetch/content-length/resources/content-length.py @@ -0,0 +1,121 @@ +def +main +( +request +response +) +: + +response +. +add_required_headers += +False + +output += +b +" +HTTP +/ +1 +. +1 +200 +OK +\ +r +\ +n +" + +output ++ += +b +" +Content +- +Type +: +text +/ +plain +; +charset += +UTF +- +8 +\ +r +\ +n +" + +output ++ += +request +. +GET +. +first +( +b +" +length +" +) ++ +b +" +\ +r +\ +n +" + +output ++ += +b +" +\ +r +\ +n +" + +output ++ += +b +" +Fact +: +this +is +really +forty +- +two +bytes +long +. +" + +response +. +writer +. +write +( +output +) + +response +. +close_connection += +True diff --git a/testing/web-platform/tests/fetch/content-length/resources/content-lengths.json b/testing/web-platform/tests/fetch/content-length/resources/content-lengths.json new file mode 100644 index 0000000000000..d476426a2f655 --- /dev/null +++ b/testing/web-platform/tests/fetch/content-length/resources/content-lengths.json @@ -0,0 +1,676 @@ +[ +{ +" +input +" +: +" +Content +- +Length +: +42 +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +42 +42 +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +42 +\ +r +\ +nContent +- +Length +: +42 +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +42 +\ +r +\ +nContent +- +Length +: +42 +42 +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +30 +" +" +output +" +: +30 +} +{ +" +input +" +: +" +Content +- +Length +: +30 +30 +" +" +output +" +: +30 +} +{ +" +input +" +: +" +Content +- +Length +: +30 +\ +r +\ +nContent +- +Length +: +30 +" +" +output +" +: +30 +} +{ +" +input +" +: +" +Content +- +Length +: +30 +\ +r +\ +nContent +- +Length +: +30 +30 +" +" +output +" +: +30 +} +{ +" +input +" +: +" +Content +- +Length +: +42 +30 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +30 +42 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +42 +\ +r +\ +nContent +- +Length +: +30 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +30 +\ +r +\ +nContent +- +Length +: +42 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +30 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +30 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +30 +\ +r +\ +nContent +- +Length +: +\ +t +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +\ +r +\ +nContent +- +Length +: +30 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +aaaah +\ +r +\ +nContent +- +Length +: +nah +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +aaaah +nah +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +aaaah +\ +r +\ +nContent +- +Length +: +aaaah +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +aaaah +aaaah +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +aaaah +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +42s +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +30s +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +- +1 +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +0x20 +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +030 +" +" +output +" +: +30 +} +{ +" +input +" +: +" +Content +- +Length +: +030 +\ +r +\ +nContent +- +Length +: +30 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +030 +30 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +\ +" +30 +\ +" +" +" +output +" +: +42 +} +{ +" +input +" +: +" +Content +- +Length +: +30 +\ +r +\ +nContent +- +Length +: +\ +r +\ +nContent +- +Length +: +30 +" +" +output +" +: +null +} +{ +" +input +" +: +" +Content +- +Length +: +" +" +output +" +: +42 +} +] diff --git a/testing/web-platform/tests/fetch/content-length/too-long.window.js b/testing/web-platform/tests/fetch/content-length/too-long.window.js new file mode 100644 index 0000000000000..65c60b6d98720 --- /dev/null +++ b/testing/web-platform/tests/fetch/content-length/too-long.window.js @@ -0,0 +1,65 @@ +promise_test +( +async +t += +> +{ +const +result += +await +fetch +( +resources +/ +content +- +length +. +py +? +length += +{ +encodeURIComponent +( +" +Content +- +Length +: +50 +" +) +} +) +; +await +promise_rejects_js +( +t +TypeError +result +. +text +( +) +) +; +} +" +Content +- +Length +header +value +of +network +response +exceeds +response +body +" +) +;