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

refactor!: remove DEFAULT_UNIVERSE from BaseExternalClient #1690

Merged
merged 4 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 0 additions & 5 deletions src/auth/baseexternalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 11 additions & 12 deletions test/test.baseexternalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();

Expand Down Expand Up @@ -192,7 +191,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 @@ -1847,7 +1846,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 @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
26 changes: 13 additions & 13 deletions test/test.externalaccountauthorizeduserclient.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, 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();

Expand All @@ -52,15 +52,15 @@ 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;
}

function mockStsTokenRefresh(
url: string,
path: string,
nockParams: NockMockRefreshResponse[],
additionalHeaders?: {[key: string]: string}
additionalHeaders?: { [key: string]: string }
): nock.Scope {
const headers = Object.assign(
{
Expand Down Expand Up @@ -239,7 +239,7 @@ describe('ExternalAccountAuthorizedUserClient', () => {
},
})
.post(REFRESH_PATH, expectedRequest.toString())
.replyWithError({code: 'ETIMEDOUT'});
.replyWithError({ code: 'ETIMEDOUT' });

const client = new ExternalAccountAuthorizedUserClient(
externalAccountAuthorizedUserCredentialOptions
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -377,7 +377,7 @@ describe('ExternalAccountAuthorizedUserClient', () => {
]);

const optionsWithQuotaProjectId = Object.assign(
{quota_project_id: 'quotaProjectId'},
{ quota_project_id: 'quotaProjectId' },
externalAccountAuthorizedUserCredentialOptions
);
const client = new ExternalAccountAuthorizedUserClient(
Expand Down Expand Up @@ -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 = {
Expand Down