From d8244c2ec2a5ddbbb0f595f1a595a355752ac784 Mon Sep 17 00:00:00 2001 From: Levko Kravets Date: Thu, 11 Apr 2024 19:32:01 +0300 Subject: [PATCH] Fix: proxy agent unintentionally overwrites protocol in URL (#241) Signed-off-by: Levko Kravets --- lib/connection/connections/HttpConnection.ts | 3 --- tests/e2e/proxy.test.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/connection/connections/HttpConnection.ts b/lib/connection/connections/HttpConnection.ts index e113da5f..daa0661b 100644 --- a/lib/connection/connections/HttpConnection.ts +++ b/lib/connection/connections/HttpConnection.ts @@ -82,14 +82,11 @@ export default class HttpConnection implements IConnectionProvider { : ''; const proxyUrl = `${proxyOptions.protocol}://${proxyAuth}${proxyOptions.host}:${proxyOptions.port}`; - const proxyProtocol = `${proxyOptions.protocol}:`; - return new ProxyAgent({ ...this.getAgentDefaultOptions(), getProxyForUrl: () => proxyUrl, httpsAgent: this.createHttpsAgent(), httpAgent: this.createHttpAgent(), - protocol: proxyProtocol, }); } diff --git a/tests/e2e/proxy.test.js b/tests/e2e/proxy.test.js index eab37261..b7e48a33 100644 --- a/tests/e2e/proxy.test.js +++ b/tests/e2e/proxy.test.js @@ -50,6 +50,17 @@ describe('Proxy', () => { const proxy = new HttpProxyMock(`https://${config.host}`, 9090); try { const client = new DBSQLClient(); + + // Our proxy mock is HTTP -> HTTPS, but DBSQLClient is hard-coded to use HTTPS. + // Here we override default behavior to make DBSQLClient work with HTTP proxy + const originalGetConnectionOptions = client.getConnectionOptions; + client.getConnectionOptions = (...args) => { + const result = originalGetConnectionOptions.apply(client, args); + result.https = false; + result.port = 80; + return result; + }; + const clientConfig = client.getConfig(); sinon.stub(client, 'getConfig').returns(clientConfig);