From 6d6fa5c3c7df1548c78cd76dece9a4200acd806b Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 2 Apr 2025 17:58:34 +0200 Subject: [PATCH] feat(pir): deprecate useEnhancedCaptchaSystem setting --- .../broker-protection-captcha.spec.js | 230 ++++++------------ .../broker-protection.spec.js | 14 +- .../broker-protection-tests/tests-config.js | 13 +- .../mocks/broker-protection/feature-config.js | 1 - injected/src/features/broker-protection.js | 3 +- .../broker-protection/actions/actions.js | 37 +-- .../src/features/broker-protection/execute.js | 11 +- 7 files changed, 81 insertions(+), 228 deletions(-) diff --git a/injected/integration-test/broker-protection-tests/broker-protection-captcha.spec.js b/injected/integration-test/broker-protection-tests/broker-protection-captcha.spec.js index d8f4cb6190..ecd47eca67 100644 --- a/injected/integration-test/broker-protection-tests/broker-protection-captcha.spec.js +++ b/injected/integration-test/broker-protection-tests/broker-protection-captcha.spec.js @@ -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(); diff --git a/injected/integration-test/broker-protection-tests/broker-protection.spec.js b/injected/integration-test/broker-protection-tests/broker-protection.spec.js index bc6b54b14f..f83d213fa6 100644 --- a/injected/integration-test/broker-protection-tests/broker-protection.spec.js +++ b/injected/integration-test/broker-protection-tests/broker-protection.spec.js @@ -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'); diff --git a/injected/integration-test/broker-protection-tests/tests-config.js b/injected/integration-test/broker-protection-tests/tests-config.js index 44d2d4c0fa..c026e57b47 100644 --- a/injected/integration-test/broker-protection-tests/tests-config.js +++ b/injected/integration-test/broker-protection-tests/tests-config.js @@ -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(), }); diff --git a/injected/integration-test/mocks/broker-protection/feature-config.js b/injected/integration-test/mocks/broker-protection/feature-config.js index f11e5a6f51..d142c46f6d 100644 --- a/injected/integration-test/mocks/broker-protection/feature-config.js +++ b/injected/integration-test/mocks/broker-protection/feature-config.js @@ -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 { diff --git a/injected/src/features/broker-protection.js b/injected/src/features/broker-protection.js index ba70818e45..ba13474572 100644 --- a/injected/src/features/broker-protection.js +++ b/injected/src/features/broker-protection.js @@ -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)) { diff --git a/injected/src/features/broker-protection/actions/actions.js b/injected/src/features/broker-protection/actions/actions.js index b3620bd208..8d7ef88301 100644 --- a/injected/src/features/broker-protection/actions/actions.js +++ b/injected/src/features/broker-protection/actions/actions.js @@ -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'; diff --git a/injected/src/features/broker-protection/execute.js b/injected/src/features/broker-protection/execute.js index ba9b96dbcd..9588aa7f83 100644 --- a/injected/src/features/broker-protection/execute.js +++ b/injected/src/features/broker-protection/execute.js @@ -1,21 +1,14 @@ -import { resolveActionHandlers } from './actions/actions'; +import { navigate, extract, click, expectation, fillForm, getCaptchaInfo, solveCaptcha } from './actions/actions'; import { ErrorResponse } from './types'; /** * @param {import('./types.js').PirAction} action * @param {Record} inputData * @param {Document} [root] - optional root element - * @param {Object} [options] - optional options - * @param {boolean} [options.useEnhancedCaptchaSystem] - optional flag to use new action handlers * @return {Promise} */ -export async function execute(action, inputData, root = document, options = {}) { +export async function execute(action, inputData, root = document) { try { - const { useEnhancedCaptchaSystem = false } = options; - const { navigate, extract, click, expectation, fillForm, getCaptchaInfo, solveCaptcha } = resolveActionHandlers({ - useEnhancedCaptchaSystem, - }); - switch (action.actionType) { case 'navigate': return navigate(action, data(action, inputData, 'userProfile'));