Skip to content

Commit f48650f

Browse files
committed
removed clientId from userAgent string
Signed-off-by: Shivam Raj <[email protected]>
1 parent b755e62 commit f48650f

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ jobs:
4545
with:
4646
node-version: ${{ matrix.node-version }}
4747
- uses: actions/checkout@v3
48+
- name: Set up Python 3.10 for Node 14
49+
if: ${{ matrix.node-version == '14' }}
50+
uses: actions/setup-python@v4
51+
with:
52+
python-version: '3.10'
4853
- name: Cache node modules
4954
uses: actions/cache@v3
5055
with:

lib/DBSQLClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
111111
socketTimeout: options.socketTimeout,
112112
proxy: options.proxy,
113113
headers: {
114-
'User-Agent': buildUserAgentString(options.clientId),
114+
'User-Agent': buildUserAgentString(),
115115
},
116116
};
117117
}

lib/utils/buildUserAgentString.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function getOperatingSystemVersion(): string {
1111
return `${os.type()} ${os.release()}`;
1212
}
1313

14-
export default function buildUserAgentString(clientId?: string): string {
15-
const extra = [clientId, getNodeVersion(), getOperatingSystemVersion()].filter(Boolean);
14+
export default function buildUserAgentString(): string {
15+
const extra = [getNodeVersion(), getOperatingSystemVersion()].filter(Boolean);
1616
return `${productName}/${packageVersion} (${extra.join('; ')})`;
1717
}

tests/unit/utils/utils.test.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ const progressUpdateResponseStub: TProgressUpdateResp = {
1717
describe('buildUserAgentString', () => {
1818
// It should follow https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3 and
1919
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
20+
// UserAgent ::= <ProductName> '/' <ProductVersion> '(' <Comment> ')'
21+
// where:
22+
// <ProductName> is "NodejsDatabricksSqlConnector"
23+
// <ProductVersion> is three period-separated digits (optionally with a suffix)
24+
// <Comment> is "Node.js <NodeJsVersion>; <OSPlatform> <OSVersion>"
2025
//
21-
// UserAgent ::= <ProductName> '/' <ProductVersion> '(' <Comment> ')'
22-
// ProductName ::= 'NodejsDatabricksSqlConnector'
23-
// <Comment> ::= [ <ClientId> ';' ] 'Node.js' <NodeJsVersion> ';' <OSPlatform> <OSVersion>
24-
//
25-
// Examples:
26-
// - with <ClientId> provided: NodejsDatabricksSqlConnector/0.1.8-beta.1 (Client ID; Node.js 16.13.1; Darwin 21.5.0)
27-
// - without <ClientId> provided: NodejsDatabricksSqlConnector/0.1.8-beta.1 (Node.js 16.13.1; Darwin 21.5.0)
26+
// Example:
27+
// - NodejsDatabricksSqlConnector/0.1.8-beta.1 (Node.js 16.13.1; Darwin 21.5.0)
2828

29-
function checkUserAgentString(ua: string, clientId?: string) {
29+
function checkUserAgentString(ua: string) {
3030
// Prefix: 'NodejsDatabricksSqlConnector/'
3131
// Version: three period-separated digits and optional suffix
3232
const re =
@@ -36,20 +36,16 @@ describe('buildUserAgentString', () => {
3636

3737
const { comment } = match?.groups ?? {};
3838

39-
expect(comment.split(';').length).to.be.gte(2); // at least Node and OS version should be there
39+
const parts = comment.split(';').map((s) => s.trim());
40+
expect(parts.length).to.be.gte(2); // at least Node and OS version should be there
4041

41-
if (clientId) {
42-
expect(comment.trim()).to.satisfy((s: string) => s.startsWith(`${clientId};`));
43-
}
42+
// First part should start with "Node.js" followed by a version number.
43+
expect(parts[0]).to.match(/^Node\.js\s+\d+\.\d+\.\d+/);
44+
// Second part should represent the OS platform (a word) and OS version.
45+
expect(parts[1]).to.match(/^\w+/);
4446
}
4547

46-
it('matches pattern with clientId', () => {
47-
const clientId = 'Some Client ID';
48-
const ua = buildUserAgentString(clientId);
49-
checkUserAgentString(ua, clientId);
50-
});
51-
52-
it('matches pattern without clientId', () => {
48+
it('matches pattern', () => {
5349
const ua = buildUserAgentString();
5450
checkUserAgentString(ua);
5551
});

0 commit comments

Comments
 (0)