Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(clients): user agent is set #5763

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/auth/sso/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { getUserAgent, withTelemetryContext } from '../../shared/telemetry/util'

export class OidcClient {
public constructor(
private readonly client: SSOOIDC,
public readonly client: SSOOIDC,
private readonly clock: { Date: typeof Date }
) {}

Expand Down Expand Up @@ -157,7 +157,7 @@ export class SsoClient {
}

public constructor(
private readonly client: PromisifyClient<SSO>,
public readonly client: PromisifyClient<SSO>,
private readonly provider: SsoAccessTokenProvider
) {}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/shared/clients/codewhispererChatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { AuthUtil } from '../../codewhisperer/util/authUtil'
import { getUserAgent } from '../telemetry/util'

// Create a client for featureDev streaming based off of aws sdk v3
export async function createCodeWhispererChatStreamingClient(): Promise<CodeWhispererStreaming> {
const bearerToken = await AuthUtil.instance.getBearerToken()
export async function createCodeWhispererChatStreamingClient(bearerToken?: string): Promise<CodeWhispererStreaming> {
bearerToken = bearerToken ?? (await AuthUtil.instance.getBearerToken())
const cwsprConfig = getCodewhispererConfig()
const streamingClient = new CodeWhispererStreaming({
region: cwsprConfig.region,
endpoint: cwsprConfig.endpoint,
token: { token: bearerToken },
customUserAgent: getUserAgent(),
customUserAgent: getUserAgent({ includePlatform: true, includeClientId: true }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have these true by default?

// SETTING max attempts to 0 FOR BETA. RE-ENABLE FOR RE-INVENT
// Implement exponential back off starting with a base of 500ms (500 + attempt^10)
retryStrategy: new ConfiguredRetryStrategy(0, (attempt: number) => 500 + attempt ** 10),
Expand Down
22 changes: 20 additions & 2 deletions packages/core/src/test/shared/defaultAwsClientBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,37 @@ import { AWSError, Request, Service } from 'aws-sdk'
import { version } from 'vscode'
import { AWSClientBuilder, DefaultAWSClientBuilder } from '../../shared/awsClientBuilder'
import { DevSettings } from '../../shared/settings'
import { getClientId } from '../../shared/telemetry/util'
import { getClientId, getUserAgent } from '../../shared/telemetry/util'
import { FakeMemento } from '../fakeExtensionContext'
import { FakeAwsContext } from '../utilities/fakeAwsContext'
import { TestSettings } from '../utilities/testSettingsConfiguration'
import { GlobalState } from '../../shared/globalState'
import { createCodeWhispererChatStreamingClient } from '../../shared/clients/codewhispererChatClient'
import { OidcClient, SsoClient } from '../../auth/sso/clients'

describe('DefaultAwsClientBuilder', function () {
describe('AwsClientBuilder', function () {
let builder: AWSClientBuilder

beforeEach(function () {
builder = new DefaultAWSClientBuilder(new FakeAwsContext())
})

it('service clients set user agent', async function () {
const userAgent = getUserAgent({ includePlatform: true, includeClientId: true })

const cwclient = await createCodeWhispererChatStreamingClient('fake-token')
assert.deepStrictEqual(cwclient.config.customUserAgent, [[userAgent]])

const oidcClient = OidcClient.create('us-east-2')
assert.deepStrictEqual(oidcClient.client.config.customUserAgent, [[userAgent]])

const ssoClient = SsoClient.create('us-east-2', {} as any)
assert.deepStrictEqual(ssoClient.client.config.customUserAgent, [[userAgent]])

const awsService = await builder.createAwsService(Service)
assert.deepStrictEqual(awsService.config.customUserAgent, userAgent)
})

describe('createAndConfigureSdkClient', function () {
it('includes Toolkit user-agent if no options are specified', async function () {
const service = await builder.createAwsService(Service)
Expand Down
Loading