Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / xmlhttprequest / tests / test-exceptions.js
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   "user-agent",
48   "via"
49 ];
50
51 for (var i in forbiddenRequestHeaders) {
52   try {
53     xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test");
54     console.log("ERROR: " + forbiddenRequestHeaders[i] + " should have thrown exception");
55   } catch(e) {
56   }
57 }
58
59 // Try valid header
60 xhr.setRequestHeader("X-Foobar", "Test");
61
62 console.log("Done");