@@ -84,7 +84,14 @@ describe("Credentials", () => {
8484 } ,
8585 ] ) ( "$description" , async ( { apiTokenIssuer, expectedUrl } ) => {
8686 const parsedUrl = new URL ( expectedUrl ) ;
87- const scope = nock ( `${ parsedUrl . protocol } //${ parsedUrl . host } ` )
87+ // Use hostname instead of host to avoid port issues, then add port explicitly if non-default
88+ const isDefaultPort = ( parsedUrl . protocol === "https:" && parsedUrl . port === "" ) ||
89+ ( parsedUrl . protocol === "http:" && parsedUrl . port === "" ) ;
90+ const baseUrl = isDefaultPort
91+ ? `${ parsedUrl . protocol } //${ parsedUrl . hostname } `
92+ : `${ parsedUrl . protocol } //${ parsedUrl . hostname } :${ parsedUrl . port } ` ;
93+
94+ const scope = nock ( baseUrl )
8895 . post ( parsedUrl . pathname + parsedUrl . search )
8996 . reply ( 200 , {
9097 access_token : "test-token" ,
@@ -160,7 +167,14 @@ describe("Credentials", () => {
160167 }
161168 ] ) ( "should normalize audience from apiTokenIssuer when using PrivateKeyJWT client credentials ($description)" , async ( { apiTokenIssuer, expectedUrl, expectedAudience } ) => {
162169 const parsedUrl = new URL ( expectedUrl ) ;
163- const scope = nock ( `${ parsedUrl . protocol } //${ parsedUrl . host } ` )
170+ // Use hostname instead of host to avoid port issues, then add port explicitly if non-default
171+ const isDefaultPort = ( parsedUrl . protocol === "https:" && parsedUrl . port === "" ) ||
172+ ( parsedUrl . protocol === "http:" && parsedUrl . port === "" ) ;
173+ const baseUrl = isDefaultPort
174+ ? `${ parsedUrl . protocol } //${ parsedUrl . hostname } `
175+ : `${ parsedUrl . protocol } //${ parsedUrl . hostname } :${ parsedUrl . port } ` ;
176+
177+ const scope = nock ( baseUrl )
164178 . post ( parsedUrl . pathname , ( body : string ) => {
165179 const params = new URLSearchParams ( body ) ;
166180 const clientAssertion = params . get ( "client_assertion" ) as string ;
0 commit comments