Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / http-proxy / test / http / http-test.js
1 /*
2   node-http-proxy-test.js: http proxy for node.js
3
4   Copyright (c) 2010 Charlie Robbins, Marak Squires and Fedor Indutny
5
6   Permission is hereby granted, free of charge, to any person obtaining
7   a copy of this software and associated documentation files (the
8   "Software"), to deal in the Software without restriction, including
9   without limitation the rights to use, copy, modify, merge, publish,
10   distribute, sublicense, and/or sell copies of the Software, and to
11   permit persons to whom the Software is furnished to do so, subject to
12   the following conditions:
13
14   The above copyright notice and this permission notice shall be
15   included in all copies or substantial portions of the Software.
16
17   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21   LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23   WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 */
26  
27 var assert = require('assert'),
28     fs = require('fs'),
29     path = require('path'),
30     async = require('async'),
31     request = require('request'),
32     vows = require('vows'),
33     macros = require('../macros'),
34     helpers = require('../helpers');
35
36 var routeFile = path.join(__dirname, 'config.json');
37
38 vows.describe(helpers.describe()).addBatch({
39   "With a valid target server": {
40     "and no latency": {
41       "and no headers": macros.http.assertProxied(),
42       "and headers": macros.http.assertProxied({
43         request: { headers: { host: 'unknown.com' } }
44       }),
45       "and request close connection header": macros.http.assertProxied({
46         request: { headers: { connection: "close" } },
47         outputHeaders: { connection: "close" }
48       }),
49       "and request keep alive connection header": macros.http.assertProxied({
50         request: { headers: { connection: "keep-alive" } },
51         outputHeaders: { connection: "keep-alive" }
52       }),
53       "and response close connection header": macros.http.assertProxied({
54         request: { headers: { connection: "" } }, // Must explicitly set to "" because otherwise node will automatically add a "connection: keep-alive" header
55         targetHeaders: { connection: "close" },
56         outputHeaders: { connection: "close" }
57       }),
58       "and response keep-alive connection header": macros.http.assertProxied({
59         request: { headers: { connection: "" } }, // Must explicitly set to "" because otherwise node will automatically add a "connection: keep-alive" header
60         targetHeaders: { connection: "keep-alive" },
61         outputHeaders: { connection: "keep-alive" }
62       }),
63       "and response keep-alive connection header from http 1.0 client": macros.http.assertRawHttpProxied({
64         rawRequest: "GET / HTTP/1.0\r\n\r\n",
65         targetHeaders: { connection: "keep-alive" },
66         match: /connection: close/i
67       }),
68       "and request keep alive from http 1.0 client": macros.http.assertRawHttpProxied({
69         rawRequest: "GET / HTTP/1.0\r\nConnection: Keep-Alive\r\n\r\n",
70         targetHeaders: { connection: "keep-alive" },
71         match: /connection: keep-alive/i
72       }),
73       "and no connection header": macros.http.assertProxied({
74         request: { headers: { connection: "" } }, // Must explicitly set to "" because otherwise node will automatically add a "connection: keep-alive" header
75         outputHeaders: { connection: "keep-alive" }
76       }),
77       "and forwarding enabled": macros.http.assertForwardProxied()
78     },
79     "and latency": {
80       "and no headers": macros.http.assertProxied({
81         latency: 2000
82       }),
83       "and response headers": macros.http.assertProxied({
84         targetHeaders: { "x-testheader": "target" },
85         proxyHeaders: { "X-TestHeader": "proxy" },
86         outputHeaders: { "x-testheader": "target" },
87         latency: 1000
88       })
89     },
90     "and timeout set": macros.http.assertProxied({
91       shouldFail: true,
92       timeout: 2000,
93       requestLatency: 4000
94     })
95   },
96   "With a no valid target server": {
97     "and no latency": macros.http.assertInvalidProxy(),
98     "and latency": macros.http.assertInvalidProxy({
99       latency: 2000
100     })
101   }
102 }).export(module);