Skip to content

Commit 82ffa68

Browse files
Merge master into feature/inline-rollback
2 parents 69cbe54 + 4fdebc6 commit 82ffa68

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

packages/core/src/lambda/remoteDebugging/ldkClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'
1717
import { LocalProxy } from './localProxy'
1818
import globals from '../../shared/extensionGlobals'
1919
import { getLogger } from '../../shared/logger/logger'
20-
import { getIoTSTClientWithAgent, getLambdaClientWithAgent } from './utils'
20+
import { getIoTSTClientWithAgent, getLambdaClientWithAgent, getLambdaDebugUserAgent } from './utils'
2121
import { ToolkitError } from '../../shared/errors'
2222
import * as nls from 'vscode-nls'
2323

@@ -99,7 +99,7 @@ export class LdkClient {
9999
*/
100100
private getLambdaClient(region: string): DefaultLambdaClient {
101101
if (!this.lambdaClientCache.has(region)) {
102-
this.lambdaClientCache.set(region, getLambdaClientWithAgent(region))
102+
this.lambdaClientCache.set(region, getLambdaClientWithAgent(region, getLambdaDebugUserAgent()))
103103
}
104104
return this.lambdaClientCache.get(region)!
105105
}

packages/core/src/test/lambda/remoteDebugging/ldkClient.test.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,92 @@ describe('LdkClient', () => {
423423
assert.strictEqual(result, true, 'Should return true when no proxy to stop')
424424
})
425425
})
426+
427+
describe('Client User-Agent', () => {
428+
it('should create Lambda client with correct user-agent', async () => {
429+
// Restore the existing stub and create a new one to track calls
430+
const existingStub = (utils.getLambdaClientWithAgent as any).restore
431+
? (utils.getLambdaClientWithAgent as sinon.SinonStub)
432+
: undefined
433+
if (existingStub) {
434+
existingStub.restore()
435+
}
436+
437+
// Stub getUserAgent at the telemetryUtil level to return a known value
438+
const getUserAgentStub = sandbox.stub(telemetryUtil, 'getUserAgent')
439+
getUserAgentStub.returns('test-user-agent')
440+
441+
// Stub the sdkClientBuilderV3 to capture the client options
442+
let capturedClientOptions: any
443+
const createAwsServiceStub = sandbox.stub(globals.sdkClientBuilderV3, 'createAwsService')
444+
createAwsServiceStub.callsFake((options: any) => {
445+
capturedClientOptions = options
446+
// Return a mock Lambda client that has the required methods
447+
return {
448+
send: async () => ({
449+
Configuration: createMockFunctionConfig({
450+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:testFunction',
451+
}),
452+
}),
453+
middlewareStack: {} as any,
454+
destroy: () => {},
455+
} as any
456+
})
457+
458+
const mockFunctionConfig: FunctionConfiguration = createMockFunctionConfig({
459+
FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:testFunction',
460+
})
461+
462+
await ldkClient.getFunctionDetail(mockFunctionConfig.FunctionArn!)
463+
464+
assert(createAwsServiceStub.called, 'Should call createAwsService')
465+
assert.strictEqual(capturedClientOptions.clientOptions.region, 'us-east-1', 'Should use correct region')
466+
assert.deepStrictEqual(
467+
capturedClientOptions.clientOptions.userAgent,
468+
[['LAMBDA-DEBUG/1.0.0 test-user-agent']],
469+
'Should include correct user-agent with LAMBDA-DEBUG prefix in Lambda API calls'
470+
)
471+
})
472+
473+
it('should create IoT client with correct user-agent', async () => {
474+
// Restore the existing stub and create a new one to track calls
475+
const existingStub = (utils.getIoTSTClientWithAgent as any).restore
476+
? (utils.getIoTSTClientWithAgent as sinon.SinonStub)
477+
: undefined
478+
if (existingStub) {
479+
existingStub.restore()
480+
}
481+
482+
// Stub getUserAgent to return a known value
483+
const getUserAgentStub = sandbox.stub(telemetryUtil, 'getUserAgent')
484+
getUserAgentStub.returns('test-user-agent')
485+
486+
// Stub the sdkClientBuilderV3 to capture the client options
487+
let capturedClientOptions: any
488+
const createAwsServiceStub = sandbox.stub(globals.sdkClientBuilderV3, 'createAwsService')
489+
createAwsServiceStub.callsFake((options: any) => {
490+
capturedClientOptions = options
491+
return mockIoTSTClient as any
492+
})
493+
494+
mockIoTSTClient.on(ListTunnelsCommand).resolves({ tunnelSummaries: [] })
495+
mockIoTSTClient.on(OpenTunnelCommand).resolves({
496+
tunnelId: 'tunnel-123',
497+
sourceAccessToken: 'source-token',
498+
destinationAccessToken: 'dest-token',
499+
})
500+
501+
await ldkClient.createOrReuseTunnel('us-east-1')
502+
503+
assert(createAwsServiceStub.calledOnce, 'Should call createAwsService once')
504+
assert.strictEqual(capturedClientOptions.clientOptions.region, 'us-east-1', 'Should use correct region')
505+
assert.deepStrictEqual(
506+
capturedClientOptions.clientOptions.userAgent,
507+
[['LAMBDA-DEBUG/1.0.0 test-user-agent']],
508+
'Should include correct user-agent with LAMBDA-DEBUG prefix'
509+
)
510+
})
511+
})
426512
})
427513

428514
describe('Helper Functions', () => {

0 commit comments

Comments
 (0)