Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,179 +11,87 @@ test.describe('Broker Protection Captcha', () => {
const recaptchaResponseSelector = '#g-recaptcha-response';

test.describe('getCaptchaInfo', () => {
test.describe('with useEnhancedCaptchaSystem: "enabled"', () => {
test('returns the expected response for the correct action data', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction());
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test('returns the expected response for the correct action data without the "captchaType" field', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: undefined }));
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test('returns the expected type when the "captchaType" field does not match the detected captcha type', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'recaptchaEnterprise' }));
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test('returns an error response for an action data with an invalid "captchaType" field', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'invalid' }));

await dbp.isCaptchaError();
});
test('returns the expected response for the correct action data', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction());
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test('returns the expected response for the correct action data without the "captchaType" field', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: undefined }));
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test.describe('with useEnhancedCaptchaSystem: "disabled"', () => {
test('returns the expected response for the correct action data', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction());
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test('returns the expected response for the correct action data without the "captchaType" field', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: undefined }));
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test('returns the expected type when the "captchaType" field does not match the detected captcha type', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'recaptchaEnterprise' }));
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test('returns the expected response for an action data with an invalid "captchaType" field', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'invalid' }));
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});
test('returns the expected type when the "captchaType" field does not match the detected captcha type', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'recaptchaEnterprise' }));
const sucessResponse = await dbp.getSuccessResponse();

dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
});

test('returns an error response for an action data with an invalid "captchaType" field', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'invalid' }));

await dbp.isCaptchaError();
});
});

test.describe('solveCaptchaInfo', () => {
test.describe('with useEnhancedCaptchaSystem: "enabled"', () => {
test('solves the captcha for the correct action data', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction());
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test('solves the captcha for the correct action data without the "captchaType" field', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: undefined }));
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test('solves the captcha for an action data when the "captchaType" field does not match the detected captcha type', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'recaptchaEnterprise' }));
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test('returns an error response for an action data with an invalid "captchaType" field', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'invalid' }));

await dbp.isCaptchaError();
});
test('solves the captcha for the correct action data', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction());
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test('solves the captcha for the correct action data without the "captchaType" field', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: undefined }));
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test.describe('with useEnhancedCaptchaSystem: "disabled"', () => {
test('solves the captcha for the correct action data', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction());
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test('solves the captcha for the correct action data without the "captchaType" field', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: undefined }));
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test('solves the captcha for an action when the "captchaType" field does not match the detected captcha type', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'recaptchaEnterprise' }));
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test('solves the captcha for an action data with an invalid "captchaType" field', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'invalid' }));
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});
test('solves the captcha for an action data when the "captchaType" field does not match the detected captcha type', async ({
createConfiguredDbp,
}) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'recaptchaEnterprise' }));
dbp.getSuccessResponse();

await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
});

test('returns an error response for an action data with an invalid "captchaType" field', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo(recaptchaTargetPage);
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'invalid' }));

await dbp.isCaptchaError();
});
});

test('remove query params from captcha url', async ({ createConfiguredDbp }) => {
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo('re-captcha.html?fname=john&lname=smith');
await dbp.receivesInlineAction(createGetRecaptchaInfoAction());
const sucessResponse = await dbp.getSuccessResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,9 @@ test.describe('Broker Protection communications', () => {
});
});
test.describe('Executes action and sends success message', () => {
test('buildUrl with useEnhancedCaptchaSystem: "enabled"', async ({ page }, workerInfo) => {
test('buildUrl', async ({ page }, workerInfo) => {
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
await dbp.withFeatureConfig(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
await dbp.navigatesTo('results.html');
await dbp.receivesAction('navigate.json');
const response = await dbp.collector.waitForMessage('actionCompleted');
dbp.isSuccessMessage(response);
dbp.isUrlMatch(response[0].payload.params.result.success.response);
});

test('buildUrl with useEnhancedCaptchaSystem: "disabled"', async ({ page }, workerInfo) => {
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
await dbp.withFeatureConfig(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
await dbp.withFeatureConfig(BROKER_PROTECTION_CONFIGS.default);
await dbp.navigatesTo('results.html');
await dbp.receivesAction('navigate.json');
const response = await dbp.collector.waitForMessage('actionCompleted');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import { createFeatureConfig } from '../mocks/broker-protection/feature-config';

export const BROKER_PROTECTION_CONFIGS = Object.freeze({
enhancedCaptchaSystemEnabled: createFeatureConfig({
state: 'enabled',
settings: {
useEnhancedCaptchaSystem: 'enabled',
},
}),
enhancedCaptchaSystemDisabled: createFeatureConfig({
state: 'enabled',
settings: {
useEnhancedCaptchaSystem: 'disabled',
},
}),
default: createFeatureConfig(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @param {'enabled' | 'disabled'} [brokerProtection.state] - optional state of the broker protection feature
* @param {string[]} [brokerProtection.exceptions] - optional list of exceptions
* @param {object} [brokerProtection.settings] - optional settings
* @param {'enabled' | 'disabled'} [brokerProtection.settings.useEnhancedCaptchaSystem] - optional flag to use new action handlers
*/
export function createFeatureConfig(brokerProtection = {}) {
return {
Expand Down
3 changes: 1 addition & 2 deletions injected/src/features/broker-protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export default class BrokerProtection extends ContentFeature {
*/
async exec(action, data) {
const retryConfig = this.retryConfigFor(action);
const options = { useEnhancedCaptchaSystem: this.getFeatureSettingEnabled('useEnhancedCaptchaSystem') };
const { result, exceptions } = await retry(() => execute(action, data, document, options), retryConfig);
const { result, exceptions } = await retry(() => execute(action, data, document), retryConfig);

if (result) {
if ('success' in result && Array.isArray(result.success.next)) {
Expand Down
37 changes: 6 additions & 31 deletions injected/src/features/broker-protection/actions/actions.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
import { extract } from './extract';
import { fillForm } from './fill-form';
import { click } from './click';
import { expectation } from './expectation';
import { navigate } from './navigate';
import { buildUrl } from './build-url';
import * as captchaHandlers from '../captcha-services/captcha.service';
import * as deprecatedCaptchaHandlers from './captcha-deprecated';

/**
* Returns the captcha handlers based on the useEnhancedCaptchaSystem flag
* @param {Object} params
* @param {boolean} params.useEnhancedCaptchaSystem
*/
export function resolveActionHandlers({ useEnhancedCaptchaSystem }) {
return {
extract,
fillForm,
click,
expectation,
...(useEnhancedCaptchaSystem
? {
navigate,
...captchaHandlers,
}
: {
navigate: buildUrl,
...deprecatedCaptchaHandlers,
}),
};
}
export { extract } from './extract';
export { fillForm } from './fill-form';
export { click } from './click';
export { expectation } from './expectation';
export { navigate } from './navigate';
export { getCaptchaInfo, solveCaptcha } from '../captcha-services/captcha.service';
Loading
Loading