@@ -17,16 +17,16 @@ const progressUpdateResponseStub: TProgressUpdateResp = {
17
17
describe ( 'buildUserAgentString' , ( ) => {
18
18
// It should follow https://www.rfc-editor.org/rfc/rfc7231#section-5.5.3 and
19
19
// 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>"
20
25
//
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)
28
28
29
- function checkUserAgentString ( ua : string , clientId ?: string ) {
29
+ function checkUserAgentString ( ua : string ) {
30
30
// Prefix: 'NodejsDatabricksSqlConnector/'
31
31
// Version: three period-separated digits and optional suffix
32
32
const re =
@@ -36,20 +36,16 @@ describe('buildUserAgentString', () => {
36
36
37
37
const { comment } = match ?. groups ?? { } ;
38
38
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
40
41
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 ( / ^ N o d e \. j s \s + \d + \. \d + \. \d + / ) ;
44
+ // Second part should represent the OS platform (a word) and OS version.
45
+ expect ( parts [ 1 ] ) . to . match ( / ^ \w + / ) ;
44
46
}
45
47
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' , ( ) => {
53
49
const ua = buildUserAgentString ( ) ;
54
50
checkUserAgentString ( ua ) ;
55
51
} ) ;
0 commit comments