Skip to content

Commit

Permalink
Porting access-control-basic-post-fail-non-simple-content-type to WPT
Browse files Browse the repository at this point in the history
Bug: 745385
Change-Id: Iff8975a41dcace408427192c03087571b14bae53
Reviewed-on: https://chromium-review.googlesource.com/616482
WPT-Export-Revision: 59d6f986ae260981341a93e27854c434a633f477
  • Loading branch information
aahlstrom authored and chromium-wpt-export-bot committed Aug 18, 2017
1 parent 03a4dab commit ffb718b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<title>Non-CORS-safelisted value in the Content-Type header results in a request preflight</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script type="text/javascript">
test(function() {
const xhr = new XMLHttpRequest;

xhr.open("POST", get_host_info().HTTP_ORIGIN +
"/XMLHttpRequest/resources/access-control-basic-options-not-supported.py", false);

xhr.setRequestHeader("Content-Type", "application/xml");

xhr.send();

assert_equals(xhr.status, 200, "Cross-domain access was denied in 'send'.");
}, "Same-origin request with non-safelisted content type succeeds");

test(function() {
const xhr = new XMLHttpRequest;

xhr.open("POST", get_host_info().HTTP_REMOTE_ORIGIN +
"/XMLHttpRequest/resources/access-control-basic-options-not-supported.py", false);

xhr.setRequestHeader("Content-Type", "application/xml");

try {
xhr.send();
} catch(e) {
assert_equals(xhr.status, 0, "Cross-domain access was denied in 'send'.");
return;
}
assert_unreached("Cross-domain access was not denied in 'send'.");
}, "CORS request with non-safelisted content type sends preflight and fails");
</script>
</body>
</html>
@@ -0,0 +1,9 @@
def main(request, response):
response.headers.set("Cache-Control", "no-store")

# Allow simple requests, but deny preflight
if request.method != "OPTIONS":
response.headers.set("Access-Control-Allow-Credentials", "true")
response.headers.set("Access-Control-Allow-Origin", request.headers.get("origin"))
else:
response.status = 400

0 comments on commit ffb718b

Please sign in to comment.