Skip to content

Commit 1f54ad4

Browse files
committed
add test to ensure user-agent are correct
1 parent d91fd77 commit 1f54ad4

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

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', () => {

packages/toolkit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4546,7 +4546,7 @@
45464546
"description": "%AWS.toolkit.lambda.walkthrough.description%",
45474547
"when": "workspacePlatform != webworker",
45484548
"steps": [
4549-
{
4549+
{
45504550
"id": "toolInstallWindows",
45514551
"title": "%AWS.toolkit.lambda.walkthrough.toolInstall.title%",
45524552
"description": "%AWS.toolkit.lambda.walkthrough.toolInstall.description.windows%",
@@ -4564,7 +4564,7 @@
45644564
"image": "./resources/walkthrough/appBuilder/install.png",
45654565
"altText": "Showing GUI installer"
45664566
},
4567-
"when": "!isWindows"
4567+
"when": "!isWindows"
45684568
},
45694569
{
45704570
"id": "chooseTemplate",

0 commit comments

Comments
 (0)