Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: proxy agent unintentionally overwrites protocol in URL #241

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading