annotate node_modules/xmlhttprequest/tests/test-exceptions.js @ 101:52e44ee1c791 tip master

enabled all scores in autostart script
author Rob Canning <rc@kiben.net>
date Tue, 21 Apr 2015 16:20:57 +0100
parents cd921abc8887
children
rev   line source
rob@77 1 var sys = require("util")
rob@77 2 , assert = require("assert")
rob@77 3 , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
rob@77 4 , xhr = new XMLHttpRequest();
rob@77 5
rob@77 6 // Test request methods that aren't allowed
rob@77 7 try {
rob@77 8 xhr.open("TRACK", "http://localhost:8000/");
rob@77 9 console.log("ERROR: TRACK should have thrown exception");
rob@77 10 } catch(e) {}
rob@77 11 try {
rob@77 12 xhr.open("TRACE", "http://localhost:8000/");
rob@77 13 console.log("ERROR: TRACE should have thrown exception");
rob@77 14 } catch(e) {}
rob@77 15 try {
rob@77 16 xhr.open("CONNECT", "http://localhost:8000/");
rob@77 17 console.log("ERROR: CONNECT should have thrown exception");
rob@77 18 } catch(e) {}
rob@77 19 // Test valid request method
rob@77 20 try {
rob@77 21 xhr.open("GET", "http://localhost:8000/");
rob@77 22 } catch(e) {
rob@77 23 console.log("ERROR: Invalid exception for GET", e);
rob@77 24 }
rob@77 25
rob@77 26 // Test forbidden headers
rob@77 27 var forbiddenRequestHeaders = [
rob@77 28 "accept-charset",
rob@77 29 "accept-encoding",
rob@77 30 "access-control-request-headers",
rob@77 31 "access-control-request-method",
rob@77 32 "connection",
rob@77 33 "content-length",
rob@77 34 "content-transfer-encoding",
rob@77 35 "cookie",
rob@77 36 "cookie2",
rob@77 37 "date",
rob@77 38 "expect",
rob@77 39 "host",
rob@77 40 "keep-alive",
rob@77 41 "origin",
rob@77 42 "referer",
rob@77 43 "te",
rob@77 44 "trailer",
rob@77 45 "transfer-encoding",
rob@77 46 "upgrade",
rob@77 47 "user-agent",
rob@77 48 "via"
rob@77 49 ];
rob@77 50
rob@77 51 for (var i in forbiddenRequestHeaders) {
rob@77 52 try {
rob@77 53 xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test");
rob@77 54 console.log("ERROR: " + forbiddenRequestHeaders[i] + " should have thrown exception");
rob@77 55 } catch(e) {
rob@77 56 }
rob@77 57 }
rob@77 58
rob@77 59 // Try valid header
rob@77 60 xhr.setRequestHeader("X-Foobar", "Test");
rob@77 61
rob@77 62 console.log("Done");