From e543087b421689a15f33cd8e41e6574b932b356e Mon Sep 17 00:00:00 2001 From: mansisampat Date: Fri, 2 May 2025 17:05:48 +0530 Subject: [PATCH 1/6] Throw not supported exception in _performApiRequest --- common/api-review/auth.api.md | 1 + packages/auth/src/api/index.ts | 23 +++++++++++++++++-- packages/auth/src/core/auth/auth_impl.ts | 8 +++++-- packages/auth/src/core/auth/emulator.ts | 8 +++---- packages/auth/src/core/auth/register.ts | 3 ++- .../src/core/strategies/email_and_password.ts | 3 ++- packages/auth/src/core/util/assert.ts | 8 +++++++ packages/auth/src/model/auth.ts | 2 ++ packages/auth/src/model/public_types.ts | 6 +++++ 9 files changed, 52 insertions(+), 10 deletions(-) diff --git a/common/api-review/auth.api.md b/common/api-review/auth.api.md index aed0fb619da..27203e95f3a 100644 --- a/common/api-review/auth.api.md +++ b/common/api-review/auth.api.md @@ -95,6 +95,7 @@ export interface Auth { setPersistence(persistence: Persistence): Promise; readonly settings: AuthSettings; signOut(): Promise; + readonly tenantConfig?: TenantConfig; tenantId: string | null; updateCurrentUser(user: User | null): Promise; useDeviceLanguage(): void; diff --git a/packages/auth/src/api/index.ts b/packages/auth/src/api/index.ts index af9b3c63bf1..bf969ed82bc 100644 --- a/packages/auth/src/api/index.ts +++ b/packages/auth/src/api/index.ts @@ -38,6 +38,7 @@ import { IdTokenMfaResponse } from './authentication/mfa'; import { SERVER_ERROR_MAP, ServerError, ServerErrorMap } from './errors'; import { PersistenceType } from '../core/persistence'; import { CookiePersistence } from '../platform_browser/persistence/cookie_storage'; +import {_operationNotSupportedForInitializedAuthInstance} from '../core/util/assert'; export const enum HttpMethod { POST = 'POST', @@ -53,7 +54,7 @@ export const enum HttpHeader { X_FIREBASE_APP_CHECK = 'X-Firebase-AppCheck' } -export const enum Endpoint { +export enum Endpoint { CREATE_AUTH_URI = '/v1/accounts:createAuthUri', DELETE_ACCOUNT = '/v1/accounts:delete', RESET_PASSWORD = '/v1/accounts:resetPassword', @@ -80,6 +81,10 @@ export const enum Endpoint { REVOKE_TOKEN = '/v2/accounts:revokeToken' } +export enum Regional_Endpoint { + EXCHANGE_TOKEN = 'v2/${body.parent}:exchangeOidcToken' +} + const CookieAuthProxiedEndpoints: string[] = [ Endpoint.SIGN_IN_WITH_CUSTOM_TOKEN, Endpoint.SIGN_IN_WITH_EMAIL_LINK, @@ -139,10 +144,11 @@ export function _addTidIfNecessary( export async function _performApiRequest( auth: Auth, method: HttpMethod, - path: Endpoint, + path: Endpoint | Regional_Endpoint, request?: T, customErrorMap: Partial> = {} ): Promise { + _assertValidEndpointForAuth(auth, path); return _performFetchWithErrorHandling(auth, customErrorMap, async () => { let body = {}; let params = {}; @@ -322,6 +328,19 @@ export function _parseEnforcementState( } } +function _assertValidEndpointForAuth( + auth: Auth, + path: Endpoint | Regional_Endpoint +): void { + if (!auth.tenantConfig && Object.values(Regional_Endpoint).includes(path as Regional_Endpoint)) { + throw _operationNotSupportedForInitializedAuthInstance(auth); + } + + if (auth.tenantConfig && Object.values(Endpoint).includes(path as Endpoint)) { + throw _operationNotSupportedForInitializedAuthInstance(auth); + } +} + class NetworkTimeout { // Node timers and browser timers are fundamentally incompatible, but we // don't care about the value here diff --git a/packages/auth/src/core/auth/auth_impl.ts b/packages/auth/src/core/auth/auth_impl.ts index 14c23ae28f3..42727f73d4f 100644 --- a/packages/auth/src/core/auth/auth_impl.ts +++ b/packages/auth/src/core/auth/auth_impl.ts @@ -36,7 +36,8 @@ import { ErrorFn, NextFn, Unsubscribe, - PasswordValidationStatus + PasswordValidationStatus, + TenantConfig, } from '../../model/public_types'; import { createSubscribe, @@ -126,6 +127,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService { | undefined = undefined; _persistenceManagerAvailable: Promise; readonly name: string; + readonly tenantConfig?: TenantConfig; // Tracks the last notified UID for state change listeners to prevent // repeated calls to the callbacks. Undefined means it's never been @@ -140,7 +142,8 @@ export class AuthImpl implements AuthInternal, _FirebaseService { public readonly app: FirebaseApp, private readonly heartbeatServiceProvider: Provider<'heartbeat'>, private readonly appCheckServiceProvider: Provider, - public readonly config: ConfigInternal + public readonly config: ConfigInternal, + tenantConfig?: TenantConfig ) { this.name = app.name; this.clientVersion = config.sdkClientVersion; @@ -149,6 +152,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService { this._persistenceManagerAvailable = new Promise( resolve => (this._resolvePersistenceManagerAvailable = resolve) ); + this.tenantConfig = tenantConfig; } _initializeWithPersistence( diff --git a/packages/auth/src/core/auth/emulator.ts b/packages/auth/src/core/auth/emulator.ts index 05f2e5e4bd5..e5a705e3400 100644 --- a/packages/auth/src/core/auth/emulator.ts +++ b/packages/auth/src/core/auth/emulator.ts @@ -18,7 +18,7 @@ import { Auth } from '../../model/public_types'; import { AuthErrorCode } from '../errors'; import { _assert } from '../util/assert'; import { _castAuth } from './auth_impl'; -import { deepEqual, isCloudWorkstation, pingServer } from '@firebase/util'; +import { deepEqual, pingServer } from '@firebase/util'; /** * Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production @@ -102,9 +102,9 @@ export function connectAuthEmulator( } // Workaround to get cookies in Firebase Studio - if (isCloudWorkstation(host)) { - void pingServer(`${protocol}//${host}:${port}`); - } + // if (isCloudWorkstation(host)) { + // void pingServer(`${protocol}//${host}:${port}`); + // } } function extractProtocol(url: string): string { diff --git a/packages/auth/src/core/auth/register.ts b/packages/auth/src/core/auth/register.ts index 52493945abc..efe1d63ab16 100644 --- a/packages/auth/src/core/auth/register.ts +++ b/packages/auth/src/core/auth/register.ts @@ -92,7 +92,8 @@ export function registerAuth(clientPlatform: ClientPlatform): void { app, heartbeatServiceProvider, appCheckServiceProvider, - config + config, + tenantConfig ); _initializeAuthInstance(authInstance, deps); diff --git a/packages/auth/src/core/strategies/email_and_password.ts b/packages/auth/src/core/strategies/email_and_password.ts index fbfa871bc7c..577eefc23b3 100644 --- a/packages/auth/src/core/strategies/email_and_password.ts +++ b/packages/auth/src/core/strategies/email_and_password.ts @@ -35,7 +35,7 @@ import { } from '../util/assert'; import { _setActionCodeSettingsOnRequest } from './action_code_settings'; import { signInWithCredential } from './credential'; -import { _castAuth } from '../auth/auth_impl'; +import { _castAuth, AuthImpl } from '../auth/auth_impl'; import { AuthErrorCode } from '../errors'; import { getModularInstance } from '@firebase/util'; import { OperationType } from '../../model/enums'; @@ -47,6 +47,7 @@ import { RecaptchaAuthProvider } from '../../api'; import { _isFirebaseServerApp } from '@firebase/app'; +import {_isFirebaseRegionalAuthInitialized} from '../util/validate_origin' /** * Updates the password policy cached in the {@link Auth} instance if a policy is already diff --git a/packages/auth/src/core/util/assert.ts b/packages/auth/src/core/util/assert.ts index 51dff0793e2..9062f44d1ad 100644 --- a/packages/auth/src/core/util/assert.ts +++ b/packages/auth/src/core/util/assert.ts @@ -112,6 +112,14 @@ export function _serverAppCurrentUserOperationNotSupportedError( ); } +export function _operationNotSupportedForInitializedAuthInstance(auth: Auth) : FirebaseError { + return _errorWithCustomMessage( + auth, + AuthErrorCode.OPERATION_NOT_ALLOWED, + 'Operations not allowed for the auth object initialized.' + ); +} + export function _assertInstanceOf( auth: Auth, object: object, diff --git a/packages/auth/src/model/auth.ts b/packages/auth/src/model/auth.ts index a88430fd5df..60faedef4e6 100644 --- a/packages/auth/src/model/auth.ts +++ b/packages/auth/src/model/auth.ts @@ -23,6 +23,7 @@ import { PasswordPolicy, PasswordValidationStatus, PopupRedirectResolver, + TenantConfig, User } from './public_types'; import { ErrorFactory } from '@firebase/util'; @@ -100,6 +101,7 @@ export interface AuthInternal extends Auth { readonly name: AppName; readonly config: ConfigInternal; + readonly tenantConfig?: TenantConfig; languageCode: string | null; tenantId: string | null; readonly settings: AuthSettings; diff --git a/packages/auth/src/model/public_types.ts b/packages/auth/src/model/public_types.ts index ea997c7855f..bbb64fb0af8 100644 --- a/packages/auth/src/model/public_types.ts +++ b/packages/auth/src/model/public_types.ts @@ -183,6 +183,12 @@ export interface Auth { readonly name: string; /** The {@link Config} used to initialize this instance. */ readonly config: Config; + /** + * The {@link TenantConfig} used to initialize a Regional Auth. This is only present + * if regional auth is initialized and {@link DefaultConfig.REGIONAL_API_HOST} + * backend endpoint is used. + */ + readonly tenantConfig?: TenantConfig; /** * Changes the type of persistence on the `Auth` instance. * From 5afd1ce68fc4c615f5f168b73457edcfd17ea7d5 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Mon, 12 May 2025 16:08:34 +0530 Subject: [PATCH 2/6] yarn run format --- packages/auth/src/api/index.ts | 7 +++++-- packages/auth/src/core/auth/auth_impl.ts | 2 +- packages/auth/src/core/auth/emulator.ts | 8 ++++---- packages/auth/src/core/strategies/email_and_password.ts | 3 +-- packages/auth/src/core/util/assert.ts | 4 +++- packages/auth/src/model/public_types.ts | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/auth/src/api/index.ts b/packages/auth/src/api/index.ts index bf969ed82bc..960c2791e38 100644 --- a/packages/auth/src/api/index.ts +++ b/packages/auth/src/api/index.ts @@ -38,7 +38,7 @@ import { IdTokenMfaResponse } from './authentication/mfa'; import { SERVER_ERROR_MAP, ServerError, ServerErrorMap } from './errors'; import { PersistenceType } from '../core/persistence'; import { CookiePersistence } from '../platform_browser/persistence/cookie_storage'; -import {_operationNotSupportedForInitializedAuthInstance} from '../core/util/assert'; +import { _operationNotSupportedForInitializedAuthInstance } from '../core/util/assert'; export const enum HttpMethod { POST = 'POST', @@ -332,7 +332,10 @@ function _assertValidEndpointForAuth( auth: Auth, path: Endpoint | Regional_Endpoint ): void { - if (!auth.tenantConfig && Object.values(Regional_Endpoint).includes(path as Regional_Endpoint)) { + if ( + !auth.tenantConfig && + Object.values(Regional_Endpoint).includes(path as Regional_Endpoint) + ) { throw _operationNotSupportedForInitializedAuthInstance(auth); } diff --git a/packages/auth/src/core/auth/auth_impl.ts b/packages/auth/src/core/auth/auth_impl.ts index 42727f73d4f..d21cfdd0214 100644 --- a/packages/auth/src/core/auth/auth_impl.ts +++ b/packages/auth/src/core/auth/auth_impl.ts @@ -37,7 +37,7 @@ import { NextFn, Unsubscribe, PasswordValidationStatus, - TenantConfig, + TenantConfig } from '../../model/public_types'; import { createSubscribe, diff --git a/packages/auth/src/core/auth/emulator.ts b/packages/auth/src/core/auth/emulator.ts index e5a705e3400..05f2e5e4bd5 100644 --- a/packages/auth/src/core/auth/emulator.ts +++ b/packages/auth/src/core/auth/emulator.ts @@ -18,7 +18,7 @@ import { Auth } from '../../model/public_types'; import { AuthErrorCode } from '../errors'; import { _assert } from '../util/assert'; import { _castAuth } from './auth_impl'; -import { deepEqual, pingServer } from '@firebase/util'; +import { deepEqual, isCloudWorkstation, pingServer } from '@firebase/util'; /** * Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production @@ -102,9 +102,9 @@ export function connectAuthEmulator( } // Workaround to get cookies in Firebase Studio - // if (isCloudWorkstation(host)) { - // void pingServer(`${protocol}//${host}:${port}`); - // } + if (isCloudWorkstation(host)) { + void pingServer(`${protocol}//${host}:${port}`); + } } function extractProtocol(url: string): string { diff --git a/packages/auth/src/core/strategies/email_and_password.ts b/packages/auth/src/core/strategies/email_and_password.ts index 577eefc23b3..fbfa871bc7c 100644 --- a/packages/auth/src/core/strategies/email_and_password.ts +++ b/packages/auth/src/core/strategies/email_and_password.ts @@ -35,7 +35,7 @@ import { } from '../util/assert'; import { _setActionCodeSettingsOnRequest } from './action_code_settings'; import { signInWithCredential } from './credential'; -import { _castAuth, AuthImpl } from '../auth/auth_impl'; +import { _castAuth } from '../auth/auth_impl'; import { AuthErrorCode } from '../errors'; import { getModularInstance } from '@firebase/util'; import { OperationType } from '../../model/enums'; @@ -47,7 +47,6 @@ import { RecaptchaAuthProvider } from '../../api'; import { _isFirebaseServerApp } from '@firebase/app'; -import {_isFirebaseRegionalAuthInitialized} from '../util/validate_origin' /** * Updates the password policy cached in the {@link Auth} instance if a policy is already diff --git a/packages/auth/src/core/util/assert.ts b/packages/auth/src/core/util/assert.ts index 9062f44d1ad..eb497fba8aa 100644 --- a/packages/auth/src/core/util/assert.ts +++ b/packages/auth/src/core/util/assert.ts @@ -112,7 +112,9 @@ export function _serverAppCurrentUserOperationNotSupportedError( ); } -export function _operationNotSupportedForInitializedAuthInstance(auth: Auth) : FirebaseError { +export function _operationNotSupportedForInitializedAuthInstance( + auth: Auth +): FirebaseError { return _errorWithCustomMessage( auth, AuthErrorCode.OPERATION_NOT_ALLOWED, diff --git a/packages/auth/src/model/public_types.ts b/packages/auth/src/model/public_types.ts index bbb64fb0af8..bd6c9cc2b8c 100644 --- a/packages/auth/src/model/public_types.ts +++ b/packages/auth/src/model/public_types.ts @@ -186,7 +186,7 @@ export interface Auth { /** * The {@link TenantConfig} used to initialize a Regional Auth. This is only present * if regional auth is initialized and {@link DefaultConfig.REGIONAL_API_HOST} - * backend endpoint is used. + * backend endpoint is used. */ readonly tenantConfig?: TenantConfig; /** From 85db509bcab5de8a139e9d8d5ef33a3c74d7a0c7 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Tue, 13 May 2025 10:36:07 +0530 Subject: [PATCH 3/6] Adding unit test --- packages/auth/src/api/index.test.ts | 28 ++++++++++++++++++++++++- packages/auth/src/api/index.ts | 10 ++++----- packages/auth/test/helpers/mock_auth.ts | 20 ++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/packages/auth/src/api/index.test.ts b/packages/auth/src/api/index.test.ts index 02042fce429..769d508bb18 100644 --- a/packages/auth/src/api/index.test.ts +++ b/packages/auth/src/api/index.test.ts @@ -25,7 +25,7 @@ import { FirebaseError, getUA } from '@firebase/util'; import * as utils from '@firebase/util'; import { mockEndpoint } from '../../test/helpers/api/helper'; -import { testAuth, TestAuth } from '../../test/helpers/mock_auth'; +import { regionalTestAuth, testAuth, TestAuth } from '../../test/helpers/mock_auth'; import * as mockFetch from '../../test/helpers/mock_fetch'; import { AuthErrorCode } from '../core/errors'; import { ConfigInternal } from '../model/auth'; @@ -34,6 +34,7 @@ import { _performApiRequest, DEFAULT_API_TIMEOUT_MS, Endpoint, + RegionalEndpoint, HttpHeader, HttpMethod, _addTidIfNecessary @@ -55,9 +56,11 @@ describe('api/_performApiRequest', () => { }; let auth: TestAuth; + let regionalAuth: TestAuth; beforeEach(async () => { auth = await testAuth(); + regionalAuth = await regionalTestAuth(); }); afterEach(() => { @@ -595,4 +598,27 @@ describe('api/_performApiRequest', () => { .and.not.have.property('tenantId'); }); }); + + + it('should throw exception when tenantConfig is not initialized and Regional Endpoint is used', async () => { + await expect( + _performApiRequest< + typeof request, + typeof serverResponse + >(auth, HttpMethod.POST, RegionalEndpoint.EXCHANGE_TOKEN, request)).to.be.rejectedWith( + FirebaseError, + 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' + ); + }); + + it('should throw exception when tenantConfig is initialized and default Endpoint is used', async () => { + await expect( + _performApiRequest< + typeof request, + typeof serverResponse + >(regionalAuth, HttpMethod.POST, Endpoint.SIGN_UP, request)).to.be.rejectedWith( + FirebaseError, + 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' + ); + }); }); diff --git a/packages/auth/src/api/index.ts b/packages/auth/src/api/index.ts index 960c2791e38..a1480803449 100644 --- a/packages/auth/src/api/index.ts +++ b/packages/auth/src/api/index.ts @@ -26,6 +26,7 @@ import { AuthErrorCode, NamedErrorParams } from '../core/errors'; import { _createError, _errorWithCustomMessage, + _operationNotSupportedForInitializedAuthInstance, _fail } from '../core/util/assert'; import { Delay } from '../core/util/delay'; @@ -38,7 +39,6 @@ import { IdTokenMfaResponse } from './authentication/mfa'; import { SERVER_ERROR_MAP, ServerError, ServerErrorMap } from './errors'; import { PersistenceType } from '../core/persistence'; import { CookiePersistence } from '../platform_browser/persistence/cookie_storage'; -import { _operationNotSupportedForInitializedAuthInstance } from '../core/util/assert'; export const enum HttpMethod { POST = 'POST', @@ -81,7 +81,7 @@ export enum Endpoint { REVOKE_TOKEN = '/v2/accounts:revokeToken' } -export enum Regional_Endpoint { +export enum RegionalEndpoint { EXCHANGE_TOKEN = 'v2/${body.parent}:exchangeOidcToken' } @@ -144,7 +144,7 @@ export function _addTidIfNecessary( export async function _performApiRequest( auth: Auth, method: HttpMethod, - path: Endpoint | Regional_Endpoint, + path: Endpoint | RegionalEndpoint, request?: T, customErrorMap: Partial> = {} ): Promise { @@ -330,11 +330,11 @@ export function _parseEnforcementState( function _assertValidEndpointForAuth( auth: Auth, - path: Endpoint | Regional_Endpoint + path: Endpoint | RegionalEndpoint ): void { if ( !auth.tenantConfig && - Object.values(Regional_Endpoint).includes(path as Regional_Endpoint) + Object.values(RegionalEndpoint).includes(path as RegionalEndpoint) ) { throw _operationNotSupportedForInitializedAuthInstance(auth); } diff --git a/packages/auth/test/helpers/mock_auth.ts b/packages/auth/test/helpers/mock_auth.ts index e5e30fa1384..68ca48ca0c6 100644 --- a/packages/auth/test/helpers/mock_auth.ts +++ b/packages/auth/test/helpers/mock_auth.ts @@ -116,6 +116,26 @@ export async function testAuth( return auth; } +export async function regionalTestAuth(): Promise { + const tenantConfig = {'location': "us", 'tenantId': "tenant-1"}; + const auth: TestAuth = new AuthImpl( + FAKE_APP, + FAKE_HEARTBEAT_CONTROLLER_PROVIDER, + FAKE_APP_CHECK_CONTROLLER_PROVIDER, + { + apiKey: TEST_KEY, + authDomain: TEST_AUTH_DOMAIN, + apiHost: TEST_HOST, + apiScheme: TEST_SCHEME, + tokenApiHost: TEST_TOKEN_HOST, + clientPlatform: ClientPlatform.BROWSER, + sdkClientVersion: 'testSDK/0.0.0' + }, + tenantConfig + ) as TestAuth; + return auth; +} + export function testUser( auth: AuthInternal, uid: string, From 7bde67b45f9dc496a52957fe1196b224fe24de94 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Tue, 13 May 2025 11:40:23 +0530 Subject: [PATCH 4/6] Applying yarn run format --- docs-devsite/auth.auth.md | 11 +++++++ packages/auth/src/api/index.test.ts | 41 +++++++++++++++---------- packages/auth/test/helpers/mock_auth.ts | 2 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/docs-devsite/auth.auth.md b/docs-devsite/auth.auth.md index cbbc7a9ceb0..1f96bd23881 100644 --- a/docs-devsite/auth.auth.md +++ b/docs-devsite/auth.auth.md @@ -31,6 +31,7 @@ export interface Auth | [languageCode](./auth.auth.md#authlanguagecode) | string \| null | The [Auth](./auth.auth.md#auth_interface) instance's language code. | | [name](./auth.auth.md#authname) | string | The name of the app associated with the Auth service instance. | | [settings](./auth.auth.md#authsettings) | [AuthSettings](./auth.authsettings.md#authsettings_interface) | The [Auth](./auth.auth.md#auth_interface) instance's settings. | +| [tenantConfig](./auth.auth.md#authtenantconfig) | [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface) | The [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface) used to initialize a Regional Auth. This is only present if regional auth is initialized and backend endpoint is used. | | [tenantId](./auth.auth.md#authtenantid) | string \| null | The [Auth](./auth.auth.md#auth_interface) instance's tenant ID. | ## Methods @@ -120,6 +121,16 @@ This is used to edit/read configuration related options such as app verification readonly settings: AuthSettings; ``` +## Auth.tenantConfig + +The [TenantConfig](./auth.tenantconfig.md#tenantconfig_interface) used to initialize a Regional Auth. This is only present if regional auth is initialized and backend endpoint is used. + +Signature: + +```typescript +readonly tenantConfig?: TenantConfig; +``` + ## Auth.tenantId The [Auth](./auth.auth.md#auth_interface) instance's tenant ID. diff --git a/packages/auth/src/api/index.test.ts b/packages/auth/src/api/index.test.ts index 769d508bb18..10c823c6e3e 100644 --- a/packages/auth/src/api/index.test.ts +++ b/packages/auth/src/api/index.test.ts @@ -25,7 +25,11 @@ import { FirebaseError, getUA } from '@firebase/util'; import * as utils from '@firebase/util'; import { mockEndpoint } from '../../test/helpers/api/helper'; -import { regionalTestAuth, testAuth, TestAuth } from '../../test/helpers/mock_auth'; +import { + regionalTestAuth, + testAuth, + TestAuth +} from '../../test/helpers/mock_auth'; import * as mockFetch from '../../test/helpers/mock_fetch'; import { AuthErrorCode } from '../core/errors'; import { ConfigInternal } from '../model/auth'; @@ -599,26 +603,31 @@ describe('api/_performApiRequest', () => { }); }); - it('should throw exception when tenantConfig is not initialized and Regional Endpoint is used', async () => { await expect( - _performApiRequest< - typeof request, - typeof serverResponse - >(auth, HttpMethod.POST, RegionalEndpoint.EXCHANGE_TOKEN, request)).to.be.rejectedWith( - FirebaseError, - 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' - ); + _performApiRequest( + auth, + HttpMethod.POST, + RegionalEndpoint.EXCHANGE_TOKEN, + request + ) + ).to.be.rejectedWith( + FirebaseError, + 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' + ); }); it('should throw exception when tenantConfig is initialized and default Endpoint is used', async () => { await expect( - _performApiRequest< - typeof request, - typeof serverResponse - >(regionalAuth, HttpMethod.POST, Endpoint.SIGN_UP, request)).to.be.rejectedWith( - FirebaseError, - 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' - ); + _performApiRequest( + regionalAuth, + HttpMethod.POST, + Endpoint.SIGN_UP, + request + ) + ).to.be.rejectedWith( + FirebaseError, + 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' + ); }); }); diff --git a/packages/auth/test/helpers/mock_auth.ts b/packages/auth/test/helpers/mock_auth.ts index 68ca48ca0c6..15c03dc42c1 100644 --- a/packages/auth/test/helpers/mock_auth.ts +++ b/packages/auth/test/helpers/mock_auth.ts @@ -117,7 +117,7 @@ export async function testAuth( } export async function regionalTestAuth(): Promise { - const tenantConfig = {'location': "us", 'tenantId': "tenant-1"}; + const tenantConfig = { 'location': 'us', 'tenantId': 'tenant-1' }; const auth: TestAuth = new AuthImpl( FAKE_APP, FAKE_HEARTBEAT_CONTROLLER_PROVIDER, From 35a19d87a4b5a8c6cd9a5aae99fba092e9071976 Mon Sep 17 00:00:00 2001 From: mansisampat Date: Tue, 13 May 2025 11:49:59 +0530 Subject: [PATCH 5/6] Updating unit test --- packages/auth/src/api/index.test.ts | 52 +++++++++++++++-------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/packages/auth/src/api/index.test.ts b/packages/auth/src/api/index.test.ts index 10c823c6e3e..e0060d3067c 100644 --- a/packages/auth/src/api/index.test.ts +++ b/packages/auth/src/api/index.test.ts @@ -603,31 +603,33 @@ describe('api/_performApiRequest', () => { }); }); - it('should throw exception when tenantConfig is not initialized and Regional Endpoint is used', async () => { - await expect( - _performApiRequest( - auth, - HttpMethod.POST, - RegionalEndpoint.EXCHANGE_TOKEN, - request - ) - ).to.be.rejectedWith( - FirebaseError, - 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' - ); - }); + context('throws Operation now allowed exception', () => { + it('when tenantConfig is not initialized and Regional Endpoint is used', async () => { + await expect( + _performApiRequest( + auth, + HttpMethod.POST, + RegionalEndpoint.EXCHANGE_TOKEN, + request + ) + ).to.be.rejectedWith( + FirebaseError, + 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' + ); + }); - it('should throw exception when tenantConfig is initialized and default Endpoint is used', async () => { - await expect( - _performApiRequest( - regionalAuth, - HttpMethod.POST, - Endpoint.SIGN_UP, - request - ) - ).to.be.rejectedWith( - FirebaseError, - 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' - ); + it('when tenantConfig is initialized and default Endpoint is used', async () => { + await expect( + _performApiRequest( + regionalAuth, + HttpMethod.POST, + Endpoint.SIGN_UP, + request + ) + ).to.be.rejectedWith( + FirebaseError, + 'Firebase: Operations not allowed for the auth object initialized. (auth/operation-not-allowed).' + ); + }); }); }); From 6c9005baa47e3d81b33ee96f90e5156f4004b38d Mon Sep 17 00:00:00 2001 From: mansisampat Date: Tue, 13 May 2025 13:37:18 +0530 Subject: [PATCH 6/6] Fix typo --- packages/auth/src/api/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/auth/src/api/index.test.ts b/packages/auth/src/api/index.test.ts index e0060d3067c..87f674807c0 100644 --- a/packages/auth/src/api/index.test.ts +++ b/packages/auth/src/api/index.test.ts @@ -603,7 +603,7 @@ describe('api/_performApiRequest', () => { }); }); - context('throws Operation now allowed exception', () => { + context('throws Operation not allowed exception', () => { it('when tenantConfig is not initialized and Regional Endpoint is used', async () => { await expect( _performApiRequest(