From 0b8f57bee04fcc95de8b6355d891095eb7e31926 Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Tue, 7 Nov 2023 21:45:47 +0530 Subject: [PATCH 1/3] chore: remove DEFAULT_UNIVERSE from BaseExternalClient --- src/auth/baseexternalclient.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/auth/baseexternalclient.ts b/src/auth/baseexternalclient.ts index 6496b143..b74eae2e 100644 --- a/src/auth/baseexternalclient.ts +++ b/src/auth/baseexternalclient.ts @@ -63,11 +63,6 @@ const WORKFORCE_AUDIENCE_PATTERN = // eslint-disable-next-line @typescript-eslint/no-var-requires const pkg = require('../../../package.json'); -/** - * For backwards compatibility. - */ -export {DEFAULT_UNIVERSE} from './authclient'; - export interface SharedExternalAccountClientOptions extends AuthClientOptions { audience: string; token_url: string; From 486a31772c79419bdfabb571e141301429c9f52c Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Tue, 7 Nov 2023 21:46:03 +0530 Subject: [PATCH 2/3] chore: update unit tests --- test/test.baseexternalclient.ts | 23 ++++++++-------- ...est.externalaccountauthorizeduserclient.ts | 26 +++++++++---------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/test/test.baseexternalclient.ts b/test/test.baseexternalclient.ts index 96ea57ce..358d0fce 100644 --- a/test/test.baseexternalclient.ts +++ b/test/test.baseexternalclient.ts @@ -13,23 +13,22 @@ // 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, BaseExternalAccountClientOptions, - DEFAULT_UNIVERSE, } from '../src/auth/baseexternalclient'; import { OAuthErrorResponse, getErrorFromOAuthErrorResponse, } from '../src/auth/oauth2common'; -import {GaxiosError} from 'gaxios'; +import { GaxiosError } from 'gaxios'; import { assertGaxiosResponsePresent, getAudience, @@ -40,7 +39,7 @@ import { mockStsTokenExchange, getExpectedExternalAccountMetricsHeaderValue, } from './externalclienthelper'; -import {AuthClientOptions} from '../src/auth/authclient'; +import { AuthClientOptions, DEFAULT_UNIVERSE } from '../src/auth/authclient'; nock.disableNetConnect(); @@ -192,7 +191,7 @@ describe('BaseExternalAccountClient', () => { ); const expectedWorkforcePoolUserProjectError = new Error( 'workforcePoolUserProject should not be set for non-workforce pool ' + - 'credentials.' + 'credentials.' ); invalidWorkforceAudiences.forEach(invalidWorkforceAudience => { @@ -1847,7 +1846,7 @@ describe('BaseExternalAccountClient', () => { ]); const optionsWithQuotaProjectId = Object.assign( - {quota_project_id: quotaProjectId}, + { quota_project_id: quotaProjectId }, externalAccountOptions ); const client = new TestExternalAccountClient(optionsWithQuotaProjectId); @@ -1896,7 +1895,7 @@ describe('BaseExternalAccountClient', () => { 'x-goog-user-project': quotaProjectId, }; const optionsWithQuotaProjectId = Object.assign( - {quota_project_id: quotaProjectId}, + { quota_project_id: quotaProjectId }, externalAccountOptions ); const exampleRequest = { @@ -1959,7 +1958,7 @@ describe('BaseExternalAccountClient', () => { 'x-goog-user-project': quotaProjectId, }; const optionsWithQuotaProjectId = Object.assign( - {quota_project_id: quotaProjectId}, + { quota_project_id: quotaProjectId }, externalAccountOptionsWithSA ); const exampleRequest = { @@ -2023,7 +2022,7 @@ describe('BaseExternalAccountClient', () => { 'x-goog-user-project': quotaProjectId, }; const optionsWithQuotaProjectId = Object.assign( - {quota_project_id: quotaProjectId}, + { quota_project_id: quotaProjectId }, externalAccountOptions ); const exampleRequest = { diff --git a/test/test.externalaccountauthorizeduserclient.ts b/test/test.externalaccountauthorizeduserclient.ts index c97e4b03..c8e3c371 100644 --- a/test/test.externalaccountauthorizeduserclient.ts +++ b/test/test.externalaccountauthorizeduserclient.ts @@ -13,25 +13,25 @@ // limitations under the License. import * as assert from 'assert'; -import {describe, it, afterEach, beforeEach} from 'mocha'; +import { describe, it, afterEach, beforeEach } from 'mocha'; import * as nock from 'nock'; import * as sinon from 'sinon'; import * as qs from 'querystring'; -import {assertGaxiosResponsePresent, getAudience} from './externalclienthelper'; +import { assertGaxiosResponsePresent, getAudience } from './externalclienthelper'; import { EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE, ExternalAccountAuthorizedUserClient, ExternalAccountAuthorizedUserClientOptions, } from '../src/auth/externalAccountAuthorizedUserClient'; import { - DEFAULT_UNIVERSE, EXPIRATION_TIME_OFFSET, } from '../src/auth/baseexternalclient'; -import {GaxiosError, GaxiosResponse} from 'gaxios'; +import { GaxiosError, GaxiosResponse } from 'gaxios'; import { getErrorFromOAuthErrorResponse, OAuthErrorResponse, } from '../src/auth/oauth2common'; +import { DEFAULT_UNIVERSE } from '../src/auth/authclient'; nock.disableNetConnect(); @@ -52,7 +52,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { statusCode: number; response: TokenRefreshResponse | OAuthErrorResponse; // eslint-disable-next-line @typescript-eslint/no-explicit-any - request: {[key: string]: any}; + request: { [key: string]: any }; times?: number; } @@ -60,7 +60,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { url: string, path: string, nockParams: NockMockRefreshResponse[], - additionalHeaders?: {[key: string]: string} + additionalHeaders?: { [key: string]: string } ): nock.Scope { const headers = Object.assign( { @@ -239,7 +239,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { }, }) .post(REFRESH_PATH, expectedRequest.toString()) - .replyWithError({code: 'ETIMEDOUT'}); + .replyWithError({ code: 'ETIMEDOUT' }); const client = new ExternalAccountAuthorizedUserClient( externalAccountAuthorizedUserCredentialOptions @@ -309,8 +309,8 @@ describe('ExternalAccountAuthorizedUserClient', () => { // Advance clock to force new refresh. clock.tick( successfulRefreshResponseNoRefreshToken.expires_in * 1000 - - client.eagerRefreshThresholdMillis - - 1 + client.eagerRefreshThresholdMillis - + 1 ); // Refresh access token with new access token. const actualResponse = await client.getAccessToken(); @@ -344,8 +344,8 @@ describe('ExternalAccountAuthorizedUserClient', () => { // Advance clock to force new refresh. clock.tick( successfulRefreshResponseNoRefreshToken.expires_in * 1000 - - client.eagerRefreshThresholdMillis + - 1 + client.eagerRefreshThresholdMillis + + 1 ); // Refresh access token with new access token. const actualResponse = await client.getAccessToken(); @@ -377,7 +377,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { ]); const optionsWithQuotaProjectId = Object.assign( - {quota_project_id: 'quotaProjectId'}, + { quota_project_id: 'quotaProjectId' }, externalAccountAuthorizedUserCredentialOptions ); const client = new ExternalAccountAuthorizedUserClient( @@ -425,7 +425,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { 'x-goog-user-project': quotaProjectId, }; const optionsWithQuotaProjectId = Object.assign( - {quota_project_id: quotaProjectId}, + { quota_project_id: quotaProjectId }, externalAccountAuthorizedUserCredentialOptions ); const exampleRequest = { From 9548cd6f79f1d2128c0444e87b38cc1315f7b385 Mon Sep 17 00:00:00 2001 From: Dhoni77 Date: Thu, 9 Nov 2023 15:55:04 +0530 Subject: [PATCH 3/3] chore: fix formatting --- test/test.baseexternalclient.ts | 22 +++++++------- ...est.externalaccountauthorizeduserclient.ts | 30 +++++++++---------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/test/test.baseexternalclient.ts b/test/test.baseexternalclient.ts index 358d0fce..26990bd6 100644 --- a/test/test.baseexternalclient.ts +++ b/test/test.baseexternalclient.ts @@ -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, @@ -28,7 +28,7 @@ import { OAuthErrorResponse, getErrorFromOAuthErrorResponse, } from '../src/auth/oauth2common'; -import { GaxiosError } from 'gaxios'; +import {GaxiosError} from 'gaxios'; import { assertGaxiosResponsePresent, getAudience, @@ -39,7 +39,7 @@ import { mockStsTokenExchange, getExpectedExternalAccountMetricsHeaderValue, } from './externalclienthelper'; -import { AuthClientOptions, DEFAULT_UNIVERSE } from '../src/auth/authclient'; +import {AuthClientOptions, DEFAULT_UNIVERSE} from '../src/auth/authclient'; nock.disableNetConnect(); @@ -191,7 +191,7 @@ describe('BaseExternalAccountClient', () => { ); const expectedWorkforcePoolUserProjectError = new Error( 'workforcePoolUserProject should not be set for non-workforce pool ' + - 'credentials.' + 'credentials.' ); invalidWorkforceAudiences.forEach(invalidWorkforceAudience => { @@ -1846,7 +1846,7 @@ describe('BaseExternalAccountClient', () => { ]); const optionsWithQuotaProjectId = Object.assign( - { quota_project_id: quotaProjectId }, + {quota_project_id: quotaProjectId}, externalAccountOptions ); const client = new TestExternalAccountClient(optionsWithQuotaProjectId); @@ -1895,7 +1895,7 @@ describe('BaseExternalAccountClient', () => { 'x-goog-user-project': quotaProjectId, }; const optionsWithQuotaProjectId = Object.assign( - { quota_project_id: quotaProjectId }, + {quota_project_id: quotaProjectId}, externalAccountOptions ); const exampleRequest = { @@ -1958,7 +1958,7 @@ describe('BaseExternalAccountClient', () => { 'x-goog-user-project': quotaProjectId, }; const optionsWithQuotaProjectId = Object.assign( - { quota_project_id: quotaProjectId }, + {quota_project_id: quotaProjectId}, externalAccountOptionsWithSA ); const exampleRequest = { @@ -2022,7 +2022,7 @@ describe('BaseExternalAccountClient', () => { 'x-goog-user-project': quotaProjectId, }; const optionsWithQuotaProjectId = Object.assign( - { quota_project_id: quotaProjectId }, + {quota_project_id: quotaProjectId}, externalAccountOptions ); const exampleRequest = { diff --git a/test/test.externalaccountauthorizeduserclient.ts b/test/test.externalaccountauthorizeduserclient.ts index c8e3c371..584463dd 100644 --- a/test/test.externalaccountauthorizeduserclient.ts +++ b/test/test.externalaccountauthorizeduserclient.ts @@ -13,25 +13,23 @@ // limitations under the License. import * as assert from 'assert'; -import { describe, it, afterEach, beforeEach } from 'mocha'; +import {describe, it, afterEach, beforeEach} from 'mocha'; import * as nock from 'nock'; import * as sinon from 'sinon'; import * as qs from 'querystring'; -import { assertGaxiosResponsePresent, getAudience } from './externalclienthelper'; +import {assertGaxiosResponsePresent, getAudience} from './externalclienthelper'; import { EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE, ExternalAccountAuthorizedUserClient, ExternalAccountAuthorizedUserClientOptions, } from '../src/auth/externalAccountAuthorizedUserClient'; -import { - EXPIRATION_TIME_OFFSET, -} from '../src/auth/baseexternalclient'; -import { GaxiosError, GaxiosResponse } from 'gaxios'; +import {EXPIRATION_TIME_OFFSET} from '../src/auth/baseexternalclient'; +import {GaxiosError, GaxiosResponse} from 'gaxios'; import { getErrorFromOAuthErrorResponse, OAuthErrorResponse, } from '../src/auth/oauth2common'; -import { DEFAULT_UNIVERSE } from '../src/auth/authclient'; +import {DEFAULT_UNIVERSE} from '../src/auth/authclient'; nock.disableNetConnect(); @@ -52,7 +50,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { statusCode: number; response: TokenRefreshResponse | OAuthErrorResponse; // eslint-disable-next-line @typescript-eslint/no-explicit-any - request: { [key: string]: any }; + request: {[key: string]: any}; times?: number; } @@ -60,7 +58,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { url: string, path: string, nockParams: NockMockRefreshResponse[], - additionalHeaders?: { [key: string]: string } + additionalHeaders?: {[key: string]: string} ): nock.Scope { const headers = Object.assign( { @@ -239,7 +237,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { }, }) .post(REFRESH_PATH, expectedRequest.toString()) - .replyWithError({ code: 'ETIMEDOUT' }); + .replyWithError({code: 'ETIMEDOUT'}); const client = new ExternalAccountAuthorizedUserClient( externalAccountAuthorizedUserCredentialOptions @@ -309,8 +307,8 @@ describe('ExternalAccountAuthorizedUserClient', () => { // Advance clock to force new refresh. clock.tick( successfulRefreshResponseNoRefreshToken.expires_in * 1000 - - client.eagerRefreshThresholdMillis - - 1 + client.eagerRefreshThresholdMillis - + 1 ); // Refresh access token with new access token. const actualResponse = await client.getAccessToken(); @@ -344,8 +342,8 @@ describe('ExternalAccountAuthorizedUserClient', () => { // Advance clock to force new refresh. clock.tick( successfulRefreshResponseNoRefreshToken.expires_in * 1000 - - client.eagerRefreshThresholdMillis + - 1 + client.eagerRefreshThresholdMillis + + 1 ); // Refresh access token with new access token. const actualResponse = await client.getAccessToken(); @@ -377,7 +375,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { ]); const optionsWithQuotaProjectId = Object.assign( - { quota_project_id: 'quotaProjectId' }, + {quota_project_id: 'quotaProjectId'}, externalAccountAuthorizedUserCredentialOptions ); const client = new ExternalAccountAuthorizedUserClient( @@ -425,7 +423,7 @@ describe('ExternalAccountAuthorizedUserClient', () => { 'x-goog-user-project': quotaProjectId, }; const optionsWithQuotaProjectId = Object.assign( - { quota_project_id: quotaProjectId }, + {quota_project_id: quotaProjectId}, externalAccountAuthorizedUserCredentialOptions ); const exampleRequest = {