Skip to content

Commit 0712a51

Browse files
committed
test(clients): user agent is set
1 parent 6fa3a9e commit 0712a51

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

packages/core/src/auth/sso/clients.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { getUserAgent, withTelemetryContext } from '../../shared/telemetry/util'
3939

4040
export class OidcClient {
4141
public constructor(
42-
private readonly client: SSOOIDC,
42+
public readonly client: SSOOIDC,
4343
private readonly clock: { Date: typeof Date }
4444
) {}
4545

@@ -157,7 +157,7 @@ export class SsoClient {
157157
}
158158

159159
public constructor(
160-
private readonly client: PromisifyClient<SSO>,
160+
public readonly client: PromisifyClient<SSO>,
161161
private readonly provider: SsoAccessTokenProvider
162162
) {}
163163

packages/core/src/shared/clients/codewhispererChatClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { AuthUtil } from '../../codewhisperer/util/authUtil'
99
import { getUserAgent } from '../telemetry/util'
1010

1111
// Create a client for featureDev streaming based off of aws sdk v3
12-
export async function createCodeWhispererChatStreamingClient(): Promise<CodeWhispererStreaming> {
13-
const bearerToken = await AuthUtil.instance.getBearerToken()
12+
export async function createCodeWhispererChatStreamingClient(bearerToken?: string): Promise<CodeWhispererStreaming> {
13+
bearerToken = bearerToken ?? (await AuthUtil.instance.getBearerToken())
1414
const cwsprConfig = getCodewhispererConfig()
1515
const streamingClient = new CodeWhispererStreaming({
1616
region: cwsprConfig.region,
1717
endpoint: cwsprConfig.endpoint,
1818
token: { token: bearerToken },
19-
customUserAgent: getUserAgent(),
19+
customUserAgent: getUserAgent({ includePlatform: true, includeClientId: true }),
2020
// SETTING max attempts to 0 FOR BETA. RE-ENABLE FOR RE-INVENT
2121
// Implement exponential back off starting with a base of 500ms (500 + attempt^10)
2222
retryStrategy: new ConfiguredRetryStrategy(0, (attempt: number) => 500 + attempt ** 10),

packages/core/src/shared/fs/fs.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,12 @@ export class FileSystem {
380380
}
381381

382382
/**
383-
* Change permissions on file. Note that this will do nothing on browser.
383+
* Sets file permissions flags.
384+
*
385+
* Platform notes:
386+
* - web-mode: skipped
387+
* - Windows: only affects "write" permission, and group/owner/other is not implemented.
388+
*
384389
* @param uri file whose permissions should be set.
385390
* @param mode new permissions in octal notation.
386391
* More info: https://nodejs.org/api/fs.html#fspromiseschmodpath-mode
@@ -389,6 +394,8 @@ export class FileSystem {
389394
async chmod(uri: vscode.Uri | string, mode: number): Promise<void> {
390395
if (!this.isWeb) {
391396
const path = toUri(uri)
397+
// Note: https://nodejs.org/api/fs.html#fschmodpath-mode-callback
398+
// on Windows only the write permission is/can be changed. group/owner/other is not implemented.
392399
await chmod(path.fsPath, mode)
393400
}
394401
}

packages/core/src/test/shared/defaultAwsClientBuilder.test.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,37 @@ import { AWSError, Request, Service } from 'aws-sdk'
88
import { version } from 'vscode'
99
import { AWSClientBuilder, DefaultAWSClientBuilder } from '../../shared/awsClientBuilder'
1010
import { DevSettings } from '../../shared/settings'
11-
import { getClientId } from '../../shared/telemetry/util'
11+
import { getClientId, getUserAgent } from '../../shared/telemetry/util'
1212
import { FakeMemento } from '../fakeExtensionContext'
1313
import { FakeAwsContext } from '../utilities/fakeAwsContext'
1414
import { TestSettings } from '../utilities/testSettingsConfiguration'
1515
import { GlobalState } from '../../shared/globalState'
16+
import { createCodeWhispererChatStreamingClient } from '../../shared/clients/codewhispererChatClient'
17+
import { OidcClient, SsoClient } from '../../auth/sso/clients'
1618

17-
describe('DefaultAwsClientBuilder', function () {
19+
describe('AwsClientBuilder', function () {
1820
let builder: AWSClientBuilder
1921

2022
beforeEach(function () {
2123
builder = new DefaultAWSClientBuilder(new FakeAwsContext())
2224
})
2325

26+
it('service clients set user agent', async function () {
27+
const userAgent = getUserAgent({ includePlatform: true, includeClientId: true })
28+
29+
const cwclient = await createCodeWhispererChatStreamingClient('fake-token')
30+
assert.deepStrictEqual(cwclient.config.customUserAgent, [[userAgent]])
31+
32+
const oidcClient = OidcClient.create('us-east-2')
33+
assert.deepStrictEqual(oidcClient.client.config.customUserAgent, [[userAgent]])
34+
35+
const ssoClient = SsoClient.create('us-east-2', {} as any)
36+
assert.deepStrictEqual(ssoClient.client.config.customUserAgent, [[userAgent]])
37+
38+
const awsService = await builder.createAwsService(Service)
39+
assert.deepStrictEqual(awsService.config.customUserAgent, userAgent)
40+
})
41+
2442
describe('createAndConfigureSdkClient', function () {
2543
it('includes Toolkit user-agent if no options are specified', async function () {
2644
const service = await builder.createAwsService(Service)

0 commit comments

Comments
 (0)