Skip to content

Commit 455970e

Browse files
committed
Fetch: Access-Control-Expose-Headers: *
Belated test for whatwg/fetch#252.
1 parent 1856128 commit 455970e

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Fetch in worker: Access-Control-Expose-Headers: *</title>
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
</head>
9+
<body>
10+
<script>
11+
fetch_tests_from_worker(new Worker("cors-expose-star.js?pipe=sub"));
12+
</script>
13+
</body>
14+
</html>

fetch/api/cors/cors-expose-star.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Fetch: Access-Control-Expose-Headers: *</title>
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
</head>
9+
<body>
10+
<script src="../resources/utils.js"></script>
11+
<script src="cors-expose-star.js?pipe=sub"></script>
12+
</body>
13+
</html>

fetch/api/cors/cors-expose-star.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
if (this.document === undefined) {
2+
importScripts("/resources/testharness.js");
3+
importScripts("../resources/utils.js");
4+
}
5+
6+
const url = "http://{{host}}:{{ports[http][1]}}" + dirname(location.pathname) + RESOURCES_DIR + "top.txt",
7+
sharedHeaders = "?pipe=header(Access-Control-Expose-Headers,*)|header(Test,X)|header(Set-Cookie,X)|"
8+
9+
promise_test(t => {
10+
const headers = "header(Access-Control-Allow-Origin,*)"
11+
return fetch(url + sharedHeaders + headers).then(resp => {
12+
assert_equals(resp.status, 200)
13+
assert_equals(resp.type , "cors")
14+
assert_equals(resp.headers.get("test"), "X")
15+
assert_equals(resp.headers.get("set-cookie"), null)
16+
})
17+
}, "Basic Access-Control-Expose-Headers: * support")
18+
19+
promise_test(t => {
20+
const origin = location.origin, // assuming an ASCII origin
21+
headers = "header(Access-Control-Allow-Origin," + origin + ")|header(Access-Control-Allow-Credentials,true)"
22+
return fetch(url + sharedHeaders + headers, { credentials:"include" }).then(resp => {
23+
assert_equals(resp.status, 200)
24+
assert_equals(resp.type , "cors")
25+
assert_equals(resp.headers.get("content-type"), "text/plain") // safelisted
26+
assert_equals(resp.headers.get("test"), null)
27+
assert_equals(resp.headers.get("set-cookie"), null)
28+
})
29+
}, "Cannot use * for credentialed fetches")
30+
31+
done();

0 commit comments

Comments
 (0)