diff --git a/CHANGELOG.md b/CHANGELOG.md index 938983a3..7fae51c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Thrift proxy Basic authentication now preserves URL-reserved characters in `proxy.auth.username` and `proxy.auth.password`; callers should continue passing unencoded credentials. - The Thrift token federation exchange (`enableTokenFederation`) now goes through the connection's agent, so `proxy`, `checkServerCertificate`, `customCaCert` and `clientCert`/`clientKey` apply to it. Previously it connected directly with Node's default agent, so behind a required proxy the exchange failed and the driver fell back to the original token. (#611) - Kernel backend: a failed status poll while waiting for a statement (a `runAsync: true` statement, or a default execution that outlives the server's inline wait) and a failed result fetch in `hasMoreRows()` now throw the mapped driver error, such as `HiveDriverError: HTTP 500: Internal Server Error` once retries on HTTP 5xx run out, instead of a raw `Error` whose message is the internal `__databricks_error__:{...}` envelope. As in `fetchChunk()`, a failed fetch in `hasMoreRows()` also closes the statement. (#608) - Honor `cloudFetchConcurrentDownloads` when opening kernel sessions, with a default window of 16 and explicit chunk-setting overrides. Values other than positive safe integers raise `HiveDriverError` at session open. diff --git a/lib/connection/connections/HttpConnection.ts b/lib/connection/connections/HttpConnection.ts index 6472265a..904a45cc 100644 --- a/lib/connection/connections/HttpConnection.ts +++ b/lib/connection/connections/HttpConnection.ts @@ -183,7 +183,7 @@ export default class HttpConnection implements IConnectionProvider { private createProxyAgent(proxyOptions: ProxyOptions): ProxyAgent { const proxyAuth = proxyOptions.auth?.username - ? `${proxyOptions.auth.username}:${proxyOptions.auth?.password ?? ''}@` + ? `${encodeURIComponent(proxyOptions.auth.username)}:${encodeURIComponent(proxyOptions.auth?.password ?? '')}@` : ''; const proxyUrl = `${proxyOptions.protocol}://${proxyAuth}${proxyOptions.host}:${proxyOptions.port}`; diff --git a/tests/unit/connection/connections/HttpConnection.test.ts b/tests/unit/connection/connections/HttpConnection.test.ts index 5dbfa5aa..7e4787ce 100644 --- a/tests/unit/connection/connections/HttpConnection.test.ts +++ b/tests/unit/connection/connections/HttpConnection.test.ts @@ -333,6 +333,7 @@ describe('HttpConnection through an HTTP CONNECT proxy', () => { let proxy: http.Server; let proxyConnects = 0; + let proxyAuthorization: string | undefined; const tunnels = new Set(); const agents: Array = []; @@ -381,6 +382,7 @@ describe('HttpConnection through an HTTP CONNECT proxy', () => { proxy = http.createServer(); proxy.on('connect', (req: http.IncomingMessage, clientSocket: net.Socket, head: Buffer) => { proxyConnects += 1; + proxyAuthorization = req.headers['proxy-authorization']; const upstream = net.connect(Number(String(req.url).split(':')[1]), '127.0.0.1', () => { clientSocket.write('HTTP/1.1 200 Connection Established\r\n\r\n'); upstream.write(head); @@ -404,6 +406,7 @@ describe('HttpConnection through an HTTP CONNECT proxy', () => { serverRequests = 0; clientCertCN = undefined; proxyConnects = 0; + proxyAuthorization = undefined; }); afterEach(() => { @@ -508,4 +511,37 @@ describe('HttpConnection through an HTTP CONNECT proxy', () => { expect(serverRequests).to.equal(1); expect(clientCertCN).to.equal('localhost'); }); + + const proxyAuthCases = [ + { name: 'ordinary credentials', username: 'proxy-user', password: 'proxy-password' }, + { name: 'an empty password', username: 'proxy-user', password: '' }, + { name: 'an omitted password', username: 'proxy-user', password: undefined }, + ...['username', 'password'].flatMap((component) => + ['/', '#', '?', '@'].map((character) => ({ + name: `${character} in the ${component}`, + username: 'proxy-user', + password: 'proxy-password', + [component]: `before${character}after`, + })), + ), + { name: 'reserved characters in both components', username: 'user/#?@', password: 'password/#?@' }, + ]; + + for (const { name, username, password } of proxyAuthCases) { + it(`should preserve proxy Basic authentication with ${name}`, async () => { + await post({ + ca: cert, + proxy: { + protocol: 'http', + host: '127.0.0.1', + port: (proxy.address() as net.AddressInfo).port, + auth: { username, password }, + }, + }); + + expect(proxyAuthorization).to.equal(`Basic ${Buffer.from(`${username}:${password ?? ''}`).toString('base64')}`); + expect(proxyConnects).to.equal(1); + expect(serverRequests).to.equal(1); + }); + } });