blob: 14edf5bd778ef49eba175be9dd8d657a86426e9c [file] [log] [blame]
<!doctype html>
<title>XMLHttpRequest: send() - "Basic" authenticated CORS request using setRequestHeader() but not setting withCredentials (expects to succeed)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<!-- These spec references do not make much sense simply because the spec doesn't say very much about this.. -->
<link rel="help" href="" data-tested-assertations="following::ol[1]/li[6]" />
<link rel="help" href="" data-tested-assertations="following::code[contains(@title,'http-authorization')]/.." />
<div id="log"></div>
function doTest(desc, pathsuffix, conditionsFunc, errorFunc, endFunc) {
var test = async_test(desc)
test.step(function() {
var client = new XMLHttpRequest(),
urlstart = + location.pathname.replace(/\/[^\/]*$/, '/'),
user = token()"GET", location.protocol + "//www1." + urlstart + "resources/" + pathsuffix, false)
client.setRequestHeader("x-user", user)
client.setRequestHeader("x-pass", 'pass')
client.setRequestHeader("Authorization", "Basic " + btoa(user + ":pass"))
client.onerror = test.step_func(errorFunc)
client.onreadystatechange = test.step_func(function () {
if(client.readyState < 4) {return}
conditionsFunc(client, test, user)
if(endFunc) {
client.onloadend = test.step_func(endFunc)
doTest("CORS request with setRequestHeader auth to URL accepting Authorization header", "auth7/", function (client, test, user) {
assert_true(client.responseText == (user + "\npass"), "responseText should contain the right user and password")
assert_equals(client.status, 200)
assert_equals(client.getResponseHeader("x-challenge"), "DID-NOT")
}, function(){
assert_unreached("Cross-domain request is permitted and should not cause an error")
var errorFired = false;
doTest("CORS request with setRequestHeader auth to URL NOT accepting Authorization header", "auth8/", function (client, test, user) {
assert_equals(client.responseText, '')
assert_equals(client.status, 0)
}, function(e){
errorFired = true
assert_equals(e.type, 'error', 'Error event fires when Authorize is a user-set header but not allowed by the CORS endpoint')
}, function() {
assert_true(errorFired, 'The error event should fire')