Skip to content

Commit

Permalink
chore: fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhoni77 committed Nov 9, 2023
1 parent f3412ce commit e7c6ef4
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 199 deletions.
53 changes: 31 additions & 22 deletions test/test.baseexternalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
// limitations under the License.

import * as assert from 'assert';
import { describe, it, afterEach } from 'mocha';
import {describe, it, afterEach} from 'mocha';
import * as nock from 'nock';
import * as sinon from 'sinon';
import { createCrypto } from '../src/crypto/crypto';
import { Credentials } from '../src/auth/credentials';
import { StsSuccessfulResponse } from '../src/auth/stscredentials';
import {createCrypto} from '../src/crypto/crypto';
import {Credentials} from '../src/auth/credentials';
import {StsSuccessfulResponse} from '../src/auth/stscredentials';
import {
EXPIRATION_TIME_OFFSET,
BaseExternalAccountClient,
Expand All @@ -29,7 +29,7 @@ import {
OAuthErrorResponse,
getErrorFromOAuthErrorResponse,
} from '../src/auth/oauth2common';
import { GaxiosError } from 'gaxios';
import {GaxiosError} from 'gaxios';
import {
assertGaxiosResponsePresent,
getAudience,
Expand All @@ -52,9 +52,7 @@ interface SampleResponse {
class TestExternalAccountClient extends BaseExternalAccountClient {
private counter = 0;

constructor(
options: BaseExternalAccountClientOptions
) {
constructor(options: BaseExternalAccountClientOptions) {
super(options);
this.credentialSourceType = 'test';
}
Expand Down Expand Up @@ -190,7 +188,7 @@ describe('BaseExternalAccountClient', () => {
);
const expectedWorkforcePoolUserProjectError = new Error(
'workforcePoolUserProject should not be set for non-workforce pool ' +
'credentials.'
'credentials.'
);

invalidWorkforceAudiences.forEach(invalidWorkforceAudience => {
Expand Down Expand Up @@ -246,9 +244,10 @@ describe('BaseExternalAccountClient', () => {
eagerRefreshThresholdMillis: 5000,
forceRefreshOnFailure: true,
};
const client = new TestExternalAccountClient(
{ ...externalAccountOptions, ...refreshOptions }
);
const client = new TestExternalAccountClient({
...externalAccountOptions,
...refreshOptions,
});

assert.strictEqual(
client.forceRefreshOnFailure,
Expand Down Expand Up @@ -974,7 +973,10 @@ describe('BaseExternalAccountClient', () => {
]);

// Override 5min threshold with 10 second threshold.
const client = new TestExternalAccountClient({ ...externalAccountOptions, eagerRefreshThresholdMillis: customThresh });
const client = new TestExternalAccountClient({
...externalAccountOptions,
eagerRefreshThresholdMillis: customThresh,
});
const actualResponse = await client.getAccessToken();

// Confirm raw GaxiosResponse appended to response.
Expand Down Expand Up @@ -1444,9 +1446,10 @@ describe('BaseExternalAccountClient', () => {
);

// Override 5min threshold with 10 second threshold.
const client = new TestExternalAccountClient(
{ ...externalAccountOptionsWithSA, eagerRefreshThresholdMillis: customThresh }
);
const client = new TestExternalAccountClient({
...externalAccountOptionsWithSA,
eagerRefreshThresholdMillis: customThresh,
});

const actualResponse = await client.getAccessToken();

Expand Down Expand Up @@ -1840,7 +1843,7 @@ describe('BaseExternalAccountClient', () => {
]);

const optionsWithQuotaProjectId = Object.assign(
{ quota_project_id: quotaProjectId },
{quota_project_id: quotaProjectId},
externalAccountOptions
);
const client = new TestExternalAccountClient(optionsWithQuotaProjectId);
Expand Down Expand Up @@ -1889,7 +1892,7 @@ describe('BaseExternalAccountClient', () => {
'x-goog-user-project': quotaProjectId,
};
const optionsWithQuotaProjectId = Object.assign(
{ quota_project_id: quotaProjectId },
{quota_project_id: quotaProjectId},
externalAccountOptions
);
const exampleRequest = {
Expand Down Expand Up @@ -1952,7 +1955,7 @@ describe('BaseExternalAccountClient', () => {
'x-goog-user-project': quotaProjectId,
};
const optionsWithQuotaProjectId = Object.assign(
{ quota_project_id: quotaProjectId },
{quota_project_id: quotaProjectId},
externalAccountOptionsWithSA
);
const exampleRequest = {
Expand Down Expand Up @@ -2016,7 +2019,7 @@ describe('BaseExternalAccountClient', () => {
'x-goog-user-project': quotaProjectId,
};
const optionsWithQuotaProjectId = Object.assign(
{ quota_project_id: quotaProjectId },
{quota_project_id: quotaProjectId},
externalAccountOptions
);
const exampleRequest = {
Expand Down Expand Up @@ -2275,7 +2278,10 @@ describe('BaseExternalAccountClient', () => {
.reply(200, Object.assign({}, exampleResponse)),
];

const client = new TestExternalAccountClient({ ...externalAccountOptions, forceRefreshOnFailure: true });
const client = new TestExternalAccountClient({
...externalAccountOptions,
forceRefreshOnFailure: true,
});
const actualResponse = await client.request<SampleResponse>({
url: 'https://example.com/api',
method: 'POST',
Expand Down Expand Up @@ -2398,7 +2404,10 @@ describe('BaseExternalAccountClient', () => {
.reply(403),
];

const client = new TestExternalAccountClient({ ...externalAccountOptions, forceRefreshOnFailure: true });
const client = new TestExternalAccountClient({
...externalAccountOptions,
forceRefreshOnFailure: true,
});
await assert.rejects(
client.request<SampleResponse>({
url: 'https://example.com/api',
Expand Down
43 changes: 18 additions & 25 deletions test/test.downscopedclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
// limitations under the License.

import * as assert from 'assert';
import { describe, it, beforeEach, afterEach } from 'mocha';
import {describe, it, beforeEach, afterEach} from 'mocha';
import * as nock from 'nock';
import * as sinon from 'sinon';

import { GaxiosError, GaxiosOptions, GaxiosPromise } from 'gaxios';
import { Credentials } from '../src/auth/credentials';
import { StsSuccessfulResponse } from '../src/auth/stscredentials';
import {GaxiosError, GaxiosOptions, GaxiosPromise} from 'gaxios';
import {Credentials} from '../src/auth/credentials';
import {StsSuccessfulResponse} from '../src/auth/stscredentials';
import {
DownscopedClient,
CredentialAccessBoundary,
MAX_ACCESS_BOUNDARY_RULES_COUNT,
} from '../src/auth/downscopedclient';
import { AuthClient } from '../src/auth/authclient';
import { mockStsTokenExchange } from './externalclienthelper';
import {AuthClient} from '../src/auth/authclient';
import {mockStsTokenExchange} from './externalclienthelper';
import {
OAuthErrorResponse,
getErrorFromOAuthErrorResponse,
} from '../src/auth/oauth2common';
import { GetAccessTokenResponse, Headers } from '../src/auth/oauth2client';
import {GetAccessTokenResponse, Headers} from '../src/auth/oauth2client';

nock.disableNetConnect();

Expand Down Expand Up @@ -135,7 +135,7 @@ describe('DownscopedClient', () => {
it('should throw when number of access boundary rules is exceeded', () => {
const expectedError = new Error(
'The provided access boundary has more than ' +
`${MAX_ACCESS_BOUNDARY_RULES_COUNT} access boundary rules.`
`${MAX_ACCESS_BOUNDARY_RULES_COUNT} access boundary rules.`
);
const cabWithExceedingAccessBoundaryRules: CredentialAccessBoundary = {
accessBoundary: {
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('DownscopedClient', () => {
assert.doesNotThrow(() => {
const instance = new DownscopedClient(
client,
cabWithOneAccessBoundaryRule,
cabWithOneAccessBoundaryRule
);
instance.quotaProjectId = quotaProjectId;
return instance;
Expand All @@ -313,10 +313,12 @@ describe('DownscopedClient', () => {
};
const downscopedClient = new DownscopedClient(
client,
cabWithOneAccessBoundaryRules,
cabWithOneAccessBoundaryRules
);
downscopedClient.eagerRefreshThresholdMillis = refreshOptions.eagerRefreshThresholdMillis;
downscopedClient.forceRefreshOnFailure = refreshOptions.forceRefreshOnFailure;
downscopedClient.eagerRefreshThresholdMillis =
refreshOptions.eagerRefreshThresholdMillis;
downscopedClient.forceRefreshOnFailure =
refreshOptions.forceRefreshOnFailure;
assert.strictEqual(
downscopedClient.forceRefreshOnFailure,
refreshOptions.forceRefreshOnFailure
Expand All @@ -335,7 +337,7 @@ describe('DownscopedClient', () => {
};
const expectedError = new Error(
'The access token expiry_date field is missing in the provided ' +
'credentials.'
'credentials.'
);
const downscopedClient = new DownscopedClient(
client,
Expand Down Expand Up @@ -756,10 +758,7 @@ describe('DownscopedClient', () => {
},
]);

const cabClient = new DownscopedClient(
client,
testClientAccessBoundary,
);
const cabClient = new DownscopedClient(client, testClientAccessBoundary);
cabClient.quotaProjectId = quotaProjectId;
const actualHeaders = await cabClient.getRequestHeaders();

Expand Down Expand Up @@ -839,10 +838,7 @@ describe('DownscopedClient', () => {
.reply(200, Object.assign({}, exampleResponse)),
];

const cabClient = new DownscopedClient(
client,
testClientAccessBoundary,
);
const cabClient = new DownscopedClient(client, testClientAccessBoundary);
cabClient.quotaProjectId = quotaProjectId;
const actualResponse = await cabClient.request<SampleResponse>({
url: 'https://example.com/api',
Expand Down Expand Up @@ -893,10 +889,7 @@ describe('DownscopedClient', () => {
.reply(200, Object.assign({}, exampleResponse)),
];

const cabClient = new DownscopedClient(
client,
testClientAccessBoundary,
);
const cabClient = new DownscopedClient(client, testClientAccessBoundary);
cabClient.quotaProjectId = quotaProjectId;
// Send request with no headers.
const actualResponse = await cabClient.request<SampleResponse>({
Expand Down
Loading

0 comments on commit e7c6ef4

Please sign in to comment.