Skip to content

Commit 9a97595

Browse files
hiroshige-gmoz-wptsync-bot
authored andcommitted
Bug 1720757 [wpt PR 29680] - [WPT] Fetch method normalization, a=testonly
Automatic update from web-platform-tests [WPT] Fetch method normalization This CL adds tests for https://fetch.spec.whatwg.org/#concept-method-normalize to check that the methods not listed there are not uppercased. This CL also adds more complete test coverage around case-sensitiveness of request methods. Discussion for not uppercasing "patch" method: whatwg/fetch#50 Bug: 1228178 Change-Id: I003cd65f0c330cc5b4641d79dce721970795c994 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3032582 Reviewed-by: Yutaka Hirano <[email protected]> Reviewed-by: Takashi Toyoshima <[email protected]> Commit-Queue: Hiroshige Hayashizaki <[email protected]> Cr-Commit-Position: refs/heads/main@{#926658} -- wpt-commits: 14f36e0dd4932d1c2a7dcfc541e1ba89e512a788 wpt-pr: 29680
1 parent 417e625 commit 9a97595

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

testing/web-platform/tests/fetch/api/cors/cors-preflight-star.any.js

+36-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,43 @@ preflightTest(true, false, "*", "x-test", "SUPER", ["X-Test", "1"])
4040
preflightTest(true, false, "*", "*", "OK", ["X-Test", "1"])
4141
preflightTest(false, true, "*", "*", "OK", ["X-Test", "1"])
4242
preflightTest(false, true, "*", "", "PUT", [])
43-
preflightTest(true, true, "PUT", "*", "PUT", [])
4443
preflightTest(false, true, "get", "*", "GET", ["X-Test", "1"])
4544
preflightTest(false, true, "*", "*", "GET", ["X-Test", "1"])
4645
// Exact character match works even for "*" with credentials.
4746
preflightTest(true, true, "*", "*", "*", ["*", "1"])
48-
// "PUT" does not pass the case-sensitive method check, and not in the safe list.
49-
preflightTest(false, true, "put", "*", "PUT", [])
47+
48+
// The following methods are upper-cased for init["method"] by
49+
// https://fetch.spec.whatwg.org/#concept-method-normalize
50+
// but not in Access-Control-Allow-Methods response.
51+
// But they are https://fetch.spec.whatwg.org/#cors-safelisted-method,
52+
// CORS anyway passes regardless of the cases.
53+
for (const METHOD of ['GET', 'HEAD', 'POST']) {
54+
const method = METHOD.toLowerCase();
55+
preflightTest(true, true, METHOD, "*", METHOD, [])
56+
preflightTest(true, true, METHOD, "*", method, [])
57+
preflightTest(true, true, method, "*", METHOD, [])
58+
preflightTest(true, true, method, "*", method, [])
59+
}
60+
61+
// The following methods are upper-cased for init["method"] by
62+
// https://fetch.spec.whatwg.org/#concept-method-normalize
63+
// but not in Access-Control-Allow-Methods response.
64+
// As they are not https://fetch.spec.whatwg.org/#cors-safelisted-method,
65+
// Access-Control-Allow-Methods should contain upper-cased methods,
66+
// while init["method"] can be either in upper or lower case.
67+
for (const METHOD of ['DELETE', 'PUT']) {
68+
const method = METHOD.toLowerCase();
69+
preflightTest(true, true, METHOD, "*", METHOD, [])
70+
preflightTest(true, true, METHOD, "*", method, [])
71+
preflightTest(false, true, method, "*", METHOD, [])
72+
preflightTest(false, true, method, "*", method, [])
73+
}
74+
75+
// "PATCH" is NOT upper-cased in both places because it is not listed in
76+
// https://fetch.spec.whatwg.org/#concept-method-normalize.
77+
// So Access-Control-Allow-Methods value and init["method"] should match
78+
// case-sensitively.
79+
preflightTest(true, true, "PATCH", "*", "PATCH", [])
80+
preflightTest(false, true, "PATCH", "*", "patch", [])
81+
preflightTest(false, true, "patch", "*", "PATCH", [])
82+
preflightTest(true, true, "patch", "*", "patch", [])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// META: global=window,worker
2+
3+
// https://fetch.spec.whatwg.org/#forbidden-method
4+
for (const method of [
5+
'CONNECT', 'TRACE', 'TRACK',
6+
'connect', 'trace', 'track'
7+
]) {
8+
test(function() {
9+
assert_throws_js(TypeError,
10+
function() { new Request('./', {method: method}); }
11+
);
12+
}, 'Request() with a forbidden method ' + method + ' must throw.');
13+
}

testing/web-platform/tests/fetch/api/request/request-init-001.sub.html

+14-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@
1010
</head>
1111
<body>
1212
<script>
13-
var methods = {"givenValues" : ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "head"],
14-
"expectedValues" : ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "HEAD"]
13+
// https://fetch.spec.whatwg.org/#concept-method-normalize
14+
var methods = {
15+
"givenValues" : [
16+
"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS",
17+
"get", "head", "post", "put", "delete", "options",
18+
"Get", "hEad", "poSt", "Put", "deleTe", "optionS",
19+
"PATCH", "patch", "patCh"
20+
],
21+
"expectedValues" : [
22+
"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS",
23+
"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS",
24+
"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS",
25+
"PATCH", "patch", "patCh"
26+
]
1527
};
1628
var referrers = {"givenValues" : ["/relative/ressource",
1729
"http://{{host}}:{{ports[http][0]}}/relative/ressource?query=true#fragment",

0 commit comments

Comments
 (0)