Skip to content

Commit

Permalink
Recapcha integ test (#1599)
Browse files Browse the repository at this point in the history
* Added integ test for Project Config and Tenants update on reCAPTCHA config
  • Loading branch information
Xiaoshouzi-gh committed Mar 9, 2022
1 parent c01f7fb commit 13810eb
Showing 1 changed file with 93 additions and 1 deletion.
94 changes: 93 additions & 1 deletion test/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1154,6 +1154,56 @@ describe('admin.auth', () => {
});
});

describe('Project config management operations', () => {
before(function() {
if (authEmulatorHost) {
this.skip(); // getConfig is not supported in Auth Emulator
}
});
const projectConfigOption1: UpdateProjectConfigRequest = {
recaptchaConfig: {
emailPasswordEnforcementState: 'AUDIT',
managedRules: [{ endScore: 0.1, action: 'BLOCK' }],
},
};
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(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[] = [];
Expand Down Expand Up @@ -1210,6 +1260,15 @@ describe('admin.auth', () => {
testPhoneNumbers: {
'+16505551234': '123456',
},
recaptchaConfig: {
emailPasswordEnforcementState: 'AUDIT',
managedRules: [
{
endScore: 0.3,
action: 'BLOCK',
},
],
},
};
const expectedUpdatedTenant2: any = {
displayName: 'testTenantUpdated',
Expand All @@ -1222,6 +1281,15 @@ describe('admin.auth', () => {
state: 'ENABLED',
factorIds: ['phone'],
},
recaptchaConfig: {
emailPasswordEnforcementState: 'OFF',
managedRules: [
{
endScore: 0.3,
action: 'BLOCK',
},
],
},
};

// https://mochajs.org/
Expand Down Expand Up @@ -1634,6 +1702,7 @@ describe('admin.auth', () => {
},
multiFactorConfig: deepCopy(expectedUpdatedTenant.multiFactorConfig),
testPhoneNumbers: deepCopy(expectedUpdatedTenant.testPhoneNumbers),
recaptchaConfig: deepCopy(expectedUpdatedTenant.recaptchaConfig),
};
const updatedOptions2: UpdateTenantRequest = {
emailSignInConfig: {
Expand All @@ -1643,6 +1712,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)
Expand Down Expand Up @@ -1672,6 +1742,28 @@ describe('admin.auth', () => {
});
});

it('updateTenant() should not update tenant reCAPTCHA config is undefined', () => {
expectedUpdatedTenant.tenantId = createdTenantId;
const updatedOptions2: UpdateTenantRequest = {
displayName: expectedUpdatedTenant2.displayName,
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<string, string>}).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({
Expand Down

0 comments on commit 13810eb

Please sign in to comment.