@@ -17,16 +17,16 @@ const progressUpdateResponseStub: TProgressUpdateResp = {
1717describe ( '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 ( / ^ 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 + / ) ;
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