From f13ee9ac255a64a7bdff201a85f5e3551bfa2607 Mon Sep 17 00:00:00 2001 From: AsafMah Date: Tue, 18 Apr 2023 13:04:11 +0300 Subject: [PATCH] Fix errors (#248) --- .eslintrc.js | 2 +- CHANGELOG.md | 7 ++++++- packages/azure-kusto-data/src/client.ts | 14 ++++++++++++-- .../azure-kusto-ingest/test/e2eTests/e2eTest.ts | 5 ++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9c206ad..ea00d80 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -148,7 +148,7 @@ module.exports = { "no-cond-assign": "error", "no-console": "error", "no-const-assign": "error", - "no-control-regex": "error", + "no-control-regex": "off", "no-debugger": "error", "no-delete-var": "error", "no-dupe-args": "error", diff --git a/CHANGELOG.md b/CHANGELOG.md index 9df8872..e84a974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [5.0.2] - 2023-03-20 +## [5.0.2] - 2023-04-18 + +### Fixed + +- Remove authorization header from errors +- Escape non-ascii headers to align with the service ### Added diff --git a/packages/azure-kusto-data/src/client.ts b/packages/azure-kusto-data/src/client.ts index b8915b2..4e745b2 100644 --- a/packages/azure-kusto-data/src/client.ts +++ b/packages/azure-kusto-data/src/client.ts @@ -207,6 +207,11 @@ export class KustoClient { timeout: number, properties?: ClientRequestProperties | null ): Promise { + // replace non-ascii characters with ? in headers + for (const key of Object.keys(headers)) { + headers[key] = headers[key].replace(/[^\x00-\x7F]+/g, "?"); + } + const axiosConfig: AxiosRequestConfig = { headers, timeout, @@ -216,8 +221,13 @@ export class KustoClient { try { axiosResponse = await this.axiosInstance.post(endpoint, payload, axiosConfig); } catch (error: unknown) { - if (axios.isAxiosError(error) && error.response) { - if (error.response.status === 429) { + if (axios.isAxiosError(error)) { + // Since it's impossible to modify the error request object, the only way to censor the Authorization header is to remove it. + error.request = undefined; + if (error?.config?.headers) { + error.config.headers.Authorization = ""; + } + if (error.response && error.response.status === 429) { throw new ThrottlingError("POST request failed with status 429 (Too Many Requests)", error); } } diff --git a/packages/azure-kusto-ingest/test/e2eTests/e2eTest.ts b/packages/azure-kusto-ingest/test/e2eTests/e2eTest.ts index 78730c4..6d4a54d 100644 --- a/packages/azure-kusto-ingest/test/e2eTests/e2eTest.ts +++ b/packages/azure-kusto-ingest/test/e2eTests/e2eTest.ts @@ -40,7 +40,7 @@ const main = (): void => { } const engineKcsb = ConnectionStringBuilder.withAadApplicationKeyAuthentication(process.env.ENGINE_CONNECTION_STRING ?? "", appId, appKey, tenantId); - engineKcsb.applicationNameForTracing = "NodeE2ETest"; + engineKcsb.applicationNameForTracing = "NodeE2ETest_ΓΈ"; const queryClient = new Client(engineKcsb); const streamingIngestClient = new StreamingIngestClient(engineKcsb); @@ -329,6 +329,9 @@ const main = (): void => { try { await queryClient.executeQuery(databaseName, "invalidSyntax "); } catch (ex) { + const exTyped = ex as { request: unknown; config: { headers: { [k: string]: string } } }; + assert.strictEqual(exTyped.request, undefined); + assert.strictEqual(exTyped.config.headers.Authorization, ""); return; } assert.fail(`General BadRequest`);