flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
8
VISUALIZACION/node_modules/hpagent/.github/dependabot.yml
generated
vendored
Executable file
8
VISUALIZACION/node_modules/hpagent/.github/dependabot.yml
generated
vendored
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "04:00"
|
||||
open-pull-requests-limit: 10
|
||||
36
VISUALIZACION/node_modules/hpagent/.github/workflows/build.yml
generated
vendored
Executable file
36
VISUALIZACION/node_modules/hpagent/.github/workflows/build.yml
generated
vendored
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
name: build
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
NODE_EXTRA_CA_CERTS: test/fixtures/certs_unit_test.pem
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [14.x, 16.x, 18.x]
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
npm install
|
||||
|
||||
- name: Test / 1
|
||||
run: |
|
||||
npm run test-ci
|
||||
|
||||
- name: Test / 2
|
||||
run: |
|
||||
./test/hang-socket/runner.sh
|
||||
21
VISUALIZACION/node_modules/hpagent/LICENSE
generated
vendored
Executable file
21
VISUALIZACION/node_modules/hpagent/LICENSE
generated
vendored
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 Tomas Della Vedova
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
165
VISUALIZACION/node_modules/hpagent/README.md
generated
vendored
Executable file
165
VISUALIZACION/node_modules/hpagent/README.md
generated
vendored
Executable file
|
|
@ -0,0 +1,165 @@
|
|||
# hpagent
|
||||
|
||||
[](http://standardjs.com/) . 
|
||||
|
||||
A ready to use http and https agent for working with proxies that keeps connections alive!
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install hpagent
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Based on your infrastructure, you should use the http agent or the https agent.
|
||||
The following table will help you picking the right one.
|
||||
|
||||
| Type | Proxy | Server |
|
||||
|-------------------|--------|--------|
|
||||
| `HttpProxyAgent` | HTTP | HTTP |
|
||||
| `HttpProxyAgent` | HTTPS | HTTP |
|
||||
| `HttpsProxyAgent` | HTTP | HTTPS |
|
||||
| `HttpsProxyAgent` | HTTPS | HTTPS |
|
||||
|
||||
```js
|
||||
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent')
|
||||
```
|
||||
|
||||
Once you have understood the right agent for your use case, you can instance it. It takes the same parameter of the Node.js core's http(s) agent and an additional `proxy` option, which is the url of your proxy.
|
||||
|
||||
```js
|
||||
const http = require('http')
|
||||
const { HttpProxyAgent } = require('hpagent')
|
||||
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
proxy: 'http://localhost:8080'
|
||||
})
|
||||
|
||||
http.get('http://localhost:9200', { agent })
|
||||
.on('response', console.log)
|
||||
.end()
|
||||
```
|
||||
|
||||
If your proxy requires basic authentication, you can configure it in the proxy url:
|
||||
|
||||
```js
|
||||
const http = require('http')
|
||||
const { HttpProxyAgent } = require('hpagent')
|
||||
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
proxy: 'http://user:pwd@localhost:8080'
|
||||
})
|
||||
|
||||
http.get('http://localhost:9200', { agent })
|
||||
.on('response', console.log)
|
||||
.end()
|
||||
```
|
||||
|
||||
You can also pass custom options intended only for the proxy CONNECT request with the `proxyConnectOptions` option,
|
||||
such as headers or `tls.connect()` options:
|
||||
|
||||
```js
|
||||
const fs = require('fs')
|
||||
const http = require('http')
|
||||
const { HttpProxyAgent } = require('hpagent')
|
||||
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
proxy: 'https://localhost:8080',
|
||||
proxyConnectOptions: {
|
||||
headers: {
|
||||
'Proxy-Authorization': 'Basic YWxhZGRpbjpvcGVuc2VzYW1l',
|
||||
},
|
||||
ca: [ fs.readFileSync('custom-proxy-cert.pem') ]
|
||||
}
|
||||
})
|
||||
|
||||
http.get('http://localhost:9200', { agent })
|
||||
.on('response', console.log)
|
||||
.end()
|
||||
```
|
||||
|
||||
## Integrations
|
||||
|
||||
Following you can find the list of userland http libraries that are tested with this agent.
|
||||
|
||||
### [got](https://github.com/sindresorhus/got)
|
||||
|
||||
```js
|
||||
got('http://localhost:9200', {
|
||||
agent: {
|
||||
http: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: 'http://localhost:8080'
|
||||
})
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### [needle](https://github.com/tomas/needle)
|
||||
|
||||
```js
|
||||
needle('get', 'http://localhost:9200', {
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: 'http://localhost:8080'
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
### [node-fetch](https://github.com/node-fetch/node-fetch)
|
||||
|
||||
```js
|
||||
fetch('http://localhost:9200', {
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: 'http://localhost:8080'
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
### [simple-get](https://github.com/feross/simple-get)
|
||||
|
||||
```js
|
||||
sget.concat({
|
||||
url: `http://${server.address().address}:${server.address().port}`,
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
}, function (err, response, data) {
|
||||
// handle the response
|
||||
})
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This software is licensed under the [MIT](./LICENSE).
|
||||
35
VISUALIZACION/node_modules/hpagent/index.d.ts
generated
vendored
Executable file
35
VISUALIZACION/node_modules/hpagent/index.d.ts
generated
vendored
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
import * as http from 'http'
|
||||
import * as https from 'https'
|
||||
import { URL } from 'url'
|
||||
|
||||
declare class HttpProxyAgent extends http.Agent {
|
||||
constructor(options: HttpProxyAgentOptions)
|
||||
}
|
||||
|
||||
interface HttpProxyAgentOptions extends http.AgentOptions {
|
||||
proxy: string | URL,
|
||||
proxyRequestOptions?: ProxyAgentRequestOptions
|
||||
}
|
||||
|
||||
declare class HttpsProxyAgent extends https.Agent {
|
||||
constructor(options: HttpsProxyAgentOptions)
|
||||
}
|
||||
|
||||
interface HttpsProxyAgentOptions extends https.AgentOptions {
|
||||
proxy: string | URL,
|
||||
proxyRequestOptions?: ProxyAgentRequestOptions
|
||||
}
|
||||
|
||||
interface ProxyAgentRequestOptions {
|
||||
ca?: string[],
|
||||
headers?: Object,
|
||||
rejectUnauthorized?: boolean
|
||||
}
|
||||
|
||||
export {
|
||||
HttpProxyAgent,
|
||||
HttpProxyAgentOptions,
|
||||
HttpsProxyAgent,
|
||||
HttpsProxyAgentOptions,
|
||||
ProxyAgentRequestOptions,
|
||||
}
|
||||
126
VISUALIZACION/node_modules/hpagent/index.js
generated
vendored
Executable file
126
VISUALIZACION/node_modules/hpagent/index.js
generated
vendored
Executable file
|
|
@ -0,0 +1,126 @@
|
|||
'use strict'
|
||||
|
||||
const https = require('https')
|
||||
const http = require('http')
|
||||
const { URL } = require('url')
|
||||
|
||||
class HttpProxyAgent extends http.Agent {
|
||||
constructor (options) {
|
||||
const { proxy, proxyRequestOptions, ...opts } = options
|
||||
super(opts)
|
||||
this.proxy = typeof proxy === 'string'
|
||||
? new URL(proxy)
|
||||
: proxy
|
||||
this.proxyRequestOptions = proxyRequestOptions || {}
|
||||
}
|
||||
|
||||
createConnection (options, callback) {
|
||||
const requestOptions = {
|
||||
...this.proxyRequestOptions,
|
||||
method: 'CONNECT',
|
||||
host: this.proxy.hostname,
|
||||
port: this.proxy.port,
|
||||
path: `${options.host}:${options.port}`,
|
||||
setHost: false,
|
||||
headers: { ...this.proxyRequestOptions.headers, connection: this.keepAlive ? 'keep-alive' : 'close', host: `${options.host}:${options.port}` },
|
||||
agent: false,
|
||||
timeout: options.timeout || 0
|
||||
}
|
||||
|
||||
if (this.proxy.username || this.proxy.password) {
|
||||
const base64 = Buffer.from(`${decodeURIComponent(this.proxy.username || '')}:${decodeURIComponent(this.proxy.password || '')}`).toString('base64')
|
||||
requestOptions.headers['proxy-authorization'] = `Basic ${base64}`
|
||||
}
|
||||
|
||||
if (this.proxy.protocol === 'https:') {
|
||||
requestOptions.servername = this.proxy.hostname
|
||||
}
|
||||
|
||||
const request = (this.proxy.protocol === 'http:' ? http : https).request(requestOptions)
|
||||
request.once('connect', (response, socket, head) => {
|
||||
request.removeAllListeners()
|
||||
socket.removeAllListeners()
|
||||
if (response.statusCode === 200) {
|
||||
callback(null, socket)
|
||||
} else {
|
||||
socket.destroy()
|
||||
callback(new Error(`Bad response: ${response.statusCode}`), null)
|
||||
}
|
||||
})
|
||||
|
||||
request.once('timeout', () => {
|
||||
request.destroy(new Error('Proxy timeout'))
|
||||
})
|
||||
|
||||
request.once('error', err => {
|
||||
request.removeAllListeners()
|
||||
callback(err, null)
|
||||
})
|
||||
|
||||
request.end()
|
||||
}
|
||||
}
|
||||
|
||||
class HttpsProxyAgent extends https.Agent {
|
||||
constructor (options) {
|
||||
const { proxy, proxyRequestOptions, ...opts } = options
|
||||
super(opts)
|
||||
this.proxy = typeof proxy === 'string'
|
||||
? new URL(proxy)
|
||||
: proxy
|
||||
this.proxyRequestOptions = proxyRequestOptions || {}
|
||||
}
|
||||
|
||||
createConnection (options, callback) {
|
||||
const requestOptions = {
|
||||
...this.proxyRequestOptions,
|
||||
method: 'CONNECT',
|
||||
host: this.proxy.hostname,
|
||||
port: this.proxy.port,
|
||||
path: `${options.host}:${options.port}`,
|
||||
setHost: false,
|
||||
headers: { ...this.proxyRequestOptions.headers, connection: this.keepAlive ? 'keep-alive' : 'close', host: `${options.host}:${options.port}` },
|
||||
agent: false,
|
||||
timeout: options.timeout || 0
|
||||
}
|
||||
|
||||
if (this.proxy.username || this.proxy.password) {
|
||||
const base64 = Buffer.from(`${decodeURIComponent(this.proxy.username || '')}:${decodeURIComponent(this.proxy.password || '')}`).toString('base64')
|
||||
requestOptions.headers['proxy-authorization'] = `Basic ${base64}`
|
||||
}
|
||||
|
||||
// Necessary for the TLS check with the proxy to succeed.
|
||||
if (this.proxy.protocol === 'https:') {
|
||||
requestOptions.servername = this.proxy.hostname
|
||||
}
|
||||
|
||||
const request = (this.proxy.protocol === 'http:' ? http : https).request(requestOptions)
|
||||
request.once('connect', (response, socket, head) => {
|
||||
request.removeAllListeners()
|
||||
socket.removeAllListeners()
|
||||
if (response.statusCode === 200) {
|
||||
const secureSocket = super.createConnection({ ...options, socket })
|
||||
callback(null, secureSocket)
|
||||
} else {
|
||||
socket.destroy()
|
||||
callback(new Error(`Bad response: ${response.statusCode}`), null)
|
||||
}
|
||||
})
|
||||
|
||||
request.once('timeout', () => {
|
||||
request.destroy(new Error('Proxy timeout'))
|
||||
})
|
||||
|
||||
request.once('error', err => {
|
||||
request.removeAllListeners()
|
||||
callback(err, null)
|
||||
})
|
||||
|
||||
request.end()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
HttpProxyAgent,
|
||||
HttpsProxyAgent
|
||||
}
|
||||
5
VISUALIZACION/node_modules/hpagent/index.mjs
generated
vendored
Executable file
5
VISUALIZACION/node_modules/hpagent/index.mjs
generated
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
import mod from './index.js'
|
||||
|
||||
export default mod
|
||||
export const HttpProxyAgent = mod.HttpProxyAgent
|
||||
export const HttpsProxyAgent = mod.HttpsProxyAgent
|
||||
54
VISUALIZACION/node_modules/hpagent/package.json
generated
vendored
Executable file
54
VISUALIZACION/node_modules/hpagent/package.json
generated
vendored
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"name": "hpagent",
|
||||
"version": "1.2.0",
|
||||
"description": "A ready to use http and https agent for working with proxies that keeps connections alive!",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./index.js",
|
||||
"import": "./index.mjs",
|
||||
"types": "./index.d.ts"
|
||||
},
|
||||
"./*": "./*.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && NODE_EXTRA_CA_CERTS=test/fixtures/certs_unit_test.pem ava -v test/*.test.js && NODE_EXTRA_CA_CERTS=test/fixtures/certs_unit_test.pem ./test/hang-socket/runner.sh && tsd",
|
||||
"test-ci": "standard && ava -v test/*.test.js && tsd"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/delvedor/hpagent.git"
|
||||
},
|
||||
"keywords": [
|
||||
"agent",
|
||||
"http",
|
||||
"https",
|
||||
"secure",
|
||||
"proxy",
|
||||
"alive",
|
||||
"keep-alive"
|
||||
],
|
||||
"author": "Tomas Della Vedova",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/delvedor/hpagent/issues"
|
||||
},
|
||||
"homepage": "https://github.com/delvedor/hpagent#readme",
|
||||
"tsd": {
|
||||
"directory": "test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^4.2.0",
|
||||
"got": "^11.8.3",
|
||||
"needle": "^3.1.0",
|
||||
"node-fetch": "^2.6.7",
|
||||
"proxy": "^1.0.2",
|
||||
"simple-get": "^4.0.1",
|
||||
"standard": "^17.0.0",
|
||||
"tsd": "^0.24.1"
|
||||
}
|
||||
}
|
||||
113
VISUALIZACION/node_modules/hpagent/test/got.test.js
generated
vendored
Executable file
113
VISUALIZACION/node_modules/hpagent/test/got.test.js
generated
vendored
Executable file
|
|
@ -0,0 +1,113 @@
|
|||
'use strict'
|
||||
|
||||
const got = require('got')
|
||||
const test = require('ava')
|
||||
const {
|
||||
createServer,
|
||||
createSecureServer,
|
||||
createProxy,
|
||||
createSecureProxy,
|
||||
PROXY_HOSTNAME,
|
||||
SERVER_HOSTNAME
|
||||
} = require('./utils')
|
||||
const { HttpProxyAgent, HttpsProxyAgent } = require('../')
|
||||
|
||||
test('http to http', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await got(`http://${server.address().address}:${server.address().port}`, {
|
||||
agent: {
|
||||
http: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.is(response.body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('https to http', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await got(`http://${server.address().address}:${server.address().port}`, {
|
||||
agent: {
|
||||
http: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.is(response.body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('http to https', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await got(`https://${SERVER_HOSTNAME}:${server.address().port}`, {
|
||||
agent: {
|
||||
http: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.is(response.body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('https to https', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await got(`https://${SERVER_HOSTNAME}:${server.address().port}`, {
|
||||
agent: {
|
||||
http: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.is(response.body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
67
VISUALIZACION/node_modules/hpagent/test/hang-socket/http.js
generated
vendored
Executable file
67
VISUALIZACION/node_modules/hpagent/test/hang-socket/http.js
generated
vendored
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
'use strict'
|
||||
|
||||
const http = require('http')
|
||||
const { createServer, SERVER_HOSTNAME } = require('../utils')
|
||||
const { HttpProxyAgent } = require('../../')
|
||||
|
||||
function request (opts) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request(opts, resolve)
|
||||
req.on('error', reject)
|
||||
req.end(opts.body)
|
||||
})
|
||||
}
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
console.log('The http agent is not cleaning up hanging sockets')
|
||||
process.exit(1)
|
||||
}, 5000)
|
||||
|
||||
async function run () {
|
||||
const server = await createServer()
|
||||
server.on('connect', (request, socket, head) => {
|
||||
socket.on('end', () => {
|
||||
clearTimeout(timeout)
|
||||
})
|
||||
const lines = [
|
||||
'HTTP/1.1 403 FORBIDDEN',
|
||||
'',
|
||||
'Forbidden'
|
||||
]
|
||||
socket.write(lines.join('\r\n'))
|
||||
})
|
||||
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
timeout: 500,
|
||||
proxy: `http://${SERVER_HOSTNAME}:${server.address().port}`
|
||||
})
|
||||
|
||||
try {
|
||||
await request({
|
||||
method: 'GET',
|
||||
hostname: 'www.example.com',
|
||||
port: '',
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
console.error(new Error('Should throw'))
|
||||
process.exit(1)
|
||||
} catch (err) {
|
||||
if (err.message !== 'Bad response: 403') {
|
||||
console.error(new Error('Expected a different error'))
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
server.close()
|
||||
}
|
||||
|
||||
run().catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
67
VISUALIZACION/node_modules/hpagent/test/hang-socket/https.js
generated
vendored
Executable file
67
VISUALIZACION/node_modules/hpagent/test/hang-socket/https.js
generated
vendored
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
'use strict'
|
||||
|
||||
const https = require('https')
|
||||
const { createSecureServer, SERVER_HOSTNAME } = require('../utils')
|
||||
const { HttpsProxyAgent } = require('../../')
|
||||
|
||||
function request (opts) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = https.request(opts, resolve)
|
||||
req.on('error', reject)
|
||||
req.end(opts.body)
|
||||
})
|
||||
}
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
console.log('The https agent is not cleaning up hanging sockets')
|
||||
process.exit(1)
|
||||
}, 5000)
|
||||
|
||||
async function run () {
|
||||
const server = await createSecureServer()
|
||||
server.on('connect', (request, socket, head) => {
|
||||
socket.on('end', () => {
|
||||
clearTimeout(timeout)
|
||||
})
|
||||
const lines = [
|
||||
'HTTP/1.1 403 FORBIDDEN',
|
||||
'',
|
||||
'Forbidden'
|
||||
]
|
||||
socket.write(lines.join('\r\n'))
|
||||
})
|
||||
|
||||
const agent = new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
timeout: 500,
|
||||
proxy: `https://${SERVER_HOSTNAME}:${server.address().port}`
|
||||
})
|
||||
|
||||
try {
|
||||
await request({
|
||||
method: 'GET',
|
||||
hostname: 'www.example.com',
|
||||
port: '',
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
console.error(new Error('Should throw'))
|
||||
process.exit(1)
|
||||
} catch (err) {
|
||||
if (err.message !== 'Bad response: 403') {
|
||||
console.error(new Error('Expected a different error, got:', err.message))
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
server.close()
|
||||
}
|
||||
|
||||
run().catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
6
VISUALIZACION/node_modules/hpagent/test/hang-socket/runner.sh
generated
vendored
Executable file
6
VISUALIZACION/node_modules/hpagent/test/hang-socket/runner.sh
generated
vendored
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
node test/hang-socket/http.js
|
||||
node test/hang-socket/https.js
|
||||
509
VISUALIZACION/node_modules/hpagent/test/http-http.test.js
generated
vendored
Executable file
509
VISUALIZACION/node_modules/hpagent/test/http-http.test.js
generated
vendored
Executable file
|
|
@ -0,0 +1,509 @@
|
|||
'use strict'
|
||||
|
||||
const http = require('http')
|
||||
const test = require('ava')
|
||||
const { createServer, createProxy } = require('./utils')
|
||||
const { HttpProxyAgent } = require('../')
|
||||
|
||||
function request (opts) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request(opts, resolve)
|
||||
req.on('error', reject)
|
||||
req.end(opts.body)
|
||||
})
|
||||
}
|
||||
|
||||
test('Basic', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Connection header (keep-alive)', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.connection, 'keep-alive')
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Connection header (close)', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.connection, 'close')
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: Infinity,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy authentication (empty)', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === undefined)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy authentication', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://hello:world@${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Configure the agent to reuse sockets', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
let count = 0
|
||||
proxy.on('connection', () => {
|
||||
count += 1
|
||||
t.is(count, 1)
|
||||
})
|
||||
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
|
||||
let response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Configure the agent to NOT reuse sockets', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const ports = []
|
||||
proxy.on('connection', socket => {
|
||||
t.false(ports.includes(socket.remotePort))
|
||||
ports.push(socket.remotePort)
|
||||
})
|
||||
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: Infinity,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
|
||||
let response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Test Host Header', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.host, `${server.address().address}:${server.address().port}`)
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Timeout', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
try {
|
||||
await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
timeout: 1,
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
t.fail('Should throw')
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Proxy timeout')
|
||||
}
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Username and password should not be encoded', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('username_with_=:password_with_=').toString('base64')}`)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://username_with_=:password_with_=@${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy request options should be passed to the CONNECT request only', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
let serverCustomHeaderReceived
|
||||
let proxyCustomHeaderReceived
|
||||
server.on('request', (req, res) => {
|
||||
serverCustomHeaderReceived = req.headers['x-custom-header']
|
||||
return res.end('ok')
|
||||
})
|
||||
proxy.on('connect', (req) => {
|
||||
proxyCustomHeaderReceived = req.headers['x-custom-header']
|
||||
})
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
proxyRequestOptions: {
|
||||
headers: {
|
||||
'x-custom-header': 'value'
|
||||
}
|
||||
},
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
t.falsy(serverCustomHeaderReceived)
|
||||
t.is(proxyCustomHeaderReceived, 'value')
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy request options should not override internal default options for CONNECT request', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
let proxyConnectionHeaderReceived
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
proxy.on('connect', (req) => {
|
||||
proxyConnectionHeaderReceived = req.headers.connection
|
||||
})
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
proxyRequestOptions: {
|
||||
headers: {
|
||||
connection: 'close'
|
||||
}
|
||||
},
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
t.is(proxyConnectionHeaderReceived, 'keep-alive')
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
434
VISUALIZACION/node_modules/hpagent/test/http-https.test.js
generated
vendored
Executable file
434
VISUALIZACION/node_modules/hpagent/test/http-https.test.js
generated
vendored
Executable file
|
|
@ -0,0 +1,434 @@
|
|||
'use strict'
|
||||
|
||||
const https = require('https')
|
||||
const test = require('ava')
|
||||
const { createSecureServer, createProxy, SERVER_HOSTNAME } = require('./utils')
|
||||
const { HttpsProxyAgent } = require('../')
|
||||
|
||||
function request (opts) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = https.request(opts, resolve)
|
||||
req.on('error', reject)
|
||||
req.end(opts.body)
|
||||
})
|
||||
}
|
||||
|
||||
test('Basic', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Connection header (keep-alive)', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.connection, 'keep-alive')
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Connection header (close)', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.connection, 'close')
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: Infinity,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy authentication (empty)', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === undefined)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy authentication', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://hello:world@${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Configure the agent to reuse sockets', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
let count = 0
|
||||
proxy.on('connection', () => {
|
||||
count += 1
|
||||
t.is(count, 1)
|
||||
})
|
||||
|
||||
const agent = new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
|
||||
let response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Configure the agent to NOT reuse sockets', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const ports = []
|
||||
proxy.on('connection', socket => {
|
||||
t.false(ports.includes(socket.remotePort))
|
||||
ports.push(socket.remotePort)
|
||||
})
|
||||
|
||||
const agent = new HttpsProxyAgent({
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: Infinity,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
|
||||
let response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Timeout', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
try {
|
||||
await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
timeout: 1,
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
t.fail('Should throw')
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Proxy timeout')
|
||||
}
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy request options should be passed to the CONNECT request only', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
let serverCustomHeaderReceived
|
||||
let proxyCustomHeaderReceived
|
||||
server.on('request', (req, res) => {
|
||||
serverCustomHeaderReceived = req.headers['x-custom-header']
|
||||
return res.end('ok')
|
||||
})
|
||||
proxy.on('connect', (req) => {
|
||||
proxyCustomHeaderReceived = req.headers['x-custom-header']
|
||||
})
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
proxyRequestOptions: {
|
||||
headers: {
|
||||
'x-custom-header': 'value'
|
||||
}
|
||||
},
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
t.falsy(serverCustomHeaderReceived)
|
||||
t.is(proxyCustomHeaderReceived, 'value')
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy request options should not override internal default options for CONNECT request', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
let proxyConnectionHeaderReceived
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
proxy.on('connect', (req) => {
|
||||
proxyConnectionHeaderReceived = req.headers.connection
|
||||
})
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
proxyRequestOptions: {
|
||||
headers: {
|
||||
connection: 'close'
|
||||
}
|
||||
},
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
t.is(proxyConnectionHeaderReceived, 'keep-alive')
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
434
VISUALIZACION/node_modules/hpagent/test/https-http.test.js
generated
vendored
Executable file
434
VISUALIZACION/node_modules/hpagent/test/https-http.test.js
generated
vendored
Executable file
|
|
@ -0,0 +1,434 @@
|
|||
'use strict'
|
||||
|
||||
const http = require('http')
|
||||
const test = require('ava')
|
||||
const { createServer, createSecureProxy, PROXY_HOSTNAME } = require('./utils')
|
||||
const { HttpProxyAgent } = require('../')
|
||||
|
||||
function request (opts) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request(opts, resolve)
|
||||
req.on('error', reject)
|
||||
req.end(opts.body)
|
||||
})
|
||||
}
|
||||
|
||||
test('Basic', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Connection header (keep-alive)', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.connection, 'keep-alive')
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Connection header (close)', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.connection, 'close')
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: Infinity,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy authentication (empty)', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === undefined)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy authentication', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://hello:world@${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Configure the agent to reuse sockets', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
let count = 0
|
||||
proxy.on('connection', () => {
|
||||
count += 1
|
||||
t.is(count, 1)
|
||||
})
|
||||
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
|
||||
let response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Configure the agent to NOT reuse sockets', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const ports = []
|
||||
proxy.on('connection', socket => {
|
||||
t.false(ports.includes(socket.remotePort))
|
||||
ports.push(socket.remotePort)
|
||||
})
|
||||
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: Infinity,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
|
||||
let response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Timeout', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
try {
|
||||
await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
timeout: 1,
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
t.fail('Should throw')
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Proxy timeout')
|
||||
}
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy request options should be passed to the CONNECT request only', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
let serverCustomHeaderReceived
|
||||
let proxyCustomHeaderReceived
|
||||
server.on('request', (req, res) => {
|
||||
serverCustomHeaderReceived = req.headers['x-custom-header']
|
||||
return res.end('ok')
|
||||
})
|
||||
proxy.on('connect', (req) => {
|
||||
proxyCustomHeaderReceived = req.headers['x-custom-header']
|
||||
})
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
proxyRequestOptions: {
|
||||
headers: {
|
||||
'x-custom-header': 'value'
|
||||
}
|
||||
},
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
t.falsy(serverCustomHeaderReceived)
|
||||
t.is(proxyCustomHeaderReceived, 'value')
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy request options should not override internal default options for CONNECT request', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
let proxyConnectionHeaderReceived
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
proxy.on('connect', (req) => {
|
||||
proxyConnectionHeaderReceived = req.headers.connection
|
||||
})
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: server.address().address,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpProxyAgent({
|
||||
proxyRequestOptions: {
|
||||
headers: {
|
||||
connection: 'close'
|
||||
}
|
||||
},
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
t.is(proxyConnectionHeaderReceived, 'keep-alive')
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
471
VISUALIZACION/node_modules/hpagent/test/https-https.test.js
generated
vendored
Executable file
471
VISUALIZACION/node_modules/hpagent/test/https-https.test.js
generated
vendored
Executable file
|
|
@ -0,0 +1,471 @@
|
|||
'use strict'
|
||||
|
||||
const https = require('https')
|
||||
const test = require('ava')
|
||||
const { createSecureServer, createSecureProxy, PROXY_HOSTNAME, SERVER_HOSTNAME } = require('./utils')
|
||||
const { HttpsProxyAgent } = require('../')
|
||||
|
||||
function request (opts) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = https.request(opts, resolve)
|
||||
req.on('error', reject)
|
||||
req.end(opts.body)
|
||||
})
|
||||
}
|
||||
|
||||
test('Basic', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Connection header (keep-alive)', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.connection, 'keep-alive')
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Connection header (close)', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
t.is(req.headers.connection, 'close')
|
||||
fn(null, true)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: Infinity,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy authentication (empty)', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === undefined)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy authentication', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://hello:world@${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Configure the agent to reuse sockets', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
let count = 0
|
||||
proxy.on('connection', () => {
|
||||
count += 1
|
||||
t.is(count, 1)
|
||||
})
|
||||
|
||||
const agent = new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
|
||||
let response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Configure the agent to NOT reuse sockets', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const ports = []
|
||||
proxy.on('connection', socket => {
|
||||
t.false(ports.includes(socket.remotePort))
|
||||
ports.push(socket.remotePort)
|
||||
})
|
||||
|
||||
const agent = new HttpsProxyAgent({
|
||||
keepAlive: false,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: Infinity,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
|
||||
let response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent
|
||||
})
|
||||
|
||||
body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Timeout', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
try {
|
||||
await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
timeout: 1,
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
t.fail('Should throw')
|
||||
} catch (err) {
|
||||
t.is(err.message, 'Proxy timeout')
|
||||
}
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Username and password should not be encoded', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
proxy.authenticate = function (req, fn) {
|
||||
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('username_with_=:password_with_=').toString('base64')}`)
|
||||
}
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://username_with_=:password_with_=@${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy request options should be passed to the CONNECT request only', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
let serverCustomHeaderReceived
|
||||
let proxyCustomHeaderReceived
|
||||
server.on('request', (req, res) => {
|
||||
serverCustomHeaderReceived = req.headers['x-custom-header']
|
||||
return res.end('ok')
|
||||
})
|
||||
proxy.on('connect', (req) => {
|
||||
proxyCustomHeaderReceived = req.headers['x-custom-header']
|
||||
})
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
proxyRequestOptions: {
|
||||
headers: {
|
||||
'x-custom-header': 'value'
|
||||
}
|
||||
},
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
t.falsy(serverCustomHeaderReceived)
|
||||
t.is(proxyCustomHeaderReceived, 'value')
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('Proxy request options should not override internal default options for CONNECT request', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
let proxyConnectionHeaderReceived
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
proxy.on('connect', (req) => {
|
||||
proxyConnectionHeaderReceived = req.headers.connection
|
||||
})
|
||||
|
||||
const response = await request({
|
||||
method: 'GET',
|
||||
hostname: SERVER_HOSTNAME,
|
||||
port: server.address().port,
|
||||
path: '/',
|
||||
agent: new HttpsProxyAgent({
|
||||
proxyRequestOptions: {
|
||||
headers: {
|
||||
connection: 'close'
|
||||
}
|
||||
},
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
let body = ''
|
||||
response.setEncoding('utf8')
|
||||
for await (const chunk of response) {
|
||||
body += chunk
|
||||
}
|
||||
|
||||
t.is(body, 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
t.is(proxyConnectionHeaderReceived, 'keep-alive')
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
45
VISUALIZACION/node_modules/hpagent/test/index.test-d.ts
generated
vendored
Executable file
45
VISUALIZACION/node_modules/hpagent/test/index.test-d.ts
generated
vendored
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
import * as http from 'http'
|
||||
import * as https from 'https'
|
||||
import { expectType } from 'tsd'
|
||||
import {
|
||||
HttpProxyAgent,
|
||||
HttpProxyAgentOptions,
|
||||
HttpsProxyAgent,
|
||||
HttpsProxyAgentOptions
|
||||
} from '../'
|
||||
|
||||
{
|
||||
const agent = new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
proxy: 'http://localhost:8080'
|
||||
})
|
||||
|
||||
expectType<HttpProxyAgent>(agent)
|
||||
http.request({
|
||||
method: 'GET',
|
||||
hostname: 'localhost',
|
||||
port: 9200,
|
||||
agent
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
const agent = new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
proxy: 'http://localhost:8080'
|
||||
})
|
||||
|
||||
expectType<HttpsProxyAgent>(agent)
|
||||
https.request({
|
||||
method: 'GET',
|
||||
hostname: 'localhost',
|
||||
port: 9200,
|
||||
agent
|
||||
})
|
||||
}
|
||||
105
VISUALIZACION/node_modules/hpagent/test/needle.test.js
generated
vendored
Executable file
105
VISUALIZACION/node_modules/hpagent/test/needle.test.js
generated
vendored
Executable file
|
|
@ -0,0 +1,105 @@
|
|||
'use strict'
|
||||
|
||||
const needle = require('needle')
|
||||
const test = require('ava')
|
||||
const {
|
||||
createServer,
|
||||
createSecureServer,
|
||||
createProxy,
|
||||
createSecureProxy,
|
||||
PROXY_HOSTNAME,
|
||||
SERVER_HOSTNAME
|
||||
} = require('./utils')
|
||||
const { HttpProxyAgent, HttpsProxyAgent } = require('../')
|
||||
|
||||
test('http to http', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await needle('get', `http://${server.address().address}:${server.address().port}`, {
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
t.is(response.body.toString(), 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('https to http', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await needle('get', `http://${server.address().address}:${server.address().port}`, {
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
t.is(response.body.toString(), 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('http to https', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await needle('get', `https://${SERVER_HOSTNAME}:${server.address().port}`, {
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
t.is(response.body.toString(), 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('https to https', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await needle('get', `https://${SERVER_HOSTNAME}:${server.address().port}`, {
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
t.is(response.body.toString(), 'ok')
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
105
VISUALIZACION/node_modules/hpagent/test/node-fetch.test.js
generated
vendored
Executable file
105
VISUALIZACION/node_modules/hpagent/test/node-fetch.test.js
generated
vendored
Executable file
|
|
@ -0,0 +1,105 @@
|
|||
'use strict'
|
||||
|
||||
const fetch = require('node-fetch')
|
||||
const test = require('ava')
|
||||
const {
|
||||
createServer,
|
||||
createSecureServer,
|
||||
createProxy,
|
||||
createSecureProxy,
|
||||
PROXY_HOSTNAME,
|
||||
SERVER_HOSTNAME
|
||||
} = require('./utils')
|
||||
const { HttpProxyAgent, HttpsProxyAgent } = require('../')
|
||||
|
||||
test('http to http', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await fetch(`http://${server.address().address}:${server.address().port}`, {
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
t.is(await response.text(), 'ok')
|
||||
t.is(response.status, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('https to http', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await fetch(`http://${server.address().address}:${server.address().port}`, {
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
t.is(await response.text(), 'ok')
|
||||
t.is(response.status, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('http to https', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await fetch(`https://${SERVER_HOSTNAME}:${server.address().port}`, {
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
t.is(await response.text(), 'ok')
|
||||
t.is(response.status, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('https to https', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await fetch(`https://${SERVER_HOSTNAME}:${server.address().port}`, {
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
})
|
||||
|
||||
t.is(await response.text(), 'ok')
|
||||
t.is(response.status, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
141
VISUALIZACION/node_modules/hpagent/test/simple-get.test.js
generated
vendored
Executable file
141
VISUALIZACION/node_modules/hpagent/test/simple-get.test.js
generated
vendored
Executable file
|
|
@ -0,0 +1,141 @@
|
|||
'use strict'
|
||||
|
||||
const sget = require('simple-get')
|
||||
const test = require('ava')
|
||||
const {
|
||||
createServer,
|
||||
createSecureServer,
|
||||
createProxy,
|
||||
createSecureProxy,
|
||||
PROXY_HOSTNAME,
|
||||
SERVER_HOSTNAME
|
||||
} = require('./utils')
|
||||
const { HttpProxyAgent, HttpsProxyAgent } = require('..')
|
||||
|
||||
test('http to http', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await new Promise((resolve, reject) => {
|
||||
sget.concat({
|
||||
url: `http://${server.address().address}:${server.address().port}`,
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
}, function (err, response, data) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
t.is(data.toString(), 'ok')
|
||||
|
||||
return resolve(response)
|
||||
})
|
||||
})
|
||||
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('https to http', async t => {
|
||||
const server = await createServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await new Promise((resolve, reject) => {
|
||||
sget.concat({
|
||||
url: `http://${server.address().address}:${server.address().port}`,
|
||||
agent: new HttpProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
}, function (err, response, data) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
t.is(data.toString(), 'ok')
|
||||
|
||||
return resolve(response)
|
||||
})
|
||||
})
|
||||
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('http to https', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await new Promise((resolve, reject) => {
|
||||
sget.concat({
|
||||
url: `https://${SERVER_HOSTNAME}:${server.address().port}`,
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `http://${proxy.address().address}:${proxy.address().port}`
|
||||
})
|
||||
}, function (err, response, data) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
t.is(data.toString(), 'ok')
|
||||
|
||||
return resolve(response)
|
||||
})
|
||||
})
|
||||
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
|
||||
test('https to https', async t => {
|
||||
const server = await createSecureServer()
|
||||
const proxy = await createSecureProxy()
|
||||
server.on('request', (req, res) => res.end('ok'))
|
||||
|
||||
const response = await new Promise((resolve, reject) => {
|
||||
sget.concat({
|
||||
url: `https://${SERVER_HOSTNAME}:${server.address().port}`,
|
||||
agent: new HttpsProxyAgent({
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 1000,
|
||||
maxSockets: 256,
|
||||
maxFreeSockets: 256,
|
||||
scheduling: 'lifo',
|
||||
proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
|
||||
})
|
||||
}, function (err, response, data) {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
t.is(data.toString(), 'ok')
|
||||
|
||||
return resolve(response)
|
||||
})
|
||||
})
|
||||
|
||||
t.is(response.statusCode, 200)
|
||||
|
||||
server.close()
|
||||
proxy.close()
|
||||
})
|
||||
101
VISUALIZACION/node_modules/hpagent/test/utils.js
generated
vendored
Executable file
101
VISUALIZACION/node_modules/hpagent/test/utils.js
generated
vendored
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
'use strict'
|
||||
|
||||
const proxy = require('proxy')
|
||||
const { readFileSync } = require('fs')
|
||||
const { join } = require('path')
|
||||
const http = require('http')
|
||||
const https = require('https')
|
||||
const dns = require('dns')
|
||||
|
||||
/**
|
||||
* We've manually created self signed certificates for the proxy
|
||||
* and for the server, with the following domains (Subject CN)
|
||||
* proxy.hpagent-unit-test.com
|
||||
* server.hpagent-unit-test.com
|
||||
*
|
||||
* This will allow us to properly test the TLS-over-TLS proxy,
|
||||
* specifically that the first handshake provides the proxy SNI, not the server SNI.
|
||||
*
|
||||
* These certs were generated using openssl:
|
||||
* openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout key_server.pem -out cert_server.pem
|
||||
* openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout key_proxy.pem -out cert_proxy.pem
|
||||
*
|
||||
* The certs are concatenated to the can be passed to Node.JS as trusted certs:
|
||||
* $ cat cert_proxy.pem > certs_unit_test.pem
|
||||
* $ cat cert_server.pem >> certs_unit_test.pem
|
||||
*
|
||||
* using `NODE_EXTRA_CA_CERTS` (https://nodejs.org/api/cli.html#node_extra_ca_certsfile)
|
||||
*
|
||||
* This allows actual verification of the certs w/ hostname instead of ignoring all errors
|
||||
*/
|
||||
|
||||
const sslProxy = {
|
||||
key: readFileSync(join(__dirname, 'fixtures/key_proxy.pem')),
|
||||
cert: readFileSync(join(__dirname, 'fixtures/cert_proxy.pem'))
|
||||
}
|
||||
|
||||
const sslServer = {
|
||||
key: readFileSync(join(__dirname, 'fixtures/key_server.pem')),
|
||||
cert: readFileSync(join(__dirname, 'fixtures/cert_server.pem'))
|
||||
}
|
||||
|
||||
/**
|
||||
* We override all DNS requests from the node process (for unit test) to resolve to
|
||||
* 127.0.0.1. This allows us to use the self signed certs we made for the fake
|
||||
* domains to be verified, and then the connection made to localhost.
|
||||
*/
|
||||
dns.lookup = (hostname, opts, cb) => {
|
||||
if (typeof opts === 'function') {
|
||||
return opts(null, '127.0.0.1', 4)
|
||||
}
|
||||
|
||||
return cb(null, '127.0.0.1', 4)
|
||||
}
|
||||
|
||||
function createProxy () {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = proxy(http.createServer())
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
resolve(server)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function createSecureProxy () {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = proxy(https.createServer(sslProxy))
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
resolve(server)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function createServer (handler, callback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = http.createServer()
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
resolve(server)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function createSecureServer (handler, callback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = https.createServer(sslServer)
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
resolve(server)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const PROXY_HOSTNAME = 'proxy.hpagent-unit-test.com'
|
||||
const SERVER_HOSTNAME = 'server.hpagent-unit-test.com'
|
||||
|
||||
module.exports = {
|
||||
createProxy,
|
||||
createSecureProxy,
|
||||
createServer,
|
||||
createSecureServer,
|
||||
PROXY_HOSTNAME,
|
||||
SERVER_HOSTNAME
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue