Skip to content

Commit 140fe18

Browse files
committed
Recapcha integ test (#1599)
* Added integ test for Project Config and Tenants update on reCAPTCHA config
1 parent 8f1f2ea commit 140fe18

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
@@ -1298,6 +1298,56 @@ describe('admin.auth', () => {
12981298
});
12991299
});
13001300

1301+
describe('Project config management operations', () => {
1302+
before(function() {
1303+
if (authEmulatorHost) {
1304+
this.skip(); // getConfig is not supported in Auth Emulator
1305+
}
1306+
});
1307+
const projectConfigOption1: UpdateProjectConfigRequest = {
1308+
recaptchaConfig: {
1309+
emailPasswordEnforcementState: 'AUDIT',
1310+
managedRules: [{ endScore: 0.1, action: 'BLOCK' }],
1311+
},
1312+
};
1313+
const projectConfigOption2: UpdateProjectConfigRequest = {
1314+
recaptchaConfig: {
1315+
emailPasswordEnforcementState: 'OFF',
1316+
},
1317+
};
1318+
const expectedProjectConfig1: any = {
1319+
recaptchaConfig: {
1320+
emailPasswordEnforcementState: 'AUDIT',
1321+
managedRules: [{ endScore: 0.1, action: 'BLOCK' }],
1322+
},
1323+
};
1324+
const expectedProjectConfig2: any = {
1325+
recaptchaConfig: {
1326+
emailPasswordEnforcementState: 'OFF',
1327+
managedRules: [{ endScore: 0.1, action: 'BLOCK' }],
1328+
},
1329+
};
1330+
1331+
it('updateProjectConfig() should resolve with the updated project config', () => {
1332+
return getAuth().projectConfigManager().updateProjectConfig(projectConfigOption1)
1333+
.then((actualProjectConfig) => {
1334+
expect(actualProjectConfig.toJSON()).to.deep.equal(expectedProjectConfig1);
1335+
return getAuth().projectConfigManager().updateProjectConfig(projectConfigOption2);
1336+
})
1337+
.then((actualProjectConfig) => {
1338+
expect(actualProjectConfig.toJSON()).to.deep.equal(expectedProjectConfig2);
1339+
});
1340+
});
1341+
1342+
it('getProjectConfig() should resolve with expected project config', () => {
1343+
return getAuth().projectConfigManager().getProjectConfig()
1344+
.then((actualConfig) => {
1345+
const actualConfigObj = actualConfig.toJSON();
1346+
expect(actualConfigObj).to.deep.equal(expectedProjectConfig2);
1347+
});
1348+
});
1349+
});
1350+
13011351
describe('Tenant management operations', () => {
13021352
let createdTenantId: string;
13031353
const createdTenants: string[] = [];
@@ -1378,6 +1428,15 @@ describe('admin.auth', () => {
13781428
testPhoneNumbers: {
13791429
'+16505551234': '123456',
13801430
},
1431+
recaptchaConfig: {
1432+
emailPasswordEnforcementState: 'AUDIT',
1433+
managedRules: [
1434+
{
1435+
endScore: 0.3,
1436+
action: 'BLOCK',
1437+
},
1438+
],
1439+
},
13811440
};
13821441
const expectedUpdatedTenant2: any = {
13831442
displayName: 'testTenantUpdated',
@@ -1424,6 +1483,15 @@ describe('admin.auth', () => {
14241483
disallowedRegions: ['AC', 'AD'],
14251484
}
14261485
},
1486+
recaptchaConfig: {
1487+
emailPasswordEnforcementState: 'OFF',
1488+
managedRules: [
1489+
{
1490+
endScore: 0.3,
1491+
action: 'BLOCK',
1492+
},
1493+
],
1494+
},
14271495
};
14281496

14291497
// https://mochajs.org/
@@ -1836,6 +1904,7 @@ describe('admin.auth', () => {
18361904
},
18371905
multiFactorConfig: deepCopy(expectedUpdatedTenant.multiFactorConfig),
18381906
testPhoneNumbers: deepCopy(expectedUpdatedTenant.testPhoneNumbers),
1907+
recaptchaConfig: deepCopy(expectedUpdatedTenant.recaptchaConfig),
18391908
};
18401909
const updatedOptions2: UpdateTenantRequest = {
18411910
emailSignInConfig: {
@@ -1846,6 +1915,7 @@ describe('admin.auth', () => {
18461915
// Test clearing of phone numbers.
18471916
testPhoneNumbers: null,
18481917
smsRegionConfig: deepCopy(expectedUpdatedTenant2.smsRegionConfig),
1918+
recaptchaConfig: deepCopy(expectedUpdatedTenant2.recaptchaConfig),
18491919
};
18501920
if (authEmulatorHost) {
18511921
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions)
@@ -1914,11 +1984,31 @@ describe('admin.auth', () => {
19141984
});
19151985
}
19161986
return getAuth().tenantManager().updateTenant(createdTenantId, updateRequestNoMfaConfig)
1987+
});
1988+
1989+
it('updateTenant() should not update tenant reCAPTCHA config is undefined', () => {
1990+
expectedUpdatedTenant.tenantId = createdTenantId;
1991+
const updatedOptions2: UpdateTenantRequest = {
1992+
displayName: expectedUpdatedTenant2.displayName,
1993+
recaptchaConfig: undefined,
1994+
};
1995+
if (authEmulatorHost) {
1996+
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2)
1997+
.then((actualTenant) => {
1998+
const actualTenantObj = actualTenant.toJSON();
1999+
// Not supported in Auth Emulator
2000+
delete (actualTenantObj as { testPhoneNumbers?: Record<string, string> }).testPhoneNumbers;
2001+
delete expectedUpdatedTenant2.testPhoneNumbers;
2002+
expect(actualTenantObj).to.deep.equal(expectedUpdatedTenant2);
2003+
});
2004+
}
2005+
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2)
19172006
.then((actualTenant) => {
19182007
expect(actualTenant.toJSON()).to.deep.equal(expectedUpdatedTenant2);
19192008
});
19202009
});
19212010

2011+
<<<<<<< HEAD
19222012
it('updateTenant() should not disable SMS MFA when TOTP is disabled', () => {
19232013
expectedUpdatedTenantSmsEnabledTotpDisabled.tenantId = createdTenantId;
19242014
const updateRequestSMSEnabledTOTPDisabled: UpdateTenantRequest = {
@@ -1950,6 +2040,8 @@ describe('admin.auth', () => {
19502040
});
19512041
});
19522042

2043+
=======
2044+
>>>>>>> 50ef232 (Recapcha integ test (#1599))
19532045
it('updateTenant() should be able to enable/disable anon provider', async () => {
19542046
const tenantManager = getAuth().tenantManager();
19552047
let tenant = await tenantManager.createTenant({

0 commit comments

Comments
 (0)