socketioMEANseed/server/node_modules/xmlhttprequest-ssl/tests/test-exceptions.js
server/node_modules/xmlhttprequest-ssl/tests/test-exceptions.jsRaw
1var sys = require("util")
2 , assert = require("assert")
3 , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
4 , xhr = new XMLHttpRequest();
5
6// Test request methods that aren't allowed
7try {
8 xhr.open("TRACK", "http://localhost:8000/");
9 console.log("ERROR: TRACK should have thrown exception");
10} catch(e) {}
11try {
12 xhr.open("TRACE", "http://localhost:8000/");
13 console.log("ERROR: TRACE should have thrown exception");
14} catch(e) {}
15try {
16 xhr.open("CONNECT", "http://localhost:8000/");
17 console.log("ERROR: CONNECT should have thrown exception");
18} catch(e) {}
19// Test valid request method
20try {
21 xhr.open("GET", "http://localhost:8000/");
22} catch(e) {
23 console.log("ERROR: Invalid exception for GET", e);
24}
25
26// Test forbidden headers
27var forbiddenRequestHeaders = [
28 "accept-charset",
29 "accept-encoding",
30 "access-control-request-headers",
31 "access-control-request-method",
32 "connection",
33 "content-length",
34 "content-transfer-encoding",
35 "cookie",
36 "cookie2",
37 "date",
38 "expect",
39 "host",
40 "keep-alive",
41 "origin",
42 "referer",
43 "te",
44 "trailer",
45 "transfer-encoding",
46 "upgrade",
47 "via"
48];
49
50for (var i in forbiddenRequestHeaders) {
51 if(xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test") !== false) {
52 console.log("ERROR: " + forbiddenRequestHeaders[i] + " should have thrown exception");
53 }
54}
55
56// Try valid header
57xhr.setRequestHeader("X-Foobar", "Test");
58
59console.log("Done");