@@ -171,6 +171,50 @@ describe('DataPlaneClient tests', () => {
171171 ) ;
172172 } ) ;
173173
174+ test ( 'when the endpoint contains port then the fetch request url also contains the same port' , async ( ) => {
175+ // Init
176+ const endpoint = new URL ( 'https://localhost:8080' ) ;
177+ const client : DataPlaneClient = createDataPlaneClient ( {
178+ ...defaultConfig ,
179+ endpoint
180+ } ) ;
181+
182+ // Run
183+ await client . sendFetch ( Utils . PUT_RUM_EVENTS_REQUEST ) ;
184+
185+ // Assert
186+ const signedRequest : HttpRequest = (
187+ fetchHandler . mock . calls [ 0 ] as any
188+ ) [ 0 ] ;
189+ expect ( signedRequest . port ) . toEqual ( 8080 ) ;
190+ expect ( signedRequest . hostname ) . toEqual ( 'localhost' ) ;
191+ expect ( signedRequest . path ) . toEqual (
192+ `${ endpoint . pathname . replace ( / \/ $ / , '' ) } /appmonitors/application123`
193+ ) ;
194+ } ) ;
195+
196+ test ( 'when the endpoint does not contain port then the fetch request url also contains no port' , async ( ) => {
197+ // Init
198+ const endpoint = Utils . AWS_RUM_ENDPOINT ;
199+ const client : DataPlaneClient = createDataPlaneClient ( {
200+ ...defaultConfig ,
201+ endpoint
202+ } ) ;
203+
204+ // Run
205+ await client . sendFetch ( Utils . PUT_RUM_EVENTS_REQUEST ) ;
206+
207+ // Assert
208+ const signedRequest : HttpRequest = (
209+ fetchHandler . mock . calls [ 0 ] as any
210+ ) [ 0 ] ;
211+ expect ( signedRequest . port ) . toBeUndefined ( ) ;
212+ expect ( signedRequest . hostname ) . toEqual ( Utils . AWS_RUM_ENDPOINT . hostname ) ;
213+ expect ( signedRequest . path ) . toEqual (
214+ `${ endpoint . pathname . replace ( / \/ $ / , '' ) } /appmonitors/application123`
215+ ) ;
216+ } ) ;
217+
174218 test ( 'when the endpoint contains a path then the beacon request url contains the path prefix' , async ( ) => {
175219 // Init
176220 const endpoint = new URL ( `${ Utils . AWS_RUM_ENDPOINT } ${ 'prod' } ` ) ;
@@ -213,6 +257,52 @@ describe('DataPlaneClient tests', () => {
213257 ) ;
214258 } ) ;
215259
260+ test ( 'when the endpoint contains port then the beacon request url also contains the same port' , async ( ) => {
261+ // Init
262+ const endpoint = new URL ( 'https://localhost:8080' ) ;
263+ const client : DataPlaneClient = createDataPlaneClient ( {
264+ ...defaultConfig ,
265+ endpoint
266+ } ) ;
267+
268+ // Run
269+ await client . sendBeacon ( Utils . PUT_RUM_EVENTS_REQUEST ) ;
270+
271+ // Assert
272+ const signedRequest : HttpRequest = (
273+ beaconHandler . mock . calls [ 0 ] as any
274+ ) [ 0 ] ;
275+
276+ expect ( signedRequest . port ) . toEqual ( 8080 ) ;
277+ expect ( signedRequest . hostname ) . toEqual ( 'localhost' ) ;
278+ expect ( signedRequest . path ) . toEqual (
279+ `${ endpoint . pathname . replace ( / \/ $ / , '' ) } /appmonitors/application123`
280+ ) ;
281+ } ) ;
282+
283+ test ( 'when the endpoint does not contain port then the beacon request url also does not contains port' , async ( ) => {
284+ // Init
285+ const endpoint = Utils . AWS_RUM_ENDPOINT ;
286+ const client : DataPlaneClient = createDataPlaneClient ( {
287+ ...defaultConfig ,
288+ endpoint
289+ } ) ;
290+
291+ // Run
292+ await client . sendBeacon ( Utils . PUT_RUM_EVENTS_REQUEST ) ;
293+
294+ // Assert
295+ const signedRequest : HttpRequest = (
296+ beaconHandler . mock . calls [ 0 ] as any
297+ ) [ 0 ] ;
298+
299+ expect ( signedRequest . port ) . toBeUndefined ( ) ;
300+ expect ( signedRequest . hostname ) . toEqual ( Utils . AWS_RUM_ENDPOINT . hostname ) ;
301+ expect ( signedRequest . path ) . toEqual (
302+ `${ endpoint . pathname . replace ( / \/ $ / , '' ) } /appmonitors/application123`
303+ ) ;
304+ } ) ;
305+
216306 test ( 'when signing is disabled then sendFetch does not sign the request' , async ( ) => {
217307 // Init
218308 const client : DataPlaneClient = createDataPlaneClient ( {
0 commit comments