Skip to content

Commit

Permalink
Bug 1499659 [wpt PR 13559] - Fetch: test nosniff parsing better, a=te…
Browse files Browse the repository at this point in the history
…stonly

Automatic update from web-platform-testsFetch: X-Content-Type-Options: nosniff parsing

For whatwg/fetch#818.
--

wpt-commits: 10f708e6f13141fc92ca9318c7606590f659fcf2
wpt-pr: 13559
  • Loading branch information
annevk authored and moz-wptsync-bot committed Nov 10, 2018
1 parent 2fa1d1f commit dcc2d3f
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 66 deletions.
28 changes: 0 additions & 28 deletions testing/web-platform/tests/fetch/nosniff/parsing-nosniff.html

This file was deleted.

24 changes: 24 additions & 0 deletions testing/web-platform/tests/fetch/nosniff/parsing-nosniff.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
promise_test(() => fetch("resources/x-content-type-options.json").then(res => res.json()).then(runTests), "Loading JSON…");

function runTests(allTestData) {
for (let i = 0; i < allTestData.length; i++) {
const testData = allTestData[i],
input = encodeURIComponent(testData.input);
async_test(t => {
const script = document.createElement("script");
t.add_cleanup(() => script.remove());
// A <script> element loading a classic script does not care about the MIME type, unless
// X-Content-Type-Options: nosniff is specified, in which case a JavaScript MIME type is
// enforced, which x/x is not.
if (testData.nosniff) {
script.onerror = t.step_func_done();
script.onload = t.unreached_func("Script should not have loaded");
} else {
script.onerror = t.unreached_func("Script should have loaded");
script.onload = t.step_func_done();
}
script.src = "resources/nosniff.py?nosniff=" + input;
document.body.appendChild(script);
}, input);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 10 additions & 0 deletions testing/web-platform/tests/fetch/nosniff/resources/nosniff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def main(request, response):
response.add_required_headers = False
output = "HTTP/1.1 220 YOU HAVE NO POWER HERE\r\n"
output += "Content-Length: 22\r\n"
output += "Content-Type: x/x\r\n"
output += request.GET.first("nosniff") + "\r\n"
output += "\r\n"
output += "// nothing to see here"
response.writer.write(output)
response.close_connection = True
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"input": "X-Content-Type-Options: NOSNIFF",
"nosniff": true
},
{
"input": "x-content-type-OPTIONS: nosniff",
"nosniff": true
},
{
"input": "X-Content-Type-Options: nosniff,,@#$#%%&^&^*()()11!",
"nosniff": true
},
{
"input": "X-Content-Type-Options: @#$#%%&^&^*()()11!,nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options: nosniff\r\nX-Content-Type-Options: no",
"nosniff": true
},
{
"input": "X-Content-Type-Options: no\r\nX-Content-Type-Options: nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options:\r\nX-Content-Type-Options: nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options: ,nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options: nosniff\u000C",
"nosniff": false
},
{
"input": "X-Content-Type-Options: nosniff\u000B",
"nosniff": false
},
{
"input": "X-Content-Type-Options: nosniff\u000B,nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options: 'NosniFF'",
"nosniff": false
},
{
"input": "X-Content-Type-Options: \"nosniFF\"",
"nosniff": false
},
{
"input": "Content-Type-Options: nosniff",
"nosniff": false
}
]

0 comments on commit dcc2d3f

Please sign in to comment.