Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / http-proxy / test / helpers / index.js
1 /*
2  * index.js: Top level include for node-http-proxy helpers
3  *
4  * (C) 2010 Nodejitsu Inc.
5  * MIT LICENCE
6  *
7  */
8
9 var fs = require('fs'),
10     path = require('path');
11
12 var fixturesDir = path.join(__dirname, '..', 'fixtures');
13
14 //
15 // @https {Object}
16 // Returns the necessary `https` credentials.
17 //
18 Object.defineProperty(exports, 'https', {
19   get: function () {
20     delete this.https;
21     return this.https = {
22       key:  fs.readFileSync(path.join(fixturesDir, 'agent2-key.pem'), 'utf8'),
23       cert: fs.readFileSync(path.join(fixturesDir, 'agent2-cert.pem'), 'utf8')
24     };
25   }
26 });
27
28 //
29 // @protocols {Object}
30 // Returns an object representing the desired protocols
31 // for the `proxy` and `target` server.
32 //
33 Object.defineProperty(exports, 'protocols', {
34   get: function () {
35     delete this.protocols;
36     return this.protocols = {
37       target: exports.argv.target || 'http',
38       proxy: exports.argv.proxy || 'http'
39     };
40   }
41 });
42
43 //
44 // @nextPort {number}
45 // Returns an auto-incrementing port for tests.
46 //
47 Object.defineProperty(exports, 'nextPort', {
48   get: function () {
49     var current = this.port || 9050;
50     this.port = current + 1;
51     return current;
52   }
53 });
54
55 //
56 // @nextPortPair {Object}
57 // Returns an auto-incrementing pair of ports for tests.
58 //
59 Object.defineProperty(exports, 'nextPortPair', {
60   get: function () {
61     return {
62       target: this.nextPort,
63       proxy: this.nextPort
64     };
65   }
66 });
67
68 //
69 // ### function describe(prefix)
70 // #### @prefix {string} Prefix to use before the description
71 //
72 // Returns a string representing the protocols that this suite
73 // is testing based on CLI arguments.
74 //
75 exports.describe = function (prefix, base) {
76   prefix = prefix || '';
77   base   = base   || 'http';
78
79   function protocol(endpoint) {
80     return exports.protocols[endpoint] === 'https'
81       ? base + 's'
82       : base;
83   }
84
85   return [
86     'node-http-proxy',
87     prefix,
88     [
89       protocol('proxy'),
90       '-to-',
91       protocol('target')
92     ].join('')
93   ].filter(Boolean).join('/');
94 };
95
96 //
97 // Expose the CLI arguments
98 //
99 exports.argv = require('optimist').argv;
100
101 //
102 // Export additional helpers for `http` and `websockets`.
103 //
104 exports.http = require('./http');
105 exports.ws   = require('./ws');