Skip to content
Draft
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/connection/connections/HttpConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;

Expand Down
36 changes: 36 additions & 0 deletions tests/unit/connection/connections/HttpConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<net.Socket>();

const agents: Array<http.Agent | undefined> = [];
Expand Down Expand Up @@ -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);
Expand All @@ -404,6 +406,7 @@ describe('HttpConnection through an HTTP CONNECT proxy', () => {
serverRequests = 0;
clientCertCN = undefined;
proxyConnects = 0;
proxyAuthorization = undefined;
});

afterEach(() => {
Expand Down Expand Up @@ -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);
});
}
});
Loading