This commit is contained in:
2022-09-30 05:39:11 +00:00
parent 41ee9463ae
commit 4687fa49bc
11418 changed files with 1312504 additions and 0 deletions

10
buildfiles/node_modules/global-tunnel-ng/.editorconfig generated vendored Normal file
View File

@ -0,0 +1,10 @@
root = true
[*]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@ -0,0 +1 @@
coverage

20
buildfiles/node_modules/global-tunnel-ng/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,20 @@
language: node_js
node_js:
- "node"
- "10"
- "9"
- "6"
cache:
npm: true
directories:
- node_modules
sudo: false
os:
- linux
- osx
matrix:
fast_finish: true

12
buildfiles/node_modules/global-tunnel-ng/LICENSE generated vendored Normal file
View File

@ -0,0 +1,12 @@
Copyright (c) 2013, GoInstant Inc., a salesforce.com company
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of salesforce.com, nor GoInstant, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

242
buildfiles/node_modules/global-tunnel-ng/README.md generated vendored Normal file
View File

@ -0,0 +1,242 @@
[![dependencies Status](https://david-dm.org/np-maintain/global-tunnel/status.svg)](https://david-dm.org/np-maintain/global-tunnel)
[![devDependencies Status](https://david-dm.org/np-maintain/global-tunnel/dev-status.svg)](https://david-dm.org/np-maintain/global-tunnel?type=dev)
[![Build Status](https://travis-ci.org/np-maintain/global-tunnel.png)](https://travis-ci.org/np-maintain/global-tunnel) [![Greenkeeper badge](https://badges.greenkeeper.io/np-maintain/global-tunnel.svg)](https://greenkeeper.io/)
# global-tunnel
Configures the [global
`http`](http://nodejs.org/docs/v0.10.24/api/all.html#all_http_globalagent) and
[`https`](http://nodejs.org/docs/v0.10.24/api/all.html#all_https_globalagent)
agents to use an upstream HTTP proxy.
Works transparently to tunnel modules that use node's default [`http.request()`
method](http://nodejs.org/docs/v0.10.24/api/all.html#all_http_request_options_callback)
as well as the popular [`request` module](https://npmjs.org/package/request).
# Installation
You can install this package by just executing the following:
npm install global-tunnel-ng
# Usage
To make all HTTP and HTTPS connections go through an outbound HTTP proxy:
```js
var globalTunnel = require('global-tunnel-ng');
globalTunnel.initialize({
host: '10.0.0.10',
port: 8080,
proxyAuth: 'userId:password', // optional authentication
sockets: 50 // optional pool size for each http and https
});
```
This will use the `CONNECT` method for HTTPS requests and absolute-URIs for
HTTP requests, which is how many network proxies are configured.
Optionally, to tear-down the global agent and restore node's default global
agents:
```js
globalTunnel.end();
```
Any active connections will be allowed to run to completion, but new
connections will use the default global agents.
# Advanced Usage
## Options
The complete list of options to `globalTunnel.initialize`:
- **host** - the hostname or IP of the HTTP proxy to use
- **port** - the TCP port to use on that proxy
- **connect** _(optional)_ controls what protocols use the `CONNECT` method. It
has three possible values (strings):
- **neither** - don't use `CONNECT`; just use absolute URIs
- **https** - _(the default)_ only use `CONNECT` for HTTPS requests
- **both** - use `CONNECT` for both HTTP and HTTPS requests
- **protocol** - the protocol that the proxy speaks, either `http:` or `https:`.
- **proxyAuth** - _(optional)_ to authenticate `userId:password`
- **sockets** - _(optional)_ maximum number of TCP sockets to use in each pool.
There are two pools: one for HTTP and one for HTTPS. Uses node's default (5)
if falsy.
## Variations
Here's a few interesting variations on the basic config.
### Absolute URI Proxies
Another common proxy configuration is one that expects clients to use an
[absolute URI for the
Request-URI](https://tools.ietf.org/html/rfc2616#section-5.1.2) for all HTTP
and HTTPS requests. This is common for networks that use a proxy for security
scanning and access control.
What does this mean? It means that instead of ...
```http
GET / HTTP/1.1
Host: example.com
```
... your proxy expects ...
```http
GET https://example.com/ HTTP/1.1
```
You'll need to specify `connect: 'neither'` if this is the case. If the proxy
speaks HTTP (i.e. the connection from node --> proxy is not encrypted):
```js
globalTunnel.initialize({
connect: 'neither',
host: '10.0.0.10',
port: 3128
});
```
or, if the proxy speaks HTTPS to your app instead:
```js
globalTunnel.initialize({
connect: 'neither',
protocol: 'https:',
host: '10.0.0.10',
port: 3129
});
```
### Always-CONNECT Proxies
If the proxy expects you to use the `CONNECT` method for both HTTP and HTTPS
requests, you'll need the `connect: 'both'` option.
What does this mean? It means that instead of ...
```http
GET https://example.com/ HTTP/1.1
```
... your proxy expects ...
```http
CONNECT example.com:443 HTTP/1.1
```
Be sure to set the `protocol:` option based on what protocol the proxy speaks.
```js
globalTunnel.initialize({
connect: 'both',
host: '10.0.0.10',
port: 3130
});
```
### HTTPS configuration
_EXPERIMENTAL_
If tunnelling both protocols, you can use different HTTPS client configurations
for the two phases of the connection.
```js
globalTunnel.initialize({
connect: 'both',
protocol: 'https:'
host: '10.0.0.10',
port: 3130,
proxyHttpsOptions: {
// use this config for app -> proxy
},
originHttpsOptions: {
// use this config for proxy -> origin
}
});
```
## Auto-Config
If `globalTunnel.initialize` doesnt receive a configuration as its first parameter the `http_proxys` and `http_proxy` environment variables will be used.
If these are missing the npm configurations `https-proxy`, `http-proxy`, `proxy` will be used instead.
If no environment variables or npm configurations are found nothing will be done.
## Retrieving proxy URL, parsed config and proxy status
As the module does some extra job determining the proxy (including parsing the environment variables) and does some normalization (like defaulting the protocol to `http:`) it may be useful to retrieve the proxy URL used by the module.
The property `globalTunnel.proxyUrl` is the URL-formatted (including the optional basic auth if provided) proxy config currently in use. It is `null` if the proxy is not currently enabled.
Similarly, the `globalTunnel.proxyConfig` contains the entire parsed and normalized config.
The property `globalTunnel.isProxying` contains the information about whether the global proxy is on or off.
# Compatibility
Any module that doesn't specify [an explicit `agent:` option to
`http.request`](http://nodejs.org/docs/v0.10.24/api/all.html#all_http_request_options_callback)
will also work with global-tunnel.
The unit tests for this module verify that the popular [`request`
module](https://npmjs.org/package/request) works with global-tunnel active.
For untested modules, it's recommended that you load and initialize
global-tunnel first. This way, any copies of `http.globalAgent` will point to
the right thing.
# Contributing
If you'd like to contribute to or modify global-tunnel, here's a quick guide
to get you started.
## Development Dependencies
- [node.js](http://nodejs.org) >= 0.10
## Set-Up
Download via GitHub and install npm dependencies:
```sh
git clone git@github.com:np-maintain/global-tunnel.git
cd global-tunnel
npm install
```
## Testing
Testing is with the [mocha](https://github.com/visionmedia/mocha) framework.
Tests are located in the `test/` directory.
To run the tests:
```sh
npm test
```
# Support
As this is a hard fork, you may still contact the given contacts below.
Email [GoInstant Support](mailto:support@goinstant.com) or stop by [#goinstant on freenode](irc://irc.freenode.net#goinstant).
For responsible disclosures, email [GoInstant Security](mailto:security@goinstant.com).
To [file a bug](https://github.com/np-maintain/global-tunnel/issues) or
[propose a patch](https://github.com/np-maintain/global-tunnel/pulls),
please use github directly.
# Legal
© 2014 GoInstant Inc., a salesforce.com company
Licensed under the BSD 3-clause license.

348
buildfiles/node_modules/global-tunnel-ng/index.js generated vendored Normal file
View File

@ -0,0 +1,348 @@
/* jshint node:true */
'use strict';
/**
* @fileOverview
* Global proxy settings.
*/
var globalTunnel = exports;
exports.constructor = function() {};
var http = require('http');
var https = require('https');
var urlParse = require('url').parse;
var urlStringify = require('url').format;
var pick = require('lodash/pick');
var assign = require('lodash/assign');
var clone = require('lodash/clone');
var tunnel = require('tunnel');
var npmConfig = require('npm-conf');
var encodeUrl = require('encodeurl');
var agents = require('./lib/agents');
exports.agents = agents;
var ENV_VAR_PROXY_SEARCH_ORDER = [
'https_proxy',
'HTTPS_PROXY',
'http_proxy',
'HTTP_PROXY'
];
var NPM_CONFIG_PROXY_SEARCH_ORDER = ['https-proxy', 'http-proxy', 'proxy'];
// Save the original settings for restoration later.
var ORIGINALS = {
http: pick(http, 'globalAgent', ['request', 'get']),
https: pick(https, 'globalAgent', ['request', 'get']),
env: pick(process.env, ENV_VAR_PROXY_SEARCH_ORDER)
};
var loggingEnabled =
process &&
process.env &&
process.env.DEBUG &&
process.env.DEBUG.toLowerCase().indexOf('global-tunnel') !== -1 &&
console &&
typeof console.log === 'function';
function log(message) {
if (loggingEnabled) {
console.log('DEBUG global-tunnel: ' + message);
}
}
function resetGlobals() {
assign(http, ORIGINALS.http);
assign(https, ORIGINALS.https);
var val;
for (var key in ORIGINALS.env) {
if (Object.prototype.hasOwnProperty.call(ORIGINALS.env, key)) {
val = ORIGINALS.env[key];
if (val !== null && val !== undefined) {
process.env[key] = val;
}
}
}
}
/**
* Parses the de facto `http_proxy` environment.
*/
function tryParse(url) {
if (!url) {
return null;
}
var parsed = urlParse(url);
return {
protocol: parsed.protocol,
host: parsed.hostname,
port: parseInt(parsed.port, 10),
proxyAuth: parsed.auth
};
}
// Stringifies the normalized parsed config
function stringifyProxy(conf) {
return encodeUrl(
urlStringify({
protocol: conf.protocol,
hostname: conf.host,
port: conf.port,
auth: conf.proxyAuth
})
);
}
globalTunnel.isProxying = false;
globalTunnel.proxyUrl = null;
globalTunnel.proxyConfig = null;
function findEnvVarProxy() {
var i;
var key;
var val;
var result;
for (i = 0; i < ENV_VAR_PROXY_SEARCH_ORDER.length; i++) {
key = ENV_VAR_PROXY_SEARCH_ORDER[i];
val = process.env[key];
if (val !== null && val !== undefined) {
// Get the first non-empty
result = result || val;
// Delete all
// NB: we do it here to prevent double proxy handling (and for example path change)
// by us and the `request` module or other sub-dependencies
delete process.env[key];
log('Found proxy in environment variable ' + ENV_VAR_PROXY_SEARCH_ORDER[i]);
}
}
if (!result) {
// __GLOBAL_TUNNEL_DEPENDENCY_NPMCONF__ is a hook to override the npm-conf module
var config =
(global.__GLOBAL_TUNNEL_DEPENDENCY_NPMCONF__ &&
global.__GLOBAL_TUNNEL_DEPENDENCY_NPMCONF__()) ||
npmConfig();
for (i = 0; i < NPM_CONFIG_PROXY_SEARCH_ORDER.length && !val; i++) {
val = config.get(NPM_CONFIG_PROXY_SEARCH_ORDER[i]);
}
if (val) {
log('Found proxy in npm config ' + NPM_CONFIG_PROXY_SEARCH_ORDER[i]);
result = val;
}
}
return result;
}
/**
* Overrides the node http/https `globalAgent`s to use the configured proxy.
*
* If the config is empty, the `http_proxy` environment variable is checked.
* If that's not present, the NPM `http-proxy` configuration is checked.
* If neither are present no proxying will be enabled.
*
* @param {object} conf - Options
* @param {string} conf.host - Hostname or IP of the HTTP proxy to use
* @param {int} conf.port - TCP port of the proxy
* @param {string} [conf.protocol='http'] - The protocol of the proxy, 'http' or 'https'
* @param {string} [conf.proxyAuth] - Credentials for the proxy in the form userId:password
* @param {string} [conf.connect='https'] - Which protocols will use the CONNECT method 'neither', 'https' or 'both'
* @param {int} [conf.sockets=5] Maximum number of TCP sockets to use in each pool. There are two different pools for HTTP and HTTPS
* @param {object} [conf.httpsOptions] - HTTPS options
*/
globalTunnel.initialize = function(conf) {
// Don't do anything if already proxying.
// To change the settings `.end()` should be called first.
if (globalTunnel.isProxying) {
log('Already proxying');
return;
}
try {
// This has an effect of also removing the proxy config
// from the global env to prevent other modules (like request) doing
// double handling
var envVarProxy = findEnvVarProxy();
if (conf && typeof conf === 'string') {
// Passed string - parse it as a URL
conf = tryParse(conf);
} else if (conf) {
// Passed object - take it but clone for future mutations
conf = clone(conf);
} else if (envVarProxy) {
// Nothing passed - parse from the env
conf = tryParse(envVarProxy);
} else {
log('No configuration found, not proxying');
// No config - do nothing
return;
}
log('Proxy configuration to be used is ' + JSON.stringify(conf, null, 2));
if (!conf.host) {
throw new Error('upstream proxy host is required');
}
if (!conf.port) {
throw new Error('upstream proxy port is required');
}
if (conf.protocol === undefined) {
conf.protocol = 'http:'; // Default to proxy speaking http
}
if (!/:$/.test(conf.protocol)) {
conf.protocol += ':';
}
if (!conf.connect) {
conf.connect = 'https'; // Just HTTPS by default
}
if (['both', 'neither', 'https'].indexOf(conf.connect) < 0) {
throw new Error('valid connect options are "neither", "https", or "both"');
}
var connectHttp = conf.connect === 'both';
var connectHttps = conf.connect !== 'neither';
if (conf.httpsOptions) {
conf.innerHttpsOpts = conf.httpsOptions;
conf.outerHttpsOpts = conf.innerHttpsOpts;
}
http.globalAgent = globalTunnel._makeAgent(conf, 'http', connectHttp);
https.globalAgent = globalTunnel._makeAgent(conf, 'https', connectHttps);
http.request = globalTunnel._makeHttp('request', http, 'http');
https.request = globalTunnel._makeHttp('request', https, 'https');
http.get = globalTunnel._makeHttp('get', http, 'http');
https.get = globalTunnel._makeHttp('get', https, 'https');
globalTunnel.isProxying = true;
globalTunnel.proxyUrl = stringifyProxy(conf);
globalTunnel.proxyConfig = clone(conf);
} catch (e) {
resetGlobals();
throw e;
}
};
var _makeAgent = function(conf, innerProtocol, useCONNECT) {
log('Creating proxying agent');
var outerProtocol = conf.protocol;
innerProtocol += ':';
var opts = {
proxy: pick(conf, 'host', 'port', 'protocol', 'localAddress', 'proxyAuth'),
maxSockets: conf.sockets
};
opts.proxy.innerProtocol = innerProtocol;
if (useCONNECT) {
if (conf.proxyHttpsOptions) {
assign(opts.proxy, conf.proxyHttpsOptions);
}
if (conf.originHttpsOptions) {
assign(opts, conf.originHttpsOptions);
}
if (outerProtocol === 'https:') {
if (innerProtocol === 'https:') {
return tunnel.httpsOverHttps(opts);
}
return tunnel.httpOverHttps(opts);
}
if (innerProtocol === 'https:') {
return tunnel.httpsOverHttp(opts);
}
return tunnel.httpOverHttp(opts);
}
if (conf.originHttpsOptions) {
throw new Error('originHttpsOptions must be combined with a tunnel:true option');
}
if (conf.proxyHttpsOptions) {
// NB: not opts.
assign(opts, conf.proxyHttpsOptions);
}
if (outerProtocol === 'https:') {
return new agents.OuterHttpsAgent(opts);
}
return new agents.OuterHttpAgent(opts);
};
/**
* Construct an agent based on:
* - is the connection to the proxy secure?
* - is the connection to the origin secure?
* - the address of the proxy
*/
globalTunnel._makeAgent = function(conf, innerProtocol, useCONNECT) {
var agent = _makeAgent(conf, innerProtocol, useCONNECT);
// Set the protocol to match that of the target request type
agent.protocol = innerProtocol + ':';
return agent;
};
/**
* Override for http/https, makes sure to default the agent
* to the global agent. Due to how node implements it in lib/http.js, the
* globalAgent we define won't get used (node uses a module-scoped variable,
* not the exports field).
* @param {string} method 'request' or 'get', http/https methods
* @param {string|object} options http/https request url or options
* @param {function} [cb]
* @private
*/
globalTunnel._makeHttp = function(method, httpOrHttps, protocol) {
return function(options, callback) {
if (typeof options === 'string') {
options = urlParse(options);
} else {
options = clone(options);
}
// Respect the default agent provided by node's lib/https.js
if (
(options.agent === null || options.agent === undefined) &&
typeof options.createConnection !== 'function' &&
(options.host || options.hostname)
) {
options.agent = options._defaultAgent || httpOrHttps.globalAgent;
}
// Set the default port ourselves to prevent Node doing it based on the proxy agent protocol
if (options.protocol === 'https:' || (!options.protocol && protocol === 'https')) {
options.port = options.port || 443;
}
if (options.protocol === 'http:' || (!options.protocol && protocol === 'http')) {
options.port = options.port || 80;
}
log(
'Requesting to ' +
(options.protocol || protocol) +
'//' +
(options.host || options.hostname) +
':' +
options.port
);
return ORIGINALS[protocol][method].call(httpOrHttps, options, callback);
};
};
/**
* Restores global http/https agents.
*/
globalTunnel.end = function() {
resetGlobals();
globalTunnel.isProxying = false;
globalTunnel.proxyUrl = null;
globalTunnel.proxyConfig = null;
};

52
buildfiles/node_modules/global-tunnel-ng/lib/agents.js generated vendored Normal file
View File

@ -0,0 +1,52 @@
/* jshint node:true */
'use strict';
var util = require('util');
var http = require('http');
var HttpAgent = http.Agent;
var https = require('https');
var HttpsAgent = https.Agent;
var pick = require('lodash/pick');
/**
* Proxy some traffic over HTTP.
*/
function OuterHttpAgent(opts) {
HttpAgent.call(this, opts);
mixinProxying(this, opts.proxy);
}
util.inherits(OuterHttpAgent, HttpAgent);
exports.OuterHttpAgent = OuterHttpAgent;
/**
* Proxy some traffic over HTTPS.
*/
function OuterHttpsAgent(opts) {
HttpsAgent.call(this, opts);
mixinProxying(this, opts.proxy);
}
util.inherits(OuterHttpsAgent, HttpsAgent);
exports.OuterHttpsAgent = OuterHttpsAgent;
/**
* Override createConnection and addRequest methods on the supplied agent.
* http.Agent and https.Agent will set up createConnection in the constructor.
*/
function mixinProxying(agent, proxyOpts) {
agent.proxy = proxyOpts;
var orig = pick(agent, 'createConnection', 'addRequest');
// Make the tcp or tls connection go to the proxy, ignoring the
// destination host:port arguments.
agent.createConnection = function(port, host, options) {
return orig.createConnection.call(this, this.proxy.port, this.proxy.host, options);
};
agent.addRequest = function(req, options) {
req.path =
this.proxy.innerProtocol + '//' + options.host + ':' + options.port + req.path;
return orig.addRequest.call(this, req, options);
};
}

94
buildfiles/node_modules/global-tunnel-ng/package.json generated vendored Normal file
View File

@ -0,0 +1,94 @@
{
"_from": "global-tunnel-ng@^2.7.1",
"_id": "global-tunnel-ng@2.7.1",
"_inBundle": false,
"_integrity": "sha512-4s+DyciWBV0eK148wqXxcmVAbFVPqtc3sEtUE/GTQfuU80rySLcMhUmHKSHI7/LDj8q0gDYI1lIhRRB7ieRAqg==",
"_location": "/global-tunnel-ng",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "global-tunnel-ng@^2.7.1",
"name": "global-tunnel-ng",
"escapedName": "global-tunnel-ng",
"rawSpec": "^2.7.1",
"saveSpec": null,
"fetchSpec": "^2.7.1"
},
"_requiredBy": [
"/@electron/get"
],
"_resolved": "https://registry.npmjs.org/global-tunnel-ng/-/global-tunnel-ng-2.7.1.tgz",
"_shasum": "d03b5102dfde3a69914f5ee7d86761ca35d57d8f",
"_spec": "global-tunnel-ng@^2.7.1",
"_where": "/home/shihaam/www/freezer.shihaam.me/node_modules/@electron/get",
"author": {
"name": "GoInstant Inc., a salesforce.com company"
},
"bugs": {
"url": "https://github.com/np-maintain/global-tunnel/issues"
},
"bundleDependencies": false,
"dependencies": {
"encodeurl": "^1.0.2",
"lodash": "^4.17.10",
"npm-conf": "^1.1.3",
"tunnel": "^0.0.6"
},
"deprecated": false,
"description": "Global HTTP & HTTPS tunneling",
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^5.1.0",
"eslint-config-prettier": "^3.0.0",
"eslint-config-xo": "^0.25.0",
"eslint-plugin-prettier": "^3.0.0",
"mocha": "^5.2.0",
"prettier": "^1.13.7",
"request": "^2.83.0",
"sinon": "^6.0.1"
},
"engines": {
"node": ">=0.10"
},
"eslintConfig": {
"extends": [
"xo",
"prettier"
],
"env": {
"mocha": true,
"node": true
},
"rules": {
"prettier/prettier": [
"error",
{
"singleQuote": true,
"printWidth": 90
}
]
},
"plugins": [
"prettier"
]
},
"homepage": "https://github.com/np-maintain/global-tunnel#readme",
"keywords": [
"http",
"https",
"tunnel",
"global"
],
"license": "BSD-3-Clause",
"main": "index.js",
"name": "global-tunnel-ng",
"repository": {
"type": "git",
"url": "git+https://github.com/np-maintain/global-tunnel.git"
},
"scripts": {
"test": "mocha test"
},
"version": "2.7.1"
}

View File

@ -0,0 +1,71 @@
// Use this tests for troubleshooting, you'll need a proxy runnig at an endpoint
// The idea is to make sure the tests pass if the proxy is turned on, that means the requests are resolving
// And also the tests should fail if the proxy is turned off, that means the requests are actually being proxied
const globalTunnel = require('../index');
const assert = require('chai').assert;
const request = require('request');
const http = require('http');
const https = require('https');
// You need to have a proxy running at the Proxy URL.
const proxyUrl = 'http://localhost:8080';
const resourceUrl = 'www.google.com';
describe.skip('end-to-end tests', () => {
beforeEach(() => {
globalTunnel.initialize(proxyUrl);
});
const httpResourceUrl = (secure = false) => `http${secure ? 's' : ''}://${resourceUrl}`;
const testHttp = (httpMethod = 'request') => (secure = false) => () =>
new Promise((resolve, reject) => {
const request = (secure ? https : http)[httpMethod](
httpResourceUrl(secure),
response => {
assert.isAtLeast(response.statusCode, 200);
assert.isBelow(response.statusCode, 300);
let buffer = Buffer.alloc(0);
response.on('data', chunk => {
buffer = Buffer.concat([buffer, chunk]);
});
response.on('end', () => {
assert.isNotEmpty(buffer.toString());
resolve();
});
}
);
request.on('error', reject);
if (httpMethod === 'request') {
request.end();
}
});
const testHttpRequest = testHttp();
const testHttpGet = testHttp('get');
it('proxies http.get', testHttpGet());
it('proxies https.get', testHttpGet(true));
it('proxies http.request', testHttpRequest());
it('proxies https.request', testHttpRequest(true));
it('proxies request', () =>
new Promise((resolve, reject) => {
request.get({ url: httpResourceUrl(true) }, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
}));
afterEach(() => {
globalTunnel.end();
});
});

535
buildfiles/node_modules/global-tunnel-ng/test/index.js generated vendored Normal file
View File

@ -0,0 +1,535 @@
'use strict';
var assert = require('chai').assert;
var sinon = require('sinon');
var assign = require('lodash/assign');
var pick = require('lodash/pick');
// Deliberate: node and 3rd party modules before global-tunnel
var EventEmitter = require('events').EventEmitter;
var net = require('net');
var tls = require('tls');
var http = require('http');
var globalHttpAgent = http.globalAgent;
var https = require('https');
var globalHttpsAgent = https.globalAgent;
var request = require('request');
// Deliberate: load after all 3rd party modules
var globalTunnel = require('../index');
function newFakeAgent() {
var fakeAgent = {
addRequest: sinon.stub()
};
return fakeAgent;
}
// This function replaces 'host' by 'hostname' in the options for http.request()
// background: http.request() allows to use either 'host' or 'hostname' to be used,
// both needs to be tested
function replaceHostByHostname(useHostname, options) {
if (useHostname) {
options.hostname = options.host;
delete options.host;
}
return options;
}
var origEnv;
function saveEnv() {
origEnv = process.env.http_proxy;
delete process.env.http_proxy;
}
function restoreEnv() {
if (origEnv !== undefined) {
process.env.http_proxy = origEnv; // eslint-disable-line camelcase
}
}
describe('global-proxy', function() {
// Save and restore http_proxy environment variable (yes, it's lower-case by
// convention).
before(saveEnv);
after(restoreEnv);
// Sinon setup & teardown
var sandbox;
var origHttpCreateConnection;
before(function() {
sandbox = sinon.createSandbox();
sandbox.stub(globalHttpAgent, 'addRequest');
sandbox.stub(globalHttpsAgent, 'addRequest');
assert.equal(http.Agent.prototype.addRequest, https.Agent.prototype.addRequest);
sandbox.spy(http.Agent.prototype, 'addRequest');
sandbox.stub(net, 'createConnection').callsFake(function() {
return new EventEmitter();
});
sandbox.stub(tls, 'connect').callsFake(function() {
return new EventEmitter();
});
// This is needed as at some point Node HTTP aggent implementation started
// plucking the createConnection method from the `net` module
// instead of doing `net.createConnection`
origHttpCreateConnection = http.Agent.prototype.createConnection;
http.Agent.prototype.createConnection = net.createConnection;
});
afterEach(function() {
sandbox.resetHistory();
});
after(function() {
sandbox.restore();
http.Agent.prototype.createConnection = origHttpCreateConnection;
});
describe('invalid configs', function() {
it('requires a host', function() {
var conf = { host: null, port: 1234 };
assert.throws(function() {
globalTunnel.initialize(conf);
}, 'upstream proxy host is required');
globalTunnel.end();
});
it('requires a port', function() {
var conf = { host: '10.2.3.4', port: 0 };
assert.throws(function() {
globalTunnel.initialize(conf);
}, 'upstream proxy port is required');
globalTunnel.end();
});
it('clamps tunnel types', function() {
var conf = { host: '10.2.3.4', port: 1234, connect: 'INVALID' };
assert.throws(function() {
globalTunnel.initialize(conf);
}, 'valid connect options are "neither", "https", or "both"');
globalTunnel.end();
});
});
describe('exposed config', function() {
afterEach(function() {
globalTunnel.end();
});
it('has the same params as the passed config', function() {
var conf = {
host: 'proxy.com',
port: 1234,
proxyAuth: 'user:pwd',
protocol: 'https:'
};
globalTunnel.initialize(conf);
assert.deepEqual(
conf,
pick(globalTunnel.proxyConfig, ['host', 'port', 'proxyAuth', 'protocol'])
);
});
it('has the expected defaults', function() {
var conf = { host: 'proxy.com', port: 1234, proxyAuth: 'user:pwd' };
globalTunnel.initialize(conf);
assert.equal(globalTunnel.proxyConfig.protocol, 'http:');
});
});
describe('stringified config', function() {
afterEach(function() {
globalTunnel.end();
});
it('has the same params as the passed config', function() {
var conf = {
host: 'proxy.com',
port: 1234,
proxyAuth: 'user:pwd',
protocol: 'https'
};
globalTunnel.initialize(conf);
assert.equal(globalTunnel.proxyUrl, 'https://user:pwd@proxy.com:1234');
});
it('encodes url', function() {
var conf = {
host: 'proxy.com',
port: 1234,
proxyAuth: 'user:4P@S$W0_r-D',
protocol: 'https'
};
globalTunnel.initialize(conf);
assert.equal(globalTunnel.proxyUrl, 'https://user:4P%40S%24W0_r-D@proxy.com:1234');
});
});
function proxyEnabledTests(testParams) {
function connected(innerProto) {
var innerSecure = innerProto === 'https:';
var called;
if (testParams.isHttpsProxy) {
called = tls.connect;
sinon.assert.notCalled(net.createConnection);
} else {
called = net.createConnection;
sinon.assert.notCalled(tls.connect);
}
sinon.assert.calledOnce(called);
if (typeof called.getCall(0).args[0] === 'object') {
sinon.assert.calledWith(called, sinon.match.has('port', testParams.port));
sinon.assert.calledWith(called, sinon.match.has('host', '10.2.3.4'));
} else {
sinon.assert.calledWith(called, testParams.port, '10.2.3.4');
}
var isCONNECT =
testParams.connect === 'both' || (innerSecure && testParams.connect === 'https');
if (isCONNECT) {
var expectConnect = 'example.dev:' + (innerSecure ? 443 : 80);
var whichAgent = innerSecure ? https.globalAgent : http.globalAgent;
sinon.assert.calledOnce(whichAgent.request);
sinon.assert.calledWith(whichAgent.request, sinon.match.has('method', 'CONNECT'));
sinon.assert.calledWith(
whichAgent.request,
sinon.match.has('path', expectConnect)
);
} else {
sinon.assert.calledOnce(http.Agent.prototype.addRequest);
var req = http.Agent.prototype.addRequest.getCall(0).args[0];
var method = req.method;
assert.equal(method, 'GET');
var path = req.path;
if (innerSecure) {
assert.match(path, new RegExp('^https://example\\.dev:443/'));
} else {
assert.match(path, new RegExp('^http://example\\.dev:80/'));
}
}
}
var localSandbox;
beforeEach(function() {
localSandbox = sinon.createSandbox();
if (testParams.connect === 'both') {
localSandbox.spy(http.globalAgent, 'request');
}
if (testParams.connect !== 'neither') {
localSandbox.spy(https.globalAgent, 'request');
}
});
afterEach(function() {
localSandbox.restore();
});
it('(got proxying set up)', function() {
assert.isTrue(globalTunnel.isProxying);
});
describe('with the request library', function() {
it('will proxy http requests', function(done) {
assert.isTrue(globalTunnel.isProxying);
var dummyCb = sinon.stub();
request.get('http://example.dev/', dummyCb);
setImmediate(function() {
connected('http:');
sinon.assert.notCalled(globalHttpAgent.addRequest);
sinon.assert.notCalled(globalHttpsAgent.addRequest);
done();
});
});
it('will proxy https requests', function(done) {
assert.isTrue(globalTunnel.isProxying);
var dummyCb = sinon.stub();
request.get('https://example.dev/', dummyCb);
setImmediate(function() {
connected('https:');
sinon.assert.notCalled(globalHttpAgent.addRequest);
sinon.assert.notCalled(globalHttpsAgent.addRequest);
done();
});
});
});
describe('using raw request interface', function() {
function rawRequest(useHostname) {
var req = http.request(
replaceHostByHostname(useHostname, {
method: 'GET',
path: '/raw-http',
host: 'example.dev'
}),
function() {}
);
req.end();
connected('http:');
sinon.assert.notCalled(globalHttpAgent.addRequest);
sinon.assert.notCalled(globalHttpsAgent.addRequest);
}
it('will proxy http requests (`host`)', function() {
rawRequest(false);
});
it('will proxy http requests (`hostname`)', function() {
rawRequest(true);
});
it('will proxy https requests', function() {
var req = https.request(
replaceHostByHostname(false, {
method: 'GET',
path: '/raw-https',
host: 'example.dev'
}),
function() {}
);
req.end();
connected('https:');
sinon.assert.notCalled(globalHttpAgent.addRequest);
sinon.assert.notCalled(globalHttpsAgent.addRequest);
});
it('request respects explicit agent param', function() {
var agent = newFakeAgent();
var req = http.request(
replaceHostByHostname(false, {
method: 'GET',
path: '/raw-http-w-agent',
host: 'example.dev',
agent: agent
}),
function() {}
);
req.end();
sinon.assert.notCalled(globalHttpAgent.addRequest);
sinon.assert.notCalled(globalHttpsAgent.addRequest);
sinon.assert.notCalled(net.createConnection);
sinon.assert.notCalled(tls.connect);
sinon.assert.calledOnce(agent.addRequest);
});
describe('request with `null` agent and defined `createConnection`', function() {
before(function() {
sinon.stub(http.ClientRequest.prototype, 'onSocket');
});
after(function() {
http.ClientRequest.prototype.onSocket.restore();
});
function noAgent(useHostname) {
var createConnection = sinon.stub();
var req = http.request(
replaceHostByHostname(useHostname, {
method: 'GET',
path: '/no-agent',
host: 'example.dev',
agent: null,
createConnection: createConnection
}),
function() {} // eslint-disable-line max-nested-callbacks
);
req.end();
sinon.assert.notCalled(globalHttpAgent.addRequest);
sinon.assert.notCalled(globalHttpsAgent.addRequest);
sinon.assert.calledOnce(createConnection);
}
it('uses no agent (`host`)', function() {
noAgent(false);
});
it('uses no agent (`hostname`)', function() {
noAgent(true);
});
});
});
}
function enabledBlock(conf, testParams) {
before(function() {
globalTunnel.initialize(conf);
});
after(function() {
globalTunnel.end();
});
testParams = assign(
{
port: conf && conf.port,
isHttpsProxy: conf && conf.protocol === 'https:',
connect: (conf && conf.connect) || 'https'
},
testParams
);
proxyEnabledTests(testParams);
}
describe('with http proxy in intercept mode', function() {
enabledBlock({
connect: 'neither',
protocol: 'http:',
host: '10.2.3.4',
port: 3333
});
});
describe('with https proxy in intercept mode', function() {
enabledBlock({
connect: 'neither',
protocol: 'https:',
host: '10.2.3.4',
port: 3334
});
});
describe('with http proxy in CONNECT mode', function() {
enabledBlock({
connect: 'both',
protocol: 'http:',
host: '10.2.3.4',
port: 3335
});
});
describe('with https proxy in CONNECT mode', function() {
enabledBlock({
connect: 'both',
protocol: 'https:',
host: '10.2.3.4',
port: 3336
});
});
describe('with http proxy in mixed mode', function() {
enabledBlock({
protocol: 'http:',
host: '10.2.3.4',
port: 3337
});
});
describe('with https proxy in mixed mode', function() {
enabledBlock({
protocol: 'https:',
host: '10.2.3.4',
port: 3338
});
});
describe('using env var', function() {
after(function() {
delete process.env.http_proxy;
assert.isUndefined(process.env.http_proxy);
});
describe('for http', function() {
before(function() {
process.env.http_proxy = 'http://10.2.3.4:1234'; // eslint-disable-line camelcase
});
enabledBlock(null, { isHttpsProxy: false, connect: 'https', port: 1234 });
});
describe('for https', function() {
before(function() {
process.env.http_proxy = 'https://10.2.3.4:1235'; // eslint-disable-line camelcase
});
enabledBlock(null, { isHttpsProxy: true, connect: 'https', port: 1235 });
});
});
describe('using npm config', function() {
var expectedProxy = { isHttpsProxy: false, connect: 'https', port: 1234 };
var npmConfig = { get: function() {} };
var npmConfigStub = sinon.stub(npmConfig, 'get');
function configNpm(key, value) {
return function() {
global.__GLOBAL_TUNNEL_DEPENDENCY_NPMCONF__ = function() {
return npmConfig;
};
npmConfigStub.withArgs(key).returns(value || 'http://10.2.3.4:1234');
};
}
after(function() {
global.__GLOBAL_TUNNEL_DEPENDENCY_NPMCONF__ = undefined;
});
describe('https-proxy', function() {
before(configNpm('https-proxy'));
enabledBlock(null, expectedProxy);
});
describe('http-proxy', function() {
before(configNpm('http-proxy'));
enabledBlock(null, expectedProxy);
});
describe('proxy', function() {
before(configNpm('proxy'));
enabledBlock(null, expectedProxy);
});
describe('order', function() {
before(function() {
configNpm('proxy')();
configNpm('https-proxy', 'http://10.2.3.4:12345')();
configNpm('http-proxy')();
});
enabledBlock(null, { isHttpsProxy: false, connect: 'https', port: 12345 });
});
describe('also using env var', function() {
before(function() {
configNpm('proxy')();
process.env.http_proxy = 'http://10.2.3.4:1234'; // eslint-disable-line camelcase
});
after(function() {
delete process.env.http_proxy;
});
enabledBlock(null, expectedProxy);
});
});
// Deliberately after the block above
describe('with proxy disabled', function() {
it('claims to be disabled', function() {
assert.isFalse(globalTunnel.isProxying);
});
it('will NOT proxy http requests', function(done) {
var dummyCb = sinon.stub();
request.get('http://example.dev/', dummyCb);
setImmediate(function() {
sinon.assert.calledOnce(globalHttpAgent.addRequest);
sinon.assert.notCalled(globalHttpsAgent.addRequest);
done();
});
});
it('will NOT proxy https requests', function(done) {
var dummyCb = sinon.stub();
request.get('https://example.dev/', dummyCb);
setImmediate(function() {
sinon.assert.notCalled(globalHttpAgent.addRequest);
sinon.assert.calledOnce(globalHttpsAgent.addRequest);
done();
});
});
});
});