From 962f9b097d2b06ae28dfdcd46ba9668d63d5e5c3 Mon Sep 17 00:00:00 2001 From: Shivam Raj Date: Sat, 8 Feb 2025 00:17:18 +0530 Subject: [PATCH 1/2] removed clientId from userAgent string Signed-off-by: Shivam Raj --- .github/workflows/main.yml | 5 +++++ lib/DBSQLClient.ts | 2 +- lib/utils/buildUserAgentString.ts | 4 ++-- tests/unit/utils/utils.test.ts | 34 ++++++++++++++----------------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 64a5dfd0..e854e459 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,6 +45,11 @@ jobs: with: node-version: ${{ matrix.node-version }} - uses: actions/checkout@v3 + - name: Set up Python 3.10 for Node 14 + if: ${{ matrix.node-version == '14' }} + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: Cache node modules uses: actions/cache@v3 with: diff --git a/lib/DBSQLClient.ts b/lib/DBSQLClient.ts index d3d9427c..923608ae 100644 --- a/lib/DBSQLClient.ts +++ b/lib/DBSQLClient.ts @@ -111,7 +111,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I socketTimeout: options.socketTimeout, proxy: options.proxy, headers: { - 'User-Agent': buildUserAgentString(options.clientId), + 'User-Agent': buildUserAgentString(), }, }; } diff --git a/lib/utils/buildUserAgentString.ts b/lib/utils/buildUserAgentString.ts index ce26fcfd..b6932f81 100644 --- a/lib/utils/buildUserAgentString.ts +++ b/lib/utils/buildUserAgentString.ts @@ -11,7 +11,7 @@ function getOperatingSystemVersion(): string { return `${os.type()} ${os.release()}`; } -export default function buildUserAgentString(clientId?: string): string { - const extra = [clientId, getNodeVersion(), getOperatingSystemVersion()].filter(Boolean); +export default function buildUserAgentString(): string { + const extra = [getNodeVersion(), getOperatingSystemVersion()].filter(Boolean); return `${productName}/${packageVersion} (${extra.join('; ')})`; } diff --git a/tests/unit/utils/utils.test.ts b/tests/unit/utils/utils.test.ts index f94e88c4..d76e480f 100644 --- a/tests/unit/utils/utils.test.ts +++ b/tests/unit/utils/utils.test.ts @@ -17,16 +17,16 @@ const progressUpdateResponseStub: TProgressUpdateResp = { describe('buildUserAgentString', () => { // It should follow https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3 and // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent + // UserAgent ::= '/' '(' ')' + // where: + // is "NodejsDatabricksSqlConnector" + // is three period-separated digits (optionally with a suffix) + // is "Node.js ; " // - // UserAgent ::= '/' '(' ')' - // ProductName ::= 'NodejsDatabricksSqlConnector' - // ::= [ ';' ] 'Node.js' ';' - // - // Examples: - // - with provided: NodejsDatabricksSqlConnector/0.1.8-beta.1 (Client ID; Node.js 16.13.1; Darwin 21.5.0) - // - without provided: NodejsDatabricksSqlConnector/0.1.8-beta.1 (Node.js 16.13.1; Darwin 21.5.0) + // Example: + // - NodejsDatabricksSqlConnector/0.1.8-beta.1 (Node.js 16.13.1; Darwin 21.5.0) - function checkUserAgentString(ua: string, clientId?: string) { + function checkUserAgentString(ua: string) { // Prefix: 'NodejsDatabricksSqlConnector/' // Version: three period-separated digits and optional suffix const re = @@ -36,20 +36,16 @@ describe('buildUserAgentString', () => { const { comment } = match?.groups ?? {}; - expect(comment.split(';').length).to.be.gte(2); // at least Node and OS version should be there + const parts = comment.split(';').map((s) => s.trim()); + expect(parts.length).to.be.gte(2); // at least Node and OS version should be there - if (clientId) { - expect(comment.trim()).to.satisfy((s: string) => s.startsWith(`${clientId};`)); - } + // First part should start with "Node.js" followed by a version number. + expect(parts[0]).to.match(/^Node\.js\s+\d+\.\d+\.\d+/); + // Second part should represent the OS platform (a word) and OS version. + expect(parts[1]).to.match(/^\w+/); } - it('matches pattern with clientId', () => { - const clientId = 'Some Client ID'; - const ua = buildUserAgentString(clientId); - checkUserAgentString(ua, clientId); - }); - - it('matches pattern without clientId', () => { + it('matches pattern', () => { const ua = buildUserAgentString(); checkUserAgentString(ua); }); From 2e01cc7ce0d98851a36cd50f4a1f0e03024e181b Mon Sep 17 00:00:00 2001 From: Shivam Raj Date: Sat, 8 Feb 2025 01:21:24 +0530 Subject: [PATCH 2/2] recalled workflow change Signed-off-by: Shivam Raj --- .github/workflows/main.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e854e459..64a5dfd0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,11 +45,6 @@ jobs: with: node-version: ${{ matrix.node-version }} - uses: actions/checkout@v3 - - name: Set up Python 3.10 for Node 14 - if: ${{ matrix.node-version == '14' }} - uses: actions/setup-python@v4 - with: - python-version: '3.10' - name: Cache node modules uses: actions/cache@v3 with: