Skip to content

Commit

Permalink
Fix: proxy agent unintentionally overwrites protocol in URL (#241)
Browse files Browse the repository at this point in the history
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
  • Loading branch information
kravets-levko committed Apr 11, 2024
1 parent 4592c40 commit d8244c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 0 additions & 3 deletions lib/connection/connections/HttpConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d8244c2

Please sign in to comment.