diff --git a/etc/firebase-admin.auth.api.md b/etc/firebase-admin.auth.api.md index c7090af304..2986869ef2 100644 --- a/etc/firebase-admin.auth.api.md +++ b/etc/firebase-admin.auth.api.md @@ -23,35 +23,10 @@ export interface ActionCodeSettings { url: string; } -// @public -export interface AllowByDefault { - disallowedRegions: string[]; -} - -// @public -export interface AllowByDefaultWrap { - allowByDefault: AllowByDefault; - // @alpha (undocumented) - allowlistOnly?: never; -} - -// @public -export interface AllowlistOnly { - allowedRegions: string[]; -} - -// @public -export interface AllowlistOnlyWrap { - // @alpha (undocumented) - allowByDefault?: never; - allowlistOnly: AllowlistOnly; -} - // @public export class Auth extends BaseAuth { // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts get app(): App; - projectConfigManager(): ProjectConfigManager; tenantManager(): TenantManager; } @@ -334,18 +309,6 @@ export class PhoneMultiFactorInfo extends MultiFactorInfo { toJSON(): object; } -// @public -export class ProjectConfig { - readonly smsRegionConfig?: SmsRegionConfig; - toJSON(): object; -} - -// @public -export class ProjectConfigManager { - getProjectConfig(): Promise; - updateProjectConfig(projectConfigOptions: UpdateProjectConfigRequest): Promise; -} - // @public export interface ProviderIdentifier { // (undocumented) @@ -379,9 +342,6 @@ export interface SessionCookieOptions { expiresIn: number; } -// @public -export type SmsRegionConfig = AllowByDefaultWrap | AllowlistOnlyWrap; - // @public export class Tenant { // (undocumented) @@ -389,7 +349,6 @@ export class Tenant { readonly displayName?: string; get emailSignInConfig(): EmailSignInProviderConfig | undefined; get multiFactorConfig(): MultiFactorConfig | undefined; - readonly smsRegionConfig?: SmsRegionConfig; readonly tenantId: string; readonly testPhoneNumbers?: { [phoneNumber: string]: string; @@ -432,11 +391,6 @@ export interface UpdatePhoneMultiFactorInfoRequest extends BaseUpdateMultiFactor phoneNumber: string; } -// @public -export interface UpdateProjectConfigRequest { - smsRegionConfig?: SmsRegionConfig; -} - // @public export interface UpdateRequest { disabled?: boolean; @@ -457,7 +411,6 @@ export interface UpdateTenantRequest { displayName?: string; emailSignInConfig?: EmailSignInProviderConfig; multiFactorConfig?: MultiFactorConfig; - smsRegionConfig?: SmsRegionConfig; testPhoneNumbers?: { [phoneNumber: string]: string; } | null; diff --git a/src/auth/auth-api-request.ts b/src/auth/auth-api-request.ts index 2893d49a9d..a962a4f719 100644 --- a/src/auth/auth-api-request.ts +++ b/src/auth/auth-api-request.ts @@ -42,7 +42,6 @@ import { OIDCAuthProviderConfig, SAMLAuthProviderConfig, OIDCUpdateAuthProviderRequest, SAMLUpdateAuthProviderRequest } from './auth-config'; -import { ProjectConfig, ProjectConfigServerResponse, UpdateProjectConfigRequest } from './project-config'; /** Firebase Auth request header. */ const FIREBASE_AUTH_HEADER = { @@ -103,6 +102,7 @@ const FIREBASE_AUTH_TENANT_URL_FORMAT = FIREBASE_AUTH_BASE_URL_FORMAT.replace( const FIREBASE_AUTH_EMULATOR_TENANT_URL_FORMAT = FIREBASE_AUTH_EMULATOR_BASE_URL_FORMAT.replace( 'projects/{projectId}', 'projects/{projectId}/tenants/{tenantId}'); + /** Maximum allowed number of tenants to download at one time. */ const MAX_LIST_TENANT_PAGE_SIZE = 1000; @@ -1981,29 +1981,6 @@ export abstract class AbstractAuthRequestHandler { } } -/** Instantiates the getConfig endpoint settings. */ -const GET_PROJECT_CONFIG = new ApiSettings('/config', 'GET') - .setResponseValidator((response: any) => { - // Response should always contain at least the config name. - if (!validator.isNonEmptyString(response.name)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INTERNAL_ERROR, - 'INTERNAL ASSERT FAILED: Unable to get project config', - ); - } - }); - -/** Instantiates the updateConfig endpoint settings. */ -const UPDATE_PROJECT_CONFIG = new ApiSettings('/config?updateMask={updateMask}', 'PATCH') - .setResponseValidator((response: any) => { - // Response should always contain at least the config name. - if (!validator.isNonEmptyString(response.name)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INTERNAL_ERROR, - 'INTERNAL ASSERT FAILED: Unable to update project config', - ); - } - }); /** Instantiates the getTenant endpoint settings. */ const GET_TENANT = new ApiSettings('/tenants/{tenantId}', 'GET') @@ -2072,13 +2049,13 @@ const CREATE_TENANT = new ApiSettings('/tenants', 'POST') /** - * Utility for sending requests to Auth server that are Auth instance related. This includes user, tenant, - * and project config management related APIs. This extends the BaseFirebaseAuthRequestHandler class and defines + * Utility for sending requests to Auth server that are Auth instance related. This includes user and + * tenant management related APIs. This extends the BaseFirebaseAuthRequestHandler class and defines * additional tenant management related APIs. */ export class AuthRequestHandler extends AbstractAuthRequestHandler { - protected readonly authResourceUrlBuilder: AuthResourceUrlBuilder; + protected readonly tenantMgmtResourceBuilder: AuthResourceUrlBuilder; /** * The FirebaseAuthRequestHandler constructor used to initialize an instance using a FirebaseApp. @@ -2088,7 +2065,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler { */ constructor(app: App) { super(app); - this.authResourceUrlBuilder = new AuthResourceUrlBuilder(app, 'v2'); + this.tenantMgmtResourceBuilder = new AuthResourceUrlBuilder(app, 'v2'); } /** @@ -2105,35 +2082,6 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler { return new AuthResourceUrlBuilder(this.app, 'v2'); } - /** - * Get the current project's config - * @returns A promise that resolves with the project config information. - */ - public getProjectConfig(): Promise { - return this.invokeRequestHandler(this.authResourceUrlBuilder, GET_PROJECT_CONFIG, {}, {}) - .then((response: any) => { - return response as ProjectConfigServerResponse; - }); - } - - /** - * Update the current project's config. - * @returns A promise that resolves with the project config information. - */ - public updateProjectConfig(options: UpdateProjectConfigRequest): Promise { - try { - const request = ProjectConfig.buildServerRequest(options); - const updateMask = utils.generateUpdateMask(request); - return this.invokeRequestHandler( - this.authResourceUrlBuilder, UPDATE_PROJECT_CONFIG, request, { updateMask: updateMask.join(',') }) - .then((response: any) => { - return response as ProjectConfigServerResponse; - }); - } catch (e) { - return Promise.reject(e); - } - } - /** * Looks up a tenant by tenant ID. * @@ -2144,7 +2092,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler { if (!validator.isNonEmptyString(tenantId)) { return Promise.reject(new FirebaseAuthError(AuthClientErrorCode.INVALID_TENANT_ID)); } - return this.invokeRequestHandler(this.authResourceUrlBuilder, GET_TENANT, {}, { tenantId }) + return this.invokeRequestHandler(this.tenantMgmtResourceBuilder, GET_TENANT, {}, { tenantId }) .then((response: any) => { return response as TenantServerResponse; }); @@ -2174,7 +2122,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler { if (typeof request.pageToken === 'undefined') { delete request.pageToken; } - return this.invokeRequestHandler(this.authResourceUrlBuilder, LIST_TENANTS, request) + return this.invokeRequestHandler(this.tenantMgmtResourceBuilder, LIST_TENANTS, request) .then((response: any) => { if (!response.tenants) { response.tenants = []; @@ -2194,7 +2142,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler { if (!validator.isNonEmptyString(tenantId)) { return Promise.reject(new FirebaseAuthError(AuthClientErrorCode.INVALID_TENANT_ID)); } - return this.invokeRequestHandler(this.authResourceUrlBuilder, DELETE_TENANT, undefined, { tenantId }) + return this.invokeRequestHandler(this.tenantMgmtResourceBuilder, DELETE_TENANT, undefined, { tenantId }) .then(() => { // Return nothing. }); @@ -2210,7 +2158,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler { try { // Construct backend request. const request = Tenant.buildServerRequest(tenantOptions, true); - return this.invokeRequestHandler(this.authResourceUrlBuilder, CREATE_TENANT, request) + return this.invokeRequestHandler(this.tenantMgmtResourceBuilder, CREATE_TENANT, request) .then((response: any) => { return response as TenantServerResponse; }); @@ -2236,7 +2184,7 @@ export class AuthRequestHandler extends AbstractAuthRequestHandler { // Do not traverse deep into testPhoneNumbers. The entire content should be replaced // and not just specific phone numbers. const updateMask = utils.generateUpdateMask(request, ['testPhoneNumbers']); - return this.invokeRequestHandler(this.authResourceUrlBuilder, UPDATE_TENANT, request, + return this.invokeRequestHandler(this.tenantMgmtResourceBuilder, UPDATE_TENANT, request, { tenantId, updateMask: updateMask.join(',') }) .then((response: any) => { return response as TenantServerResponse; diff --git a/src/auth/auth-config.ts b/src/auth/auth-config.ts index 45ca3ef2d0..ce45713f97 100644 --- a/src/auth/auth-config.ts +++ b/src/auth/auth-config.ts @@ -1451,146 +1451,3 @@ export class OIDCConfig implements OIDCAuthProviderConfig { }; } } - -/** - * The request interface for updating a SMS Region Config. - * Configures the regions where users are allowed to send verification SMS. - * This is based on the calling code of the destination phone number. - */ -export type SmsRegionConfig = AllowByDefaultWrap | AllowlistOnlyWrap; - -/** - * Mutual exclusive SMS Region Config of AllowByDefault interface - */ -export interface AllowByDefaultWrap { - /** - * Allow every region by default. - */ - allowByDefault: AllowByDefault; - /** @alpha */ - allowlistOnly?: never; -} - -/** - * Mutually exclusive SMS Region Config of AllowlistOnly interface - */ -export interface AllowlistOnlyWrap { - /** - * Only allowing regions by explicitly adding them to an - * allowlist. - */ - allowlistOnly: AllowlistOnly; - /** @alpha */ - allowByDefault?: never; -} - -/** - * Defines a policy of allowing every region by default and adding disallowed - * regions to a disallow list. - */ -export interface AllowByDefault { - /** - * Two letter unicode region codes to disallow as defined by - * https://cldr.unicode.org/ - * The full list of these region codes is here: - * https://github.com/unicode-cldr/cldr-localenames-full/blob/master/main/en/territories.json - */ - disallowedRegions: string[]; -} - -/** - * Defines a policy of only allowing regions by explicitly adding them to an - * allowlist. - */ -export interface AllowlistOnly { - /** - * Two letter unicode region codes to allow as defined by - * https://cldr.unicode.org/ - * The full list of these region codes is here: - * https://github.com/unicode-cldr/cldr-localenames-full/blob/master/main/en/territories.json - */ - allowedRegions: string[]; -} - -/** - * Defines the SMSRegionConfig class used for validation. - * - * @internal - */ -export class SmsRegionsAuthConfig { - public static validate(options: SmsRegionConfig): void { - if (!validator.isNonNullObject(options)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_CONFIG, - '"SmsRegionConfig" must be a non-null object.', - ); - } - - const validKeys = { - allowlistOnly: true, - allowByDefault: true, - }; - - for (const key in options) { - if (!(key in validKeys)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_CONFIG, - `"${key}" is not a valid SmsRegionConfig parameter.`, - ); - } - } - - // validate mutual exclusiveness of allowByDefault and allowlistOnly - if (typeof options.allowByDefault !== 'undefined' && typeof options.allowlistOnly !== 'undefined') { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_CONFIG, - 'SmsRegionConfig cannot have both "allowByDefault" and "allowlistOnly" parameters.', - ); - } - // validation for allowByDefault type - if (typeof options.allowByDefault !== 'undefined') { - const allowByDefaultValidKeys = { - disallowedRegions: true, - } - for (const key in options.allowByDefault) { - if (!(key in allowByDefaultValidKeys)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_CONFIG, - `"${key}" is not a valid SmsRegionConfig.allowByDefault parameter.`, - ); - } - } - // disallowedRegion can be empty. - if (typeof options.allowByDefault.disallowedRegions !== 'undefined' - && !validator.isArray(options.allowByDefault.disallowedRegions)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_CONFIG, - '"SmsRegionConfig.allowByDefault.disallowedRegions" must be a valid string array.', - ); - } - } - - if (typeof options.allowlistOnly !== 'undefined') { - const allowListOnlyValidKeys = { - allowedRegions: true, - } - for (const key in options.allowlistOnly) { - if (!(key in allowListOnlyValidKeys)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_CONFIG, - `"${key}" is not a valid SmsRegionConfig.allowlistOnly parameter.`, - ); - } - } - - // allowedRegions can be empty - if (typeof options.allowlistOnly.allowedRegions !== 'undefined' - && !validator.isArray(options.allowlistOnly.allowedRegions)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_CONFIG, - '"SmsRegionConfig.allowlistOnly.allowedRegions" must be a valid string array.', - ); - } - } - } -} diff --git a/src/auth/auth.ts b/src/auth/auth.ts index 4808fbbdc0..d9b5aa7978 100644 --- a/src/auth/auth.ts +++ b/src/auth/auth.ts @@ -19,7 +19,6 @@ import { App } from '../app/index'; import { AuthRequestHandler } from './auth-api-request'; import { TenantManager } from './tenant-manager'; import { BaseAuth } from './base-auth'; -import { ProjectConfigManager } from './project-config-manager'; /** * Auth service bound to the provided app. @@ -28,7 +27,6 @@ import { ProjectConfigManager } from './project-config-manager'; export class Auth extends BaseAuth { private readonly tenantManager_: TenantManager; - private readonly projectConfigManager_: ProjectConfigManager; private readonly app_: App; /** @@ -40,7 +38,6 @@ export class Auth extends BaseAuth { super(app, new AuthRequestHandler(app)); this.app_ = app; this.tenantManager_ = new TenantManager(app); - this.projectConfigManager_ = new ProjectConfigManager(app); } /** @@ -60,13 +57,4 @@ export class Auth extends BaseAuth { public tenantManager(): TenantManager { return this.tenantManager_; } - - /** - * Returns the project config manager instance associated with the current project. - * - * @returns The project config manager instance associated with the current project. - */ - public projectConfigManager(): ProjectConfigManager { - return this.projectConfigManager_; - } } diff --git a/src/auth/index.ts b/src/auth/index.ts index 7dec658473..5a7e668244 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -61,10 +61,6 @@ export { } from './auth'; export { - AllowByDefault, - AllowByDefaultWrap, - AllowlistOnly, - AllowlistOnlyWrap, AuthFactorType, AuthProviderConfig, AuthProviderConfigFilter, @@ -85,7 +81,6 @@ export { OIDCUpdateAuthProviderRequest, SAMLAuthProviderConfig, SAMLUpdateAuthProviderRequest, - SmsRegionConfig, UserProvider, UpdateAuthProviderRequest, UpdateMultiFactorInfoRequest, @@ -121,15 +116,6 @@ export { TenantManager, } from './tenant-manager'; -export { - UpdateProjectConfigRequest, - ProjectConfig, -} from './project-config'; - -export { - ProjectConfigManager, -} from './project-config-manager'; - export { DecodedIdToken, DecodedAuthBlockingToken diff --git a/src/auth/project-config-manager.ts b/src/auth/project-config-manager.ts deleted file mode 100644 index 030b64a779..0000000000 --- a/src/auth/project-config-manager.ts +++ /dev/null @@ -1,67 +0,0 @@ -/*! - * Copyright 2022 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { App } from '../app'; -import { ProjectConfig, ProjectConfigServerResponse, UpdateProjectConfigRequest } from './project-config'; -import { - AuthRequestHandler, -} from './auth-api-request'; - -/** - * Defines the project config manager used to help manage project config related operations. - * This includes: - *
    - *
  • The ability to update and get project config.
  • - */ -export class ProjectConfigManager { - private readonly authRequestHandler: AuthRequestHandler; - - /** - * Initializes a ProjectConfigManager instance for a specified FirebaseApp. - * - * @param app - The app for this ProjectConfigManager instance. - * - * @constructor - * @internal - */ - constructor(app: App) { - this.authRequestHandler = new AuthRequestHandler(app); - } - - /** - * Get the project configuration. - * - * @returns A promise fulfilled with the project configuration. - */ - public getProjectConfig(): Promise { - return this.authRequestHandler.getProjectConfig() - .then((response: ProjectConfigServerResponse) => { - return new ProjectConfig(response); - }) - } - /** - * Updates an existing project configuration. - * - * @param projectConfigOptions - The properties to update on the project. - * - * @returns A promise fulfilled with the updated project config. - */ - public updateProjectConfig(projectConfigOptions: UpdateProjectConfigRequest): Promise { - return this.authRequestHandler.updateProjectConfig(projectConfigOptions) - .then((response: ProjectConfigServerResponse) => { - return new ProjectConfig(response); - }) - } -} diff --git a/src/auth/project-config.ts b/src/auth/project-config.ts deleted file mode 100644 index 54dcfb3b9c..0000000000 --- a/src/auth/project-config.ts +++ /dev/null @@ -1,131 +0,0 @@ -/*! - * Copyright 2022 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import * as validator from '../utils/validator'; -import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error'; -import { - SmsRegionsAuthConfig, - SmsRegionConfig, -} from './auth-config'; -import { deepCopy } from '../utils/deep-copy'; - -/** - * Interface representing the properties to update on the provided project config. - */ -export interface UpdateProjectConfigRequest { - /** - * The SMS configuration to update on the project. - */ - smsRegionConfig?: SmsRegionConfig; -} - -/** - * Response received from getting or updating a project config. - * This object currently exposes only the SMS Region config. - */ -export interface ProjectConfigServerResponse { - smsRegionConfig?: SmsRegionConfig; -} - -/** - * Request sent to update project config. - * This object currently exposes only the SMS Region config. - */ -export interface ProjectConfigClientRequest { - smsRegionConfig?: SmsRegionConfig; -} - -/** -* Represents a project configuration. -*/ -export class ProjectConfig { - /** - * The SMS Regions Config for the project. - * Configures the regions where users are allowed to send verification SMS. - * This is based on the calling code of the destination phone number. - */ - public readonly smsRegionConfig?: SmsRegionConfig; - - /** - * Validates a project config options object. Throws an error on failure. - * - * @param request - The project config options object to validate. - */ - private static validate(request: ProjectConfigClientRequest): void { - if (!validator.isNonNullObject(request)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_ARGUMENT, - '"UpdateProjectConfigRequest" must be a valid non-null object.', - ); - } - const validKeys = { - smsRegionConfig: true, - } - // Check for unsupported top level attributes. - for (const key in request) { - if (!(key in validKeys)) { - throw new FirebaseAuthError( - AuthClientErrorCode.INVALID_ARGUMENT, - `"${key}" is not a valid UpdateProjectConfigRequest parameter.`, - ); - } - } - // Validate SMS Regions Config if provided. - if (typeof request.smsRegionConfig !== 'undefined') { - SmsRegionsAuthConfig.validate(request.smsRegionConfig); - } - } - - /** - * Build the corresponding server request for a UpdateProjectConfigRequest object. - * @param configOptions - The properties to convert to a server request. - * @returns The equivalent server request. - * - * @internal - */ - public static buildServerRequest(configOptions: UpdateProjectConfigRequest): ProjectConfigClientRequest { - ProjectConfig.validate(configOptions); - return configOptions as ProjectConfigClientRequest; - } - - /** - * The Project Config object constructor. - * - * @param response - The server side response used to initialize the Project Config object. - * @constructor - * @internal - */ - constructor(response: ProjectConfigServerResponse) { - if (typeof response.smsRegionConfig !== 'undefined') { - this.smsRegionConfig = response.smsRegionConfig; - } - } - /** - * Returns a JSON-serializable representation of this object. - * - * @returns A JSON-serializable representation of this object. - */ - public toJSON(): object { - // JSON serialization - const json = { - smsRegionConfig: deepCopy(this.smsRegionConfig), - }; - if (typeof json.smsRegionConfig === 'undefined') { - delete json.smsRegionConfig; - } - return json; - } -} - diff --git a/src/auth/tenant.ts b/src/auth/tenant.ts index 56cf2abd8d..e489fa3b09 100644 --- a/src/auth/tenant.ts +++ b/src/auth/tenant.ts @@ -21,7 +21,7 @@ import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error'; import { EmailSignInConfig, EmailSignInConfigServerRequest, MultiFactorAuthServerConfig, MultiFactorConfig, validateTestPhoneNumbers, EmailSignInProviderConfig, - MultiFactorAuthConfig, SmsRegionConfig, SmsRegionsAuthConfig + MultiFactorAuthConfig, } from './auth-config'; /** @@ -54,11 +54,6 @@ export interface UpdateTenantRequest { * Passing null clears the previously save phone number / code pairs. */ testPhoneNumbers?: { [phoneNumber: string]: string } | null; - - /** - * The SMS configuration to update on the project. - */ - smsRegionConfig?: SmsRegionConfig; } /** @@ -73,7 +68,6 @@ export interface TenantOptionsServerRequest extends EmailSignInConfigServerReque enableAnonymousUser?: boolean; mfaConfig?: MultiFactorAuthServerConfig; testPhoneNumbers?: {[key: string]: string}; - smsRegionConfig?: SmsRegionConfig; } /** The tenant server response interface. */ @@ -85,7 +79,6 @@ export interface TenantServerResponse { enableAnonymousUser?: boolean; mfaConfig?: MultiFactorAuthServerConfig; testPhoneNumbers?: {[key: string]: string}; - smsRegionConfig?: SmsRegionConfig; } /** @@ -130,13 +123,6 @@ export class Tenant { private readonly emailSignInConfig_?: EmailSignInConfig; private readonly multiFactorConfig_?: MultiFactorAuthConfig; - /** - * The SMS Regions Config to update a tenant. - * Configures the regions where users are allowed to send verification SMS. - * This is based on the calling code of the destination phone number. - */ - public readonly smsRegionConfig?: SmsRegionConfig; - /** * Builds the corresponding server request for a TenantOptions object. * @@ -166,9 +152,6 @@ export class Tenant { // null will clear existing test phone numbers. Translate to empty object. request.testPhoneNumbers = tenantOptions.testPhoneNumbers ?? {}; } - if (typeof tenantOptions.smsRegionConfig !== 'undefined') { - request.smsRegionConfig = tenantOptions.smsRegionConfig; - } return request; } @@ -202,7 +185,6 @@ export class Tenant { anonymousSignInEnabled: true, multiFactorConfig: true, testPhoneNumbers: true, - smsRegionConfig: true, }; const label = createRequest ? 'CreateTenantRequest' : 'UpdateTenantRequest'; if (!validator.isNonNullObject(request)) { @@ -249,10 +231,6 @@ export class Tenant { // This will throw an error if invalid. MultiFactorAuthConfig.buildServerRequest(request.multiFactorConfig); } - // Validate SMS Regions Config if provided. - if (typeof request.smsRegionConfig != 'undefined') { - SmsRegionsAuthConfig.validate(request.smsRegionConfig); - } } /** @@ -287,9 +265,6 @@ export class Tenant { if (typeof response.testPhoneNumbers !== 'undefined') { this.testPhoneNumbers = deepCopy(response.testPhoneNumbers || {}); } - if (typeof response.smsRegionConfig !== 'undefined') { - this.smsRegionConfig = deepCopy(response.smsRegionConfig); - } } /** @@ -319,7 +294,6 @@ export class Tenant { multiFactorConfig: this.multiFactorConfig_?.toJSON(), anonymousSignInEnabled: this.anonymousSignInEnabled, testPhoneNumbers: this.testPhoneNumbers, - smsRegionConfig: deepCopy(this.smsRegionConfig), }; if (typeof json.multiFactorConfig === 'undefined') { delete json.multiFactorConfig; @@ -327,9 +301,6 @@ export class Tenant { if (typeof json.testPhoneNumbers === 'undefined') { delete json.testPhoneNumbers; } - if (typeof json.smsRegionConfig === 'undefined') { - delete json.smsRegionConfig; - } return json; } } diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index 9245ac5211..e1005d9c4a 100644 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -31,7 +31,7 @@ import { deepExtend, deepCopy } from '../../src/utils/deep-copy'; import { AuthProviderConfig, CreateTenantRequest, DeleteUsersResult, PhoneMultiFactorInfo, TenantAwareAuth, UpdatePhoneMultiFactorInfoRequest, UpdateTenantRequest, UserImportOptions, - UserImportRecord, UserRecord, getAuth, UpdateProjectConfigRequest, + UserImportRecord, UserRecord, getAuth, } from '../../lib/auth/index'; const chalk = require('chalk'); // eslint-disable-line @typescript-eslint/no-var-requires @@ -1180,61 +1180,6 @@ describe('admin.auth', () => { }); }); - describe('Project config management operations', () => { - before(function() { - if (authEmulatorHost) { - this.skip(); // getConfig is not supported in Auth Emulator - } - }); - const projectConfigOption1: UpdateProjectConfigRequest = { - smsRegionConfig: { - allowByDefault: { - disallowedRegions: [ 'AC', 'AD' ], - } - }, - }; - const projectConfigOption2: UpdateProjectConfigRequest = { - smsRegionConfig: { - allowlistOnly: { - allowedRegions: [ 'AC', 'AD' ], - } - }, - }; - const expectedProjectConfig1: any = { - smsRegionConfig: { - allowByDefault: { - disallowedRegions: [ 'AC', 'AD' ], - } - }, - }; - const expectedProjectConfig2: any = { - smsRegionConfig: { - allowlistOnly: { - allowedRegions: [ 'AC', 'AD' ], - } - }, - }; - - it('updateProjectConfig() should resolve with the updated project config', () => { - return getAuth().projectConfigManager().updateProjectConfig(projectConfigOption1) - .then((actualProjectConfig) => { - expect(actualProjectConfig.toJSON()).to.deep.equal(expectedProjectConfig1); - return getAuth().projectConfigManager().updateProjectConfig(projectConfigOption2); - }) - .then((actualProjectConfig) => { - expect(actualProjectConfig.toJSON()).to.deep.equal(expectedProjectConfig2); - }); - }); - - it('getProjectConfig() should resolve with expected project config', () => { - return getAuth().projectConfigManager().getProjectConfig() - .then((actualConfig) => { - const actualConfigObj = actualConfig.toJSON(); - expect(actualConfigObj).to.deep.equal(expectedProjectConfig2); - }); - }); - }); - describe('Tenant management operations', () => { let createdTenantId: string; const createdTenants: string[] = []; @@ -1303,11 +1248,6 @@ describe('admin.auth', () => { state: 'ENABLED', factorIds: ['phone'], }, - smsRegionConfig: { - allowByDefault: { - disallowedRegions: [ 'AC', 'AD' ], - } - }, }; // https://mochajs.org/ @@ -1729,7 +1669,6 @@ describe('admin.auth', () => { multiFactorConfig: deepCopy(expectedUpdatedTenant2.multiFactorConfig), // Test clearing of phone numbers. testPhoneNumbers: null, - smsRegionConfig: deepCopy(expectedUpdatedTenant2.smsRegionConfig), }; if (authEmulatorHost) { return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions) @@ -1759,28 +1698,6 @@ describe('admin.auth', () => { }); }); - it('updateTenant() should not update tenant when SMS region config is undefined', () => { - expectedUpdatedTenant.tenantId = createdTenantId; - const updatedOptions2: UpdateTenantRequest = { - displayName: expectedUpdatedTenant2.displayName, - smsRegionConfig: undefined, - }; - if (authEmulatorHost) { - return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2) - .then((actualTenant) => { - const actualTenantObj = actualTenant.toJSON(); - // Not supported in Auth Emulator - delete (actualTenantObj as {testPhoneNumbers: Record}).testPhoneNumbers; - delete expectedUpdatedTenant2.testPhoneNumbers; - expect(actualTenantObj).to.deep.equal(expectedUpdatedTenant2); - }); - } - return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2) - .then((actualTenant) => { - expect(actualTenant.toJSON()).to.deep.equal(expectedUpdatedTenant2); - }); - }); - it('updateTenant() should be able to enable/disable anon provider', async () => { const tenantManager = getAuth().tenantManager(); let tenant = await tenantManager.createTenant({ diff --git a/test/unit/auth/project-config-manager.spec.ts b/test/unit/auth/project-config-manager.spec.ts deleted file mode 100644 index d06b24fa80..0000000000 --- a/test/unit/auth/project-config-manager.spec.ts +++ /dev/null @@ -1,196 +0,0 @@ -/*! - * Copyright 2022 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -import * as _ from 'lodash'; -import * as chai from 'chai'; -import * as sinon from 'sinon'; -import * as sinonChai from 'sinon-chai'; -import * as chaiAsPromised from 'chai-as-promised'; - -import * as mocks from '../../resources/mocks'; -import { FirebaseApp } from '../../../src/app/firebase-app'; -import { AuthRequestHandler } from '../../../src/auth/auth-api-request'; -import { AuthClientErrorCode, FirebaseAuthError } from '../../../src/utils/error'; -import { ProjectConfigManager } from '../../../src/auth/project-config-manager'; -import { - ProjectConfig, - ProjectConfigServerResponse, - UpdateProjectConfigRequest -} from '../../../src/auth/project-config'; - -chai.should(); -chai.use(sinonChai); -chai.use(chaiAsPromised); - -const expect = chai.expect; - -describe('ProjectConfigManager', () => { - let mockApp: FirebaseApp; - let projectConfigManager: ProjectConfigManager; - let nullAccessTokenProjectConfigManager: ProjectConfigManager; - let malformedAccessTokenProjectConfigManager: ProjectConfigManager; - let rejectedPromiseAccessTokenProjectConfigManager: ProjectConfigManager; - const GET_CONFIG_RESPONSE: ProjectConfigServerResponse = { - smsRegionConfig: { - allowlistOnly: { - allowedRegions: [ 'AC', 'AD' ], - }, - }, - }; - - before(() => { - mockApp = mocks.app(); - projectConfigManager = new ProjectConfigManager(mockApp); - nullAccessTokenProjectConfigManager = new ProjectConfigManager( - mocks.appReturningNullAccessToken()); - malformedAccessTokenProjectConfigManager = new ProjectConfigManager( - mocks.appReturningMalformedAccessToken()); - rejectedPromiseAccessTokenProjectConfigManager = new ProjectConfigManager( - mocks.appRejectedWhileFetchingAccessToken()); - }); - - after(() => { - return mockApp.delete(); - }); - - describe('getProjectConfig()', () => { - const expectedProjectConfig = new ProjectConfig(GET_CONFIG_RESPONSE); - const expectedError = new FirebaseAuthError(AuthClientErrorCode.INVALID_CONFIG); - // Stubs used to simulate underlying API calls. - let stubs: sinon.SinonStub[] = []; - afterEach(() => { - _.forEach(stubs, (stub) => stub.restore()); - stubs = []; - }); - - it('should be rejected given an app which returns null access tokens', () => { - return nullAccessTokenProjectConfigManager.getProjectConfig() - .should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); - }); - - it('should be rejected given an app which returns invalid access tokens', () => { - return malformedAccessTokenProjectConfigManager.getProjectConfig() - .should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); - }); - - it('should be rejected given an app which fails to generate access tokens', () => { - return rejectedPromiseAccessTokenProjectConfigManager.getProjectConfig() - .should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); - }); - - it('should resolve with a Project Config on success', () => { - // Stub getProjectConfig to return expected result. - const stub = sinon.stub(AuthRequestHandler.prototype, 'getProjectConfig') - .returns(Promise.resolve(GET_CONFIG_RESPONSE)); - stubs.push(stub); - return projectConfigManager.getProjectConfig() - .then((result) => { - // Confirm underlying API called with expected parameters. - expect(stub).to.have.been.calledOnce; - // Confirm expected project config returned. - expect(result).to.deep.equal(expectedProjectConfig); - }); - }); - - it('should throw an error when the backend returns an error', () => { - // Stub getConfig to throw a backend error. - const stub = sinon.stub(AuthRequestHandler.prototype, 'getProjectConfig') - .returns(Promise.reject(expectedError)); - stubs.push(stub); - return projectConfigManager.getProjectConfig() - .then(() => { - throw new Error('Unexpected success'); - }, (error) => { - // Confirm underlying API called with expected parameters. - expect(stub).to.have.been.calledOnce; - // Confirm expected error returned. - expect(error).to.equal(expectedError); - }); - }); - }); - - describe('updateProjectConfig()', () => { - const projectConfigOptions: UpdateProjectConfigRequest = { - smsRegionConfig: { - allowByDefault: { - disallowedRegions: [ 'AC', 'AD' ], - }, - }, - }; - const expectedProjectConfig = new ProjectConfig(GET_CONFIG_RESPONSE); - const expectedError = new FirebaseAuthError( - AuthClientErrorCode.INTERNAL_ERROR, - 'Unable to update the config provided.'); - // Stubs used to simulate underlying API calls. - let stubs: sinon.SinonStub[] = []; - afterEach(() => { - _.forEach(stubs, (stub) => stub.restore()); - stubs = []; - }); - - it('should be rejected given no projectConfigOptions', () => { - return (projectConfigManager as any).updateProjectConfig(null as unknown as UpdateProjectConfigRequest) - .should.eventually.be.rejected.and.have.property('code', 'auth/argument-error'); - }); - - it('should be rejected given an app which returns null access tokens', () => { - return nullAccessTokenProjectConfigManager.updateProjectConfig(projectConfigOptions) - .should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); - }); - - it('should be rejected given an app which returns invalid access tokens', () => { - return malformedAccessTokenProjectConfigManager.updateProjectConfig(projectConfigOptions) - .should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); - }); - - it('should be rejected given an app which fails to generate access tokens', () => { - return rejectedPromiseAccessTokenProjectConfigManager.updateProjectConfig(projectConfigOptions) - .should.eventually.be.rejected.and.have.property('code', 'app/invalid-credential'); - }); - - it('should resolve with a ProjectConfig on updateProjectConfig request success', () => { - // Stub updateProjectConfig to return expected result. - const updateConfigStub = sinon.stub(AuthRequestHandler.prototype, 'updateProjectConfig') - .returns(Promise.resolve(GET_CONFIG_RESPONSE)); - stubs.push(updateConfigStub); - return projectConfigManager.updateProjectConfig(projectConfigOptions) - .then((actualProjectConfig) => { - // Confirm underlying API called with expected parameters. - expect(updateConfigStub).to.have.been.calledOnce.and.calledWith(projectConfigOptions); - // Confirm expected Project Config object returned. - expect(actualProjectConfig).to.deep.equal(expectedProjectConfig); - }); - }); - - it('should throw an error when updateProjectConfig returns an error', () => { - // Stub updateProjectConfig to throw a backend error. - const updateConfigStub = sinon.stub(AuthRequestHandler.prototype, 'updateProjectConfig') - .returns(Promise.reject(expectedError)); - stubs.push(updateConfigStub); - return projectConfigManager.updateProjectConfig(projectConfigOptions) - .then(() => { - throw new Error('Unexpected success'); - }, (error) => { - // Confirm underlying API called with expected parameters. - expect(updateConfigStub).to.have.been.calledOnce.and.calledWith(projectConfigOptions); - // Confirm expected error returned. - expect(error).to.equal(expectedError); - }); - }); - }); -}); \ No newline at end of file diff --git a/test/unit/auth/project-config.spec.ts b/test/unit/auth/project-config.spec.ts deleted file mode 100644 index 19cc8f420d..0000000000 --- a/test/unit/auth/project-config.spec.ts +++ /dev/null @@ -1,192 +0,0 @@ -/*! - * Copyright 2022 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as _ from 'lodash'; -import * as chai from 'chai'; -import * as sinonChai from 'sinon-chai'; -import * as chaiAsPromised from 'chai-as-promised'; - -import { deepCopy } from '../../../src/utils/deep-copy'; -import { - ProjectConfig, - ProjectConfigServerResponse, - UpdateProjectConfigRequest, -} from '../../../src/auth/project-config'; - -chai.should(); -chai.use(sinonChai); -chai.use(chaiAsPromised); - -const expect = chai.expect; - -describe('ProjectConfig', () => { - const serverResponse: ProjectConfigServerResponse = { - smsRegionConfig: { - allowByDefault: { - disallowedRegions: [ 'AC', 'AD' ], - }, - }, - }; - - const updateProjectConfigRequest1: UpdateProjectConfigRequest = { - smsRegionConfig: { - allowByDefault: { - disallowedRegions: [ 'AC', 'AD' ], - }, - }, - }; - - const updateProjectConfigRequest2: UpdateProjectConfigRequest = { - smsRegionConfig: { - allowlistOnly: { - allowedRegions: [ 'AC', 'AD' ], - }, - }, - }; - - const updateProjectConfigRequest3: any = { - smsRegionConfig: { - allowlistOnly: { - allowedRegions: [ 'AC', 'AD' ], - }, - allowByDefault: { - disallowedRegions: ['AC', 'AD'], - }, - }, - }; - - describe('buildServerRequest()', () => { - - describe('for an update request', () => { - it('should throw on null SmsRegionConfig attribute', () => { - const configOptionsClientRequest = deepCopy(updateProjectConfigRequest1) as any; - configOptionsClientRequest.smsRegionConfig = null; - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest); - }).to.throw('"SmsRegionConfig" must be a non-null object.'); - }); - - it('should throw on invalid SmsRegionConfig attribute', () => { - const configOptionsClientRequest = deepCopy(updateProjectConfigRequest1) as any; - configOptionsClientRequest.smsRegionConfig.invalidParameter = 'invalid'; - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest); - }).to.throw('"invalidParameter" is not a valid SmsRegionConfig parameter.'); - }); - - it('should throw on invalid allowlistOnly attribute', () => { - const configOptionsClientRequest = deepCopy(updateProjectConfigRequest2) as any; - configOptionsClientRequest.smsRegionConfig.allowlistOnly.disallowedRegions = [ 'AC', 'AD' ]; - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest); - }).to.throw('"disallowedRegions" is not a valid SmsRegionConfig.allowlistOnly parameter.'); - }); - - it('should throw on invalid allowByDefault attribute', () => { - const configOptionsClientRequest = deepCopy(updateProjectConfigRequest1) as any; - configOptionsClientRequest.smsRegionConfig.allowByDefault.allowedRegions = [ 'AC', 'AD' ]; - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest); - }).to.throw('"allowedRegions" is not a valid SmsRegionConfig.allowByDefault parameter.'); - }); - - it('should throw on non-array disallowedRegions attribute', () => { - const configOptionsClientRequest = deepCopy(updateProjectConfigRequest1) as any; - configOptionsClientRequest.smsRegionConfig.allowByDefault.disallowedRegions = 'non-array'; - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest); - }).to.throw('"SmsRegionConfig.allowByDefault.disallowedRegions" must be a valid string array.'); - }); - - it('should throw on non-array allowedRegions attribute', () => { - const configOptionsClientRequest = deepCopy(updateProjectConfigRequest2) as any; - configOptionsClientRequest.smsRegionConfig.allowlistOnly.allowedRegions = 'non-array'; - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest); - }).to.throw('"SmsRegionConfig.allowlistOnly.allowedRegions" must be a valid string array.'); - }); - - it('should throw when both allowlistOnly and allowByDefault attributes are presented', () => { - const configOptionsClientRequest = deepCopy(updateProjectConfigRequest3) as any; - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest); - }).to.throw('SmsRegionConfig cannot have both "allowByDefault" and "allowlistOnly" parameters.'); - }); - - it('should not throw on valid client request object', () => { - const configOptionsClientRequest1 = deepCopy(updateProjectConfigRequest1); - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest1); - }).not.to.throw; - const configOptionsClientRequest2 = deepCopy(updateProjectConfigRequest2); - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest2); - }).not.to.throw; - }); - - const nonObjects = [null, NaN, 0, 1, true, false, '', 'a', [], [1, 'a'], _.noop]; - nonObjects.forEach((request) => { - it('should throw on invalid UpdateProjectConfigRequest:' + JSON.stringify(request), () => { - expect(() => { - ProjectConfig.buildServerRequest(request as any); - }).to.throw('"UpdateProjectConfigRequest" must be a valid non-null object.'); - }); - }); - - it('should throw on unsupported attribute for update request', () => { - const configOptionsClientRequest = deepCopy(updateProjectConfigRequest1) as any; - configOptionsClientRequest.unsupported = 'value'; - expect(() => { - ProjectConfig.buildServerRequest(configOptionsClientRequest); - }).to.throw('"unsupported" is not a valid UpdateProjectConfigRequest parameter.'); - }); - }); - }); - - describe('constructor', () => { - const serverResponseCopy: ProjectConfigServerResponse = deepCopy(serverResponse); - const projectConfig = new ProjectConfig(serverResponseCopy); - - it('should not throw on valid initialization', () => { - expect(() => new ProjectConfig(serverResponse)).not.to.throw(); - }); - - it('should set readonly property smsRegionConfig', () => { - const expectedSmsRegionConfig = { - allowByDefault: { - disallowedRegions: [ 'AC', 'AD' ], - }, - }; - expect(projectConfig.smsRegionConfig).to.deep.equal(expectedSmsRegionConfig); - }); - }); - - describe('toJSON()', () => { - const serverResponseCopy: ProjectConfigServerResponse = deepCopy(serverResponse); - it('should return the expected object representation of project config', () => { - expect(new ProjectConfig(serverResponseCopy).toJSON()).to.deep.equal({ - smsRegionConfig: deepCopy(serverResponse.smsRegionConfig) - }); - }); - - it('should not populate optional fields if not available', () => { - const serverResponseOptionalCopy: ProjectConfigServerResponse = deepCopy(serverResponse); - delete serverResponseOptionalCopy.smsRegionConfig; - - expect(new ProjectConfig(serverResponseOptionalCopy).toJSON()).to.deep.equal({}); - }); - }); -}); \ No newline at end of file diff --git a/test/unit/auth/tenant.spec.ts b/test/unit/auth/tenant.spec.ts index 4780cbb473..0f14856faa 100644 --- a/test/unit/auth/tenant.spec.ts +++ b/test/unit/auth/tenant.spec.ts @@ -33,18 +33,6 @@ chai.use(chaiAsPromised); const expect = chai.expect; describe('Tenant', () => { - const smsAllowByDefault = { - allowByDefault: { - disallowedRegions: [ 'AC', 'AD' ], - }, - }; - - const smsAllowlistOnly = { - allowlistOnly: { - allowedRegions: [ 'AC', 'AD' ], - }, - }; - const serverRequest: TenantServerResponse = { name: 'projects/project1/tenants/TENANT-ID', displayName: 'TENANT-DISPLAY-NAME', @@ -58,7 +46,6 @@ describe('Tenant', () => { '+16505551234': '019287', '+16505550676': '985235', }, - smsRegionConfig: smsAllowByDefault, }; const clientRequest: UpdateTenantRequest = { @@ -75,7 +62,6 @@ describe('Tenant', () => { '+16505551234': '019287', '+16505550676': '985235', }, - smsRegionConfig: smsAllowByDefault, }; const serverRequestWithoutMfa: TenantServerResponse = { @@ -155,64 +141,6 @@ describe('Tenant', () => { .to.deep.equal(tenantOptionsServerRequest); }); - it('should throw on null SmsRegionConfig attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig = null; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, !createRequest); - }).to.throw('"SmsRegionConfig" must be a non-null object.'); - }); - - it('should throw on invalid SmsRegionConfig attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig.invalidParameter = 'invalid'; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, !createRequest); - }).to.throw('"invalidParameter" is not a valid SmsRegionConfig parameter.'); - }); - - it('should throw on invalid allowlistOnly attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig = deepCopy(smsAllowlistOnly); - tenantOptionsClientRequest.smsRegionConfig.allowlistOnly.disallowedRegions = [ 'AC', 'AD' ]; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, !createRequest); - }).to.throw('"disallowedRegions" is not a valid SmsRegionConfig.allowlistOnly parameter.'); - }); - - it('should throw on invalid allowByDefault attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig.allowByDefault.allowedRegions = [ 'AC', 'AD' ]; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, !createRequest); - }).to.throw('"allowedRegions" is not a valid SmsRegionConfig.allowByDefault parameter.'); - }); - - it('should throw on non-array disallowedRegions attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig.allowByDefault.disallowedRegions = 'non-array'; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, !createRequest); - }).to.throw('"SmsRegionConfig.allowByDefault.disallowedRegions" must be a valid string array.'); - }); - - it('should throw on non-array allowedRegions attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig = deepCopy(smsAllowlistOnly); - tenantOptionsClientRequest.smsRegionConfig.allowlistOnly.allowedRegions = 'non-array'; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, !createRequest); - }).to.throw('"SmsRegionConfig.allowlistOnly.allowedRegions" must be a valid string array.'); - }); - - it('should throw when both allowlistOnly and allowByDefault attributes are presented', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig = { ...smsAllowByDefault, ...smsAllowlistOnly }; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, !createRequest); - }).to.throw('SmsRegionConfig cannot have both "allowByDefault" and "allowlistOnly" parameters.'); - }); - it('should not throw on valid client request object', () => { const tenantOptionsClientRequest = deepCopy(clientRequest); expect(() => { @@ -304,64 +232,6 @@ describe('Tenant', () => { }).to.throw('"CreateTenantRequest.testPhoneNumbers" must be a non-null object.'); }); - it('should throw on null SmsRegionConfig attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig = null; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, createRequest); - }).to.throw('"SmsRegionConfig" must be a non-null object.'); - }); - - it('should throw on invalid SmsRegionConfig attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig.invalidParameter = 'invalid'; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, createRequest); - }).to.throw('"invalidParameter" is not a valid SmsRegionConfig parameter.'); - }); - - it('should throw on invalid allowlistOnly attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig = deepCopy(smsAllowlistOnly); - tenantOptionsClientRequest.smsRegionConfig.allowlistOnly.disallowedRegions = [ 'AC', 'AD' ]; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, createRequest); - }).to.throw('"disallowedRegions" is not a valid SmsRegionConfig.allowlistOnly parameter.'); - }); - - it('should throw on invalid allowByDefault attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig.allowByDefault.allowedRegions = [ 'AC', 'AD' ]; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, createRequest); - }).to.throw('"allowedRegions" is not a valid SmsRegionConfig.allowByDefault parameter.'); - }); - - it('should throw on non-array disallowedRegions attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig.allowByDefault.disallowedRegions = 'non-array'; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, createRequest); - }).to.throw('"SmsRegionConfig.allowByDefault.disallowedRegions" must be a valid string array.'); - }); - - it('should throw on non-array allowedRegions attribute', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig = deepCopy(smsAllowlistOnly); - tenantOptionsClientRequest.smsRegionConfig.allowlistOnly.allowedRegions = 'non-array'; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, createRequest); - }).to.throw('"SmsRegionConfig.allowlistOnly.allowedRegions" must be a valid string array.'); - }); - - it('should throw when both allowlistOnly and allowByDefault attributes are presented', () => { - const tenantOptionsClientRequest = deepCopy(clientRequest) as any; - tenantOptionsClientRequest.smsRegionConfig = { ...smsAllowByDefault, ...smsAllowlistOnly }; - expect(() => { - Tenant.buildServerRequest(tenantOptionsClientRequest, createRequest); - }).to.throw('SmsRegionConfig cannot have both "allowByDefault" and "allowlistOnly" parameters.'); - }); - const nonObjects = [null, NaN, 0, 1, true, false, '', 'a', [], [1, 'a'], _.noop]; nonObjects.forEach((request) => { it('should throw on invalid CreateTenantRequest:' + JSON.stringify(request), () => { @@ -444,11 +314,6 @@ describe('Tenant', () => { deepCopy(clientRequest.testPhoneNumbers)); }); - it('should set readonly property smsRegionConfig', () => { - expect(tenant.smsRegionConfig).to.deep.equal( - deepCopy(clientRequest.smsRegionConfig)); - }); - it('should throw when no tenant ID is provided', () => { const invalidOptions = deepCopy(serverRequest); // Use resource name that does not include a tenant ID. @@ -487,7 +352,6 @@ describe('Tenant', () => { anonymousSignInEnabled: false, multiFactorConfig: deepCopy(clientRequest.multiFactorConfig), testPhoneNumbers: deepCopy(clientRequest.testPhoneNumbers), - smsRegionConfig: deepCopy(clientRequest.smsRegionConfig), }); }); @@ -495,7 +359,6 @@ describe('Tenant', () => { const serverRequestCopyWithoutMfa: TenantServerResponse = deepCopy(serverRequest); delete serverRequestCopyWithoutMfa.mfaConfig; delete serverRequestCopyWithoutMfa.testPhoneNumbers; - delete serverRequestCopyWithoutMfa.smsRegionConfig; expect(new Tenant(serverRequestCopyWithoutMfa).toJSON()).to.deep.equal({ tenantId: 'TENANT-ID',