From d593c528fa197111853e45fc26e9df319a7905a1 Mon Sep 17 00:00:00 2001 From: Liubin Jiang Date: Tue, 8 Mar 2022 14:57:05 -0800 Subject: [PATCH 1/4] Add integ test for project config and tenants update on recaptcha config --- test/integration/auth.spec.ts | 67 ++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index 2308ca6879..959d0b117c 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, + UserImportRecord, UserRecord, getAuth, UpdateProjectConfigRequest, } from '../../lib/auth/index'; const chalk = require('chalk'); // eslint-disable-line @typescript-eslint/no-var-requires @@ -1154,6 +1154,55 @@ describe('admin.auth', () => { }); }); + describe('Project config management operations', () => { + before(function() { + if (authEmulatorHost) { + this.skip(); // getConfig is not supported in Auth Emulator + } + }); + const projectOption1: UpdateProjectConfigRequest = { + recaptchaConfig: { + emailPasswordEnforcementState: 'AUDIT', + managedRules: [{endScore: 0.1, action: 'BLOCK'}], + } + } + const projectOption2: UpdateProjectConfigRequest = { + recaptchaConfig: { + emailPasswordEnforcementState: 'OFF', + } + } + const expectedProjectConfig1: any = { + recaptchaConfig: { + emailPasswordEnforcementState: 'AUDIT', + managedRules: [{endScore: 0.1, action: 'BLOCK'}], + } + } + const expectedProjectConfig2: any = { + recaptchaConfig: { + emailPasswordEnforcementState: 'OFF', + managedRules: [{endScore: 0.1, action: 'BLOCK'}], + } + } + it('updateProjectConfig() should resolve with the updated project config', () => { + return getAuth().projectConfigManager().updateProjectConfig(projectOption1) + .then((actualProjectConfig) => { + expect(actualProjectConfig.toJSON()).to.deep.equal(expectedProjectConfig1); + return getAuth().projectConfigManager().updateProjectConfig(projectOption2); + }) + .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[] = []; @@ -1210,6 +1259,13 @@ describe('admin.auth', () => { testPhoneNumbers: { '+16505551234': '123456', }, + recaptchaConfig: { + emailPasswordEnforcementState: 'AUDIT', + managedRules: [{ + endScore: 0.3, + action: 'BLOCK' + }] + } }; const expectedUpdatedTenant2: any = { displayName: 'testTenantUpdated', @@ -1222,6 +1278,13 @@ describe('admin.auth', () => { state: 'ENABLED', factorIds: ['phone'], }, + recaptchaConfig: { + emailPasswordEnforcementState: 'OFF', + managedRules: [{ + endScore: 0.3, + action: 'BLOCK' + }] + } }; // https://mochajs.org/ @@ -1634,6 +1697,7 @@ describe('admin.auth', () => { }, multiFactorConfig: deepCopy(expectedUpdatedTenant.multiFactorConfig), testPhoneNumbers: deepCopy(expectedUpdatedTenant.testPhoneNumbers), + recaptchaConfig: deepCopy(expectedUpdatedTenant.recaptchaConfig), }; const updatedOptions2: UpdateTenantRequest = { emailSignInConfig: { @@ -1643,6 +1707,7 @@ describe('admin.auth', () => { multiFactorConfig: deepCopy(expectedUpdatedTenant2.multiFactorConfig), // Test clearing of phone numbers. testPhoneNumbers: null, + recaptchaConfig: deepCopy(expectedUpdatedTenant2.recaptchaConfig), }; if (authEmulatorHost) { return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions) From 0faf91343f01755b6a71f621b45feba5657538c8 Mon Sep 17 00:00:00 2001 From: Liubin Jiang Date: Tue, 8 Mar 2022 16:30:46 -0800 Subject: [PATCH 2/4] fix lint --- test/integration/auth.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index 959d0b117c..bd1c639151 100644 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -1163,7 +1163,7 @@ describe('admin.auth', () => { const projectOption1: UpdateProjectConfigRequest = { recaptchaConfig: { emailPasswordEnforcementState: 'AUDIT', - managedRules: [{endScore: 0.1, action: 'BLOCK'}], + managedRules: [{ endScore: 0.1, action: 'BLOCK' }], } } const projectOption2: UpdateProjectConfigRequest = { @@ -1174,13 +1174,13 @@ describe('admin.auth', () => { const expectedProjectConfig1: any = { recaptchaConfig: { emailPasswordEnforcementState: 'AUDIT', - managedRules: [{endScore: 0.1, action: 'BLOCK'}], + managedRules: [{ endScore: 0.1, action: 'BLOCK' }], } } const expectedProjectConfig2: any = { recaptchaConfig: { emailPasswordEnforcementState: 'OFF', - managedRules: [{endScore: 0.1, action: 'BLOCK'}], + managedRules: [{ endScore: 0.1, action: 'BLOCK' }], } } it('updateProjectConfig() should resolve with the updated project config', () => { From 9cab7f9c59084b1426ac0025fcb77314c6c5c0b2 Mon Sep 17 00:00:00 2001 From: Liubin Jiang Date: Wed, 9 Mar 2022 14:02:43 -0800 Subject: [PATCH 3/4] add undefined recaptcha config test for update tenants, and address PR feedbacks. --- test/integration/auth.spec.ts | 79 +++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index bd1c639151..e8ecb98b85 100644 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -1160,39 +1160,41 @@ describe('admin.auth', () => { this.skip(); // getConfig is not supported in Auth Emulator } }); - const projectOption1: UpdateProjectConfigRequest = { + const projectConfigOption1: UpdateProjectConfigRequest = { recaptchaConfig: { emailPasswordEnforcementState: 'AUDIT', managedRules: [{ endScore: 0.1, action: 'BLOCK' }], - } - } - const projectOption2: UpdateProjectConfigRequest = { + }, + }; + const projectConfigOption2: UpdateProjectConfigRequest = { recaptchaConfig: { emailPasswordEnforcementState: 'OFF', - } - } + }, + }; const expectedProjectConfig1: any = { recaptchaConfig: { emailPasswordEnforcementState: 'AUDIT', managedRules: [{ endScore: 0.1, action: 'BLOCK' }], - } - } + }, + }; const expectedProjectConfig2: any = { recaptchaConfig: { emailPasswordEnforcementState: 'OFF', managedRules: [{ endScore: 0.1, action: 'BLOCK' }], - } - } + }, + }; + it('updateProjectConfig() should resolve with the updated project config', () => { - return getAuth().projectConfigManager().updateProjectConfig(projectOption1) + return getAuth().projectConfigManager().updateProjectConfig(projectConfigOption1) .then((actualProjectConfig) => { expect(actualProjectConfig.toJSON()).to.deep.equal(expectedProjectConfig1); - return getAuth().projectConfigManager().updateProjectConfig(projectOption2); + 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) => { @@ -1200,7 +1202,6 @@ describe('admin.auth', () => { expect(actualConfigObj).to.deep.equal(expectedProjectConfig2); }); }); - }); describe('Tenant management operations', () => { @@ -1261,11 +1262,13 @@ describe('admin.auth', () => { }, recaptchaConfig: { emailPasswordEnforcementState: 'AUDIT', - managedRules: [{ - endScore: 0.3, - action: 'BLOCK' - }] - } + managedRules: [ + { + endScore: 0.3, + action: 'BLOCK', + }, + ], + }, }; const expectedUpdatedTenant2: any = { displayName: 'testTenantUpdated', @@ -1280,11 +1283,13 @@ describe('admin.auth', () => { }, recaptchaConfig: { emailPasswordEnforcementState: 'OFF', - managedRules: [{ - endScore: 0.3, - action: 'BLOCK' - }] - } + managedRules: [ + { + endScore: 0.3, + action: 'BLOCK', + }, + ], + }, }; // https://mochajs.org/ @@ -1737,6 +1742,34 @@ describe('admin.auth', () => { }); }); + it('updateTenant() should not update tenant reCAPTCHA config is undefined', () => { + expectedUpdatedTenant.tenantId = createdTenantId; + const updatedOptions2: UpdateTenantRequest = { + emailSignInConfig: { + enabled: true, + passwordRequired: false, + }, + multiFactorConfig: deepCopy(expectedUpdatedTenant2.multiFactorConfig), + // Test clearing of phone numbers. + testPhoneNumbers: null, + recaptchaConfig: 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({ From 87faf5f0ea09284415747f2d76cba41b0c6379e8 Mon Sep 17 00:00:00 2001 From: Liubin Jiang Date: Wed, 9 Mar 2022 15:33:23 -0800 Subject: [PATCH 4/4] address pr feedback --- test/integration/auth.spec.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index e8ecb98b85..cf9444d9bb 100644 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -1745,13 +1745,7 @@ describe('admin.auth', () => { it('updateTenant() should not update tenant reCAPTCHA config is undefined', () => { expectedUpdatedTenant.tenantId = createdTenantId; const updatedOptions2: UpdateTenantRequest = { - emailSignInConfig: { - enabled: true, - passwordRequired: false, - }, - multiFactorConfig: deepCopy(expectedUpdatedTenant2.multiFactorConfig), - // Test clearing of phone numbers. - testPhoneNumbers: null, + displayName: expectedUpdatedTenant2.displayName, recaptchaConfig: undefined, }; if (authEmulatorHost) {