flow like the river

This commit is contained in:
root 2025-11-07 00:06:12 +01:00
commit 013fe673f3
42435 changed files with 5764238 additions and 0 deletions

113
VISUALIZACION/node_modules/hpagent/test/got.test.js generated vendored Executable file
View 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
View 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
View 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)
})

View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
}