@@ -24,105 +24,6 @@ import {
2424 TunnelStatus ,
2525} from '@aws-sdk/client-iotsecuretunneling'
2626import { AwsStub , mockClient } from 'aws-sdk-client-mock'
27- import * as http from 'http'
28- import { AWSClientBuilderV3 } from '../../../shared/awsClientBuilderV3'
29- import { FakeAwsContext } from '../../utilities/fakeAwsContext'
30- import { Any } from '../../../shared/utilities/typeConstructors'
31-
32- describe ( 'Remote Debugging User-Agent test' , ( ) => {
33- let sandbox : sinon . SinonSandbox
34- let ldkClient : LdkClient
35- let mockServer : http . Server
36- let capturedHeaders : http . IncomingHttpHeaders | undefined
37- let sdkBuilderTmp : Any
38-
39- before ( async ( ) => {
40- sdkBuilderTmp = globals . sdkClientBuilderV3
41-
42- mockServer = http . createServer ( ( req , res ) => {
43- capturedHeaders = req . headers
44- res . writeHead ( 200 , { 'Content-Type' : 'application/json' } )
45- res . end ( )
46- } )
47-
48- // Start the mock server
49- await new Promise < void > ( ( resolve ) => {
50- mockServer . listen ( 0 , '127.0.0.1' , ( ) => {
51- resolve ( )
52- } )
53- } )
54-
55- const port = ( mockServer . address ( ) as any ) . port
56- globals . sdkClientBuilderV3 = new AWSClientBuilderV3 (
57- new FakeAwsContext ( {
58- contextCredentials : {
59- endpointUrl : `http://127.0.0.1:${ port } ` ,
60- credentials : undefined as any ,
61- credentialsId : '' ,
62- } ,
63- } )
64- )
65- } )
66-
67- beforeEach ( ( ) => {
68- sandbox = sinon . createSandbox ( )
69- sandbox . stub ( telemetryUtil , 'getClientId' ) . returns ( 'test-client-id' )
70- capturedHeaders = undefined
71-
72- ldkClient = LdkClient . instance
73- ldkClient . dispose ( )
74- } )
75-
76- afterEach ( ( ) => {
77- sandbox . restore ( )
78- } )
79-
80- after ( async ( ) => {
81- globals . sdkClientBuilderV3 = sdkBuilderTmp
82- // Close the server
83- await new Promise < void > ( ( resolve ) => {
84- mockServer . close ( ( ) => resolve ( ) )
85- } )
86- } )
87-
88- for ( const scenario of [ 'Lambda' , 'IoT' ] ) {
89- it ( `should send ${ scenario } request with correct User-Agent header to mock server` , async ( ) => {
90- try {
91- switch ( scenario ) {
92- case 'Lambda' :
93- await ldkClient . getFunctionDetail ( 'arn:aws:lambda:us-east-1:123456789012:function:testFunction' )
94- break
95- case 'IoT' :
96- await ldkClient . createOrReuseTunnel ( 'us-east-1' )
97- break
98- }
99- } catch ( e ) {
100- // Ignore errors from the mock response, we just want to capture headers
101- }
102-
103- // Verify the User-Agent header was sent correctly
104- assert ( capturedHeaders , 'Should have captured request headers' )
105- const userAgent = capturedHeaders ! [ 'user-agent' ] || capturedHeaders ! [ 'User-Agent' ]
106- assert ( userAgent , 'Should have User-Agent header' )
107-
108- // The User-Agent should contain our custom user agent pairs
109- assert (
110- userAgent . includes ( 'LAMBDA-DEBUG/1.0.0' ) ,
111- `User-Agent should include LAMBDA-DEBUG/1.0.0, got: ${ userAgent } `
112- )
113- // Check for presence of other user agent components without checking specific values
114- assert (
115- userAgent . includes ( 'AWS-Toolkit-For-VSCode/' ) ,
116- `User-Agent should include AWS-Toolkit-For-VSCode/, got: ${ userAgent } `
117- )
118- assert (
119- userAgent . includes ( 'Visual-Studio-Code' ) ,
120- `User-Agent should include Visual-Studio-Code, got: ${ userAgent } `
121- )
122- assert ( userAgent . includes ( 'ClientId/' ) , `User-Agent should include ClientId/, got: ${ userAgent } ` )
123- } )
124- }
125- } )
12627
12728describe ( 'LdkClient' , ( ) => {
12829 let sandbox : sinon . SinonSandbox
0 commit comments