Skip to content

Commit 50ef232

Browse files
committed
Recapcha integ test (#1599)
* Added integ test for Project Config and Tenants update on reCAPTCHA config
1 parent c39c189 commit 50ef232

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

test/integration/auth.spec.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,56 @@ describe('admin.auth', () => {
12551255
});
12561256
});
12571257

1258+
describe('Project config management operations', () => {
1259+
before(function() {
1260+
if (authEmulatorHost) {
1261+
this.skip(); // getConfig is not supported in Auth Emulator
1262+
}
1263+
});
1264+
const projectConfigOption1: UpdateProjectConfigRequest = {
1265+
recaptchaConfig: {
1266+
emailPasswordEnforcementState: 'AUDIT',
1267+
managedRules: [{ endScore: 0.1, action: 'BLOCK' }],
1268+
},
1269+
};
1270+
const projectConfigOption2: UpdateProjectConfigRequest = {
1271+
recaptchaConfig: {
1272+
emailPasswordEnforcementState: 'OFF',
1273+
},
1274+
};
1275+
const expectedProjectConfig1: any = {
1276+
recaptchaConfig: {
1277+
emailPasswordEnforcementState: 'AUDIT',
1278+
managedRules: [{ endScore: 0.1, action: 'BLOCK' }],
1279+
},
1280+
};
1281+
const expectedProjectConfig2: any = {
1282+
recaptchaConfig: {
1283+
emailPasswordEnforcementState: 'OFF',
1284+
managedRules: [{ endScore: 0.1, action: 'BLOCK' }],
1285+
},
1286+
};
1287+
1288+
it('updateProjectConfig() should resolve with the updated project config', () => {
1289+
return getAuth().projectConfigManager().updateProjectConfig(projectConfigOption1)
1290+
.then((actualProjectConfig) => {
1291+
expect(actualProjectConfig.toJSON()).to.deep.equal(expectedProjectConfig1);
1292+
return getAuth().projectConfigManager().updateProjectConfig(projectConfigOption2);
1293+
})
1294+
.then((actualProjectConfig) => {
1295+
expect(actualProjectConfig.toJSON()).to.deep.equal(expectedProjectConfig2);
1296+
});
1297+
});
1298+
1299+
it('getProjectConfig() should resolve with expected project config', () => {
1300+
return getAuth().projectConfigManager().getProjectConfig()
1301+
.then((actualConfig) => {
1302+
const actualConfigObj = actualConfig.toJSON();
1303+
expect(actualConfigObj).to.deep.equal(expectedProjectConfig2);
1304+
});
1305+
});
1306+
});
1307+
12581308
describe('Tenant management operations', () => {
12591309
let createdTenantId: string;
12601310
const createdTenants: string[] = [];
@@ -1311,6 +1361,15 @@ describe('admin.auth', () => {
13111361
testPhoneNumbers: {
13121362
'+16505551234': '123456',
13131363
},
1364+
recaptchaConfig: {
1365+
emailPasswordEnforcementState: 'AUDIT',
1366+
managedRules: [
1367+
{
1368+
endScore: 0.3,
1369+
action: 'BLOCK',
1370+
},
1371+
],
1372+
},
13141373
};
13151374
const expectedUpdatedTenant2: any = {
13161375
displayName: 'testTenantUpdated',
@@ -1328,6 +1387,15 @@ describe('admin.auth', () => {
13281387
disallowedRegions: ['AC', 'AD'],
13291388
}
13301389
},
1390+
recaptchaConfig: {
1391+
emailPasswordEnforcementState: 'OFF',
1392+
managedRules: [
1393+
{
1394+
endScore: 0.3,
1395+
action: 'BLOCK',
1396+
},
1397+
],
1398+
},
13311399
};
13321400

13331401
// https://mochajs.org/
@@ -1740,6 +1808,7 @@ describe('admin.auth', () => {
17401808
},
17411809
multiFactorConfig: deepCopy(expectedUpdatedTenant.multiFactorConfig),
17421810
testPhoneNumbers: deepCopy(expectedUpdatedTenant.testPhoneNumbers),
1811+
recaptchaConfig: deepCopy(expectedUpdatedTenant.recaptchaConfig),
17431812
};
17441813
const updatedOptions2: UpdateTenantRequest = {
17451814
emailSignInConfig: {
@@ -1750,6 +1819,7 @@ describe('admin.auth', () => {
17501819
// Test clearing of phone numbers.
17511820
testPhoneNumbers: null,
17521821
smsRegionConfig: deepCopy(expectedUpdatedTenant2.smsRegionConfig),
1822+
recaptchaConfig: deepCopy(expectedUpdatedTenant2.recaptchaConfig),
17531823
};
17541824
if (authEmulatorHost) {
17551825
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions)
@@ -1801,6 +1871,28 @@ describe('admin.auth', () => {
18011871
});
18021872
});
18031873

1874+
it('updateTenant() should not update tenant reCAPTCHA config is undefined', () => {
1875+
expectedUpdatedTenant.tenantId = createdTenantId;
1876+
const updatedOptions2: UpdateTenantRequest = {
1877+
displayName: expectedUpdatedTenant2.displayName,
1878+
recaptchaConfig: undefined,
1879+
};
1880+
if (authEmulatorHost) {
1881+
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2)
1882+
.then((actualTenant) => {
1883+
const actualTenantObj = actualTenant.toJSON();
1884+
// Not supported in Auth Emulator
1885+
delete (actualTenantObj as { testPhoneNumbers?: Record<string, string> }).testPhoneNumbers;
1886+
delete expectedUpdatedTenant2.testPhoneNumbers;
1887+
expect(actualTenantObj).to.deep.equal(expectedUpdatedTenant2);
1888+
});
1889+
}
1890+
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2)
1891+
.then((actualTenant) => {
1892+
expect(actualTenant.toJSON()).to.deep.equal(expectedUpdatedTenant2);
1893+
});
1894+
});
1895+
18041896
it('updateTenant() should be able to enable/disable anon provider', async () => {
18051897
const tenantManager = getAuth().tenantManager();
18061898
let tenant = await tenantManager.createTenant({

0 commit comments

Comments
 (0)