Skip to content

fix(devtools-proxy-support): add yet another proxy-agent workaround #453

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

Merged
merged 1 commit into from
Aug 14, 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
17 changes: 17 additions & 0 deletions packages/devtools-proxy-support/src/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,21 @@ q/I2+0j6dAkOGcK/68z7qQXByeGri3n28a1Kn6o=
}
});
});

context('invalid arguments', function () {
it('does not receive unhandled rejections when using invalid options', async function () {
// This test may seem contrived, but it mimics FIPS mode without a valid system FIPS config
// (i.e. OpenSSL cannot load ciphers) -- this should result in a handled rejection, rather than
// an unhandled one.
try {
await get(
'https://example.com/hello',
createAgent({ ciphers: 'unknown' } as any)
);
expect.fail('missed exception');
} catch (err: any) {
expect(err.message).to.include('no cipher match');
}
});
});
});
20 changes: 16 additions & 4 deletions packages/devtools-proxy-support/src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ProxyAgent } from './proxy-agent';
import type { Agent } from 'https';
import type { Agent as HTTPSAgent } from 'https';
import type { DevtoolsProxyOptions } from './proxy-options';
import { proxyForUrl } from './proxy-options';
import type { ClientRequest, Agent as HTTPAgent } from 'http';
import type { ClientRequest } from 'http';
import { Agent as HTTPAgent } from 'http';
import type { TcpNetConnectOpts } from 'net';
import type { ConnectionOptions, SecureContextOptions } from 'tls';
import type { Duplex } from 'stream';
Expand All @@ -16,7 +17,7 @@ import { mergeCA, systemCA } from './system-ca';
// Helper type that represents an https.Agent (= connection factory)
// with some custom properties that TS does not know about and/or
// that we add for our own purposes.
export type AgentWithInitialize = Agent & {
export type AgentWithInitialize = HTTPSAgent & {
// This is genuinely custom for our usage (to allow establishing an SSH tunnel
// first before starting to push connections through it)
initialize?(): Promise<void>;
Expand Down Expand Up @@ -96,7 +97,18 @@ class DevtoolsProxyAgent extends ProxyAgent implements AgentWithInitialize {
}
this._req = req;
this._reqLock = new Promise((resolve) => (this._reqLockResolve = resolve));
return await super.connect(req, opts);
const agent = await super.connect(req, opts);
// Work around https://github.com/TooTallNate/proxy-agents/pull/330
if ('addRequest' in agent && typeof agent.addRequest === 'function') {
const dummyHttpAgent = Object.assign(new HTTPAgent(), {
addRequest() {
//ignore
},
});
agent.addRequest(req, opts);
return dummyHttpAgent;
}
return agent;
}

destroy(): void {
Expand Down
Loading