Repository navigation
fix: route OAuth token requests through HTTPS_PROXY again - #11598
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where OAuth token requests ignored the HTTPS_PROXY environment variable, causing commands to hang behind a proxy. It introduces authTransporterAgent in src/apiv2.ts which returns undefined if a proxy is configured in the environment, allowing gaxios to handle the proxy routing. Otherwise, it falls back to the standard noKeepAliveAgent. The getAuthClient function in src/requireAuth.ts is updated to use this new agent, and corresponding unit tests are added in src/apiv2.spec.ts. There are no review comments, so I have no feedback to provide.
|
Thanks for the contribution! We could add some better tests here too |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11598 +/- ##
=======================================
Coverage ? 61.33%
=======================================
Files ? 870
Lines ? 51132
Branches ? 10319
=======================================
Hits ? 31362
Misses ? 18632
Partials ? 1138 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Move building the GoogleAuth options into authClientOptions() so it can be tested, and test it: the no-keep-alive agent without a proxy, no agent with one, the caller's options kept, and a token request through a transporter with these options reaching a local proxy as a CONNECT tunnel. That last test fails without the fix (no request reaches the proxy).
|
Thanks for the review, @joehan! I added tests in 7597f54:
|
gaxios skips the proxy for hosts NO_PROXY (or no_proxy) lists, so the token-request test failed on a machine where it covers the test host. Save and clear both with the other proxy variables.
Description
Fixes #11595.
Since 15.22.3 (#10717),
getAuthClient()insrc/requireAuth.tssetstransporterOptions.agenttoapiv2.noKeepAliveAgent. gaxios uses a caller-supplied agent as is and skips itsHTTPS_PROXYhandling, and Node.js does not applyNODE_USE_ENV_PROXYto custom agents. So OAuth token requests skip the proxy, and in proxy-only environments (CI runners withGOOGLE_APPLICATION_CREDENTIALS) commands hang aftercommand requires scopesand then fail.This adds
authTransporterAgent()toapiv2.ts, which returns the no-keep-alive agent only when no proxy is set in the environment.getAuthClient()passes the agent only when there is one. This matches the premature-close retry inapiv2.ts, which already skips its no-keep-alive agent when a proxy is set. Without a proxy, behavior is unchanged.Scenarios Tested
apiv2.spec.ts:authTransporterAgent()returns the no-keep-alive agent with no proxy, andundefinedfor each ofHTTPS_PROXY,https_proxy,HTTP_PROXYandhttp_proxy.requireAuth({})withHTTPS_PROXYpointing at a local proxy andGOOGLE_APPLICATION_CREDENTIALSpointing at a fake service-account key.CONNECT www.googleapis.com:443and the call fails withinvalid_grant, as expected for a fake key (same as 15.22.2 in the issue).main: the proxy receives nothing; the token request goes direct.npm run mocha: 6145 passing. The 2 failures (should return expected tsc path,should output the date in the correct format) also fail onmainon my machine.tsc --noEmit, eslint (no new warnings) and prettier pass.Sample Commands
No command or flag changes. Reproduction from the issue: