mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ResponseOps] Fix the forward proxy manual tester (#160216)
Updates the code in the manual proxy tester to work with an updated version of it's pre-req npm packages. This code is not used in production, or ci tests, just used manually for ad hoc proxy testing. Since this file is used manually, is currently not type-checked, and infrequently used, no one noticed it was no longer working, till I did this morning.
This commit is contained in:
parent
da745c3083
commit
8a04cdee62
1 changed files with 10 additions and 3 deletions
|
@ -34,11 +34,13 @@ echo done - you should run all the lines above as one command
|
|||
|
||||
*/
|
||||
|
||||
// @ts-check
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const proxySetup = require('proxy');
|
||||
const proxy = require('proxy');
|
||||
|
||||
const PROGRAM = path.basename(__filename).replace(/.js$/, '');
|
||||
const CertDir = path.resolve(__dirname, '../../../../../packages/kbn-dev-utils/certs');
|
||||
|
@ -60,12 +62,14 @@ async function main() {
|
|||
|
||||
const specs = args.map(argToSpec);
|
||||
for (const spec of specs) {
|
||||
if (!spec) continue;
|
||||
|
||||
const { protocol, port, auth } = spec;
|
||||
createServer(protocol, port, auth);
|
||||
}
|
||||
}
|
||||
|
||||
/** @type { (protocol: string, port: number, auth: boolean) => Promise<http.Server | httpServer> } */
|
||||
/** @type { (protocol: string, port: number, auth: boolean) => Promise<http.Server> } */
|
||||
async function createServer(protocol, port, auth) {
|
||||
let proxyServer;
|
||||
|
||||
|
@ -75,11 +79,12 @@ async function createServer(protocol, port, auth) {
|
|||
proxyServer = https.createServer(HttpsOptions);
|
||||
}
|
||||
|
||||
proxySetup(proxyServer);
|
||||
proxy.createProxy(proxyServer);
|
||||
|
||||
let authLabel = '';
|
||||
if (auth) {
|
||||
authLabel = `${Auth}@`;
|
||||
// @ts-ignore
|
||||
proxyServer.authenticate = (req, callback) => {
|
||||
const auth = req.headers['proxy-authorization'];
|
||||
callback(null, auth === `Basic ${AuthB64}`);
|
||||
|
@ -90,6 +95,8 @@ async function createServer(protocol, port, auth) {
|
|||
proxyServer.listen(port, 'localhost', () => {
|
||||
console.log(`proxy server started on ${serverLabel}`);
|
||||
});
|
||||
|
||||
return proxyServer;
|
||||
}
|
||||
|
||||
/* convert 'proto-port-auth' into object with shape shown below */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue