twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

test-exceptions.js (1440B)


      1 var 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
      7 try {
      8   xhr.open("TRACK", "http://localhost:8000/");
      9   console.log("ERROR: TRACK should have thrown exception");
     10 } catch(e) {}
     11 try {
     12   xhr.open("TRACE", "http://localhost:8000/");
     13   console.log("ERROR: TRACE should have thrown exception");
     14 } catch(e) {}
     15 try {
     16   xhr.open("CONNECT", "http://localhost:8000/");
     17   console.log("ERROR: CONNECT should have thrown exception");
     18 } catch(e) {}
     19 // Test valid request method
     20 try {
     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
     27 var 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 
     50 for (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
     57 xhr.setRequestHeader("X-Foobar", "Test");
     58 
     59 console.log("Done");