Skip to content

Recapcha integ test #1599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does updating a config with an undefined recaptchaConfig deletes the current config? Do we need to add a test (unit or integration) for this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. With recaptchaConfig being undefined, the current config will stay unchanged. Added integration test for updateTenants. As of project config, since it's the only config, it got covered by unit test.

};
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recaptchaConfig: null would throw a runtime error, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

};
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