Skip to content

Commit

Permalink
upgrade proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
davidebianchi committed May 10, 2023
1 parent e83cf4a commit 661d7da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"hpagent": "^1.2.0",
"nock": "^13.3.1",
"pre-commit": "^1.2.2",
"proxy": "^1.0.2",
"proxy": "^2.0.1",
"split2": "^4.2.0",
"swagger-parser": "^10.0.3",
"tap": "^16.3.4",
Expand Down
26 changes: 10 additions & 16 deletions tests/httpClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const tap = require('tap')
const nock = require('nock')
const { Readable } = require('stream')
const http = require('http')
const proxy = require('proxy')
const { createProxy: proxy } = require('proxy')
const fs = require('fs')
const https = require('https')
const split = require('split2')
Expand Down Expand Up @@ -1716,10 +1716,9 @@ tap.test('httpClient', test => {
res.end('{"status": "ok"}')
})
const serverProxy = await createProxy()
let proxyCalled = false
serverProxy.authenticate = (req, fn) => {
proxyCalled = true
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
serverProxy.authenticate = (req) => {
assert.strictSame(req.headers['proxy-authorization'], `Basic ${Buffer.from('hello:world').toString('base64')}`)
return true
}

const service = new HttpClient(`http://${server.address().address}:${server.address().port}`)
Expand All @@ -1738,7 +1737,6 @@ tap.test('httpClient', test => {

assert.equal(response.statusCode, 200)
assert.strictSame(response.payload, { status: 'ok' })
assert.ok(proxyCalled)

server.close()
serverProxy.close()
Expand All @@ -1752,10 +1750,9 @@ tap.test('httpClient', test => {
res.end('OK')
})
const serverProxy = await createProxy()
let proxyCalled = false
serverProxy.authenticate = (req, fn) => {
proxyCalled = true
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
serverProxy.authenticate = (req) => {
assert.strictSame(req.headers['proxy-authorization'], `Basic ${Buffer.from('hello:world').toString('base64')}`)
return true
}

const service = new HttpClient(`http://${server.address().address}:${server.address().port}`)
Expand All @@ -1775,7 +1772,6 @@ tap.test('httpClient', test => {

assert.equal(response.statusCode, 200)
assert.strictSame(response.payload.toString('utf-8'), 'OK')
assert.ok(proxyCalled)

server.close()
serverProxy.close()
Expand All @@ -1789,10 +1785,9 @@ tap.test('httpClient', test => {
res.end(JSON.stringify({ the: 'response' }))
})
const serverProxy = await createProxy()
let proxyCalled = false
serverProxy.authenticate = (req, fn) => {
proxyCalled = true
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
serverProxy.authenticate = (req) => {
assert.strictSame(req.headers['proxy-authorization'], `Basic ${Buffer.from('hello:world').toString('base64')}`)
return true
}

const service = new HttpClient(`http://${server.address().address}:${server.address().port}`)
Expand All @@ -1812,7 +1807,6 @@ tap.test('httpClient', test => {

assert.equal(response.statusCode, 200)
assert.ok(response.headers['content-length'])
assert.ok(proxyCalled)

await wait(200)

Expand Down
26 changes: 10 additions & 16 deletions tests/serviceBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const serviceBuilder = require('../lib/serviceBuilder')
const reqheaders = { 'content-type': 'application/json;charset=utf-8' }
const { Readable } = require('stream')
const http = require('http')
const proxy = require('proxy')
const { createProxy: proxy } = require('proxy')
const { HttpProxyAgent } = require('hpagent')
const fs = require('fs')
const https = require('https')
Expand Down Expand Up @@ -1331,10 +1331,9 @@ tap.test('serviceBuilder', test => {
res.end('{"status": "ok"}')
})
const serverProxy = await createProxy()
let proxyCalled = false
serverProxy.authenticate = (req, fn) => {
proxyCalled = true
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
serverProxy.authenticate = req => {
assert.strictSame(req.headers['proxy-authorization'], `Basic ${Buffer.from('hello:world').toString('base64')}`)
return true
}

const service = serviceBuilder(server.address().address)
Expand All @@ -1349,7 +1348,6 @@ tap.test('serviceBuilder', test => {

assert.equal(response.statusCode, 200)
assert.strictSame(response.payload, { status: 'ok' })
assert.ok(proxyCalled)

server.close()
serverProxy.close()
Expand All @@ -1363,10 +1361,9 @@ tap.test('serviceBuilder', test => {
res.end('OK')
})
const serverProxy = await createProxy()
let proxyCalled = false
serverProxy.authenticate = (req, fn) => {
proxyCalled = true
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
serverProxy.authenticate = (req) => {
assert.strictSame(req.headers['proxy-authorization'], `Basic ${Buffer.from('hello:world').toString('base64')}`)
return true
}

const service = serviceBuilder(server.address().address)
Expand All @@ -1381,7 +1378,6 @@ tap.test('serviceBuilder', test => {

assert.equal(response.statusCode, 200)
assert.strictSame(response.payload.toString('utf-8'), 'OK')
assert.ok(proxyCalled)

server.close()
serverProxy.close()
Expand All @@ -1395,10 +1391,9 @@ tap.test('serviceBuilder', test => {
res.end(JSON.stringify({ the: 'response' }))
})
const serverProxy = await createProxy()
let proxyCalled = false
serverProxy.authenticate = (req, fn) => {
proxyCalled = true
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('hello:world').toString('base64')}`)
serverProxy.authenticate = (req) => {
assert.strictSame(req.headers['proxy-authorization'], `Basic ${Buffer.from('hello:world').toString('base64')}`)
return true
}

const service = serviceBuilder(server.address().address)
Expand All @@ -1413,7 +1408,6 @@ tap.test('serviceBuilder', test => {

assert.equal(response.statusCode, 200)
assert.ok(response.headers['content-length'])
assert.ok(proxyCalled)

await wait(200)

Expand Down

0 comments on commit 661d7da

Please sign in to comment.