Skip to content

Commit 719673e

Browse files
authored
feat(pir): deprecate useEnhancedCaptchaSystem setting (#1608)
1 parent f8c5a43 commit 719673e

File tree

7 files changed

+81
-228
lines changed

7 files changed

+81
-228
lines changed

injected/integration-test/broker-protection-tests/broker-protection-captcha.spec.js

Lines changed: 69 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -11,179 +11,87 @@ test.describe('Broker Protection Captcha', () => {
1111
const recaptchaResponseSelector = '#g-recaptcha-response';
1212

1313
test.describe('getCaptchaInfo', () => {
14-
test.describe('with useEnhancedCaptchaSystem: "enabled"', () => {
15-
test('returns the expected response for the correct action data', async ({ createConfiguredDbp }) => {
16-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
17-
await dbp.navigatesTo(recaptchaTargetPage);
18-
await dbp.receivesInlineAction(createGetRecaptchaInfoAction());
19-
const sucessResponse = await dbp.getSuccessResponse();
20-
21-
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
22-
});
23-
24-
test('returns the expected response for the correct action data without the "captchaType" field', async ({
25-
createConfiguredDbp,
26-
}) => {
27-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
28-
await dbp.navigatesTo(recaptchaTargetPage);
29-
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: undefined }));
30-
const sucessResponse = await dbp.getSuccessResponse();
31-
32-
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
33-
});
34-
35-
test('returns the expected type when the "captchaType" field does not match the detected captcha type', async ({
36-
createConfiguredDbp,
37-
}) => {
38-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
39-
await dbp.navigatesTo(recaptchaTargetPage);
40-
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'recaptchaEnterprise' }));
41-
const sucessResponse = await dbp.getSuccessResponse();
42-
43-
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
44-
});
45-
46-
test('returns an error response for an action data with an invalid "captchaType" field', async ({
47-
createConfiguredDbp,
48-
}) => {
49-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
50-
await dbp.navigatesTo(recaptchaTargetPage);
51-
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'invalid' }));
52-
53-
await dbp.isCaptchaError();
54-
});
14+
test('returns the expected response for the correct action data', async ({ createConfiguredDbp }) => {
15+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
16+
await dbp.navigatesTo(recaptchaTargetPage);
17+
await dbp.receivesInlineAction(createGetRecaptchaInfoAction());
18+
const sucessResponse = await dbp.getSuccessResponse();
19+
20+
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
21+
});
22+
23+
test('returns the expected response for the correct action data without the "captchaType" field', async ({
24+
createConfiguredDbp,
25+
}) => {
26+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
27+
await dbp.navigatesTo(recaptchaTargetPage);
28+
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: undefined }));
29+
const sucessResponse = await dbp.getSuccessResponse();
30+
31+
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
5532
});
5633

57-
test.describe('with useEnhancedCaptchaSystem: "disabled"', () => {
58-
test('returns the expected response for the correct action data', async ({ createConfiguredDbp }) => {
59-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
60-
await dbp.navigatesTo(recaptchaTargetPage);
61-
await dbp.receivesInlineAction(createGetRecaptchaInfoAction());
62-
const sucessResponse = await dbp.getSuccessResponse();
63-
64-
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
65-
});
66-
67-
test('returns the expected response for the correct action data without the "captchaType" field', async ({
68-
createConfiguredDbp,
69-
}) => {
70-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
71-
await dbp.navigatesTo(recaptchaTargetPage);
72-
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: undefined }));
73-
const sucessResponse = await dbp.getSuccessResponse();
74-
75-
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
76-
});
77-
78-
test('returns the expected type when the "captchaType" field does not match the detected captcha type', async ({
79-
createConfiguredDbp,
80-
}) => {
81-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
82-
await dbp.navigatesTo(recaptchaTargetPage);
83-
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'recaptchaEnterprise' }));
84-
const sucessResponse = await dbp.getSuccessResponse();
85-
86-
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
87-
});
88-
89-
test('returns the expected response for an action data with an invalid "captchaType" field', async ({
90-
createConfiguredDbp,
91-
}) => {
92-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
93-
await dbp.navigatesTo(recaptchaTargetPage);
94-
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'invalid' }));
95-
const sucessResponse = await dbp.getSuccessResponse();
96-
97-
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
98-
});
34+
test('returns the expected type when the "captchaType" field does not match the detected captcha type', async ({
35+
createConfiguredDbp,
36+
}) => {
37+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
38+
await dbp.navigatesTo(recaptchaTargetPage);
39+
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'recaptchaEnterprise' }));
40+
const sucessResponse = await dbp.getSuccessResponse();
41+
42+
dbp.isCaptchaMatch(sucessResponse, { captchaType: 'recaptcha2', targetPage: recaptchaTargetPage });
43+
});
44+
45+
test('returns an error response for an action data with an invalid "captchaType" field', async ({ createConfiguredDbp }) => {
46+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
47+
await dbp.navigatesTo(recaptchaTargetPage);
48+
await dbp.receivesInlineAction(createGetRecaptchaInfoAction({ captchaType: 'invalid' }));
49+
50+
await dbp.isCaptchaError();
9951
});
10052
});
10153

10254
test.describe('solveCaptchaInfo', () => {
103-
test.describe('with useEnhancedCaptchaSystem: "enabled"', () => {
104-
test('solves the captcha for the correct action data', async ({ createConfiguredDbp }) => {
105-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
106-
await dbp.navigatesTo(recaptchaTargetPage);
107-
await dbp.receivesInlineAction(createSolveRecaptchaAction());
108-
dbp.getSuccessResponse();
109-
110-
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
111-
});
112-
113-
test('solves the captcha for the correct action data without the "captchaType" field', async ({ createConfiguredDbp }) => {
114-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
115-
await dbp.navigatesTo(recaptchaTargetPage);
116-
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: undefined }));
117-
dbp.getSuccessResponse();
118-
119-
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
120-
});
121-
122-
test('solves the captcha for an action data when the "captchaType" field does not match the detected captcha type', async ({
123-
createConfiguredDbp,
124-
}) => {
125-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
126-
await dbp.navigatesTo(recaptchaTargetPage);
127-
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'recaptchaEnterprise' }));
128-
dbp.getSuccessResponse();
129-
130-
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
131-
});
132-
133-
test('returns an error response for an action data with an invalid "captchaType" field', async ({
134-
createConfiguredDbp,
135-
}) => {
136-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
137-
await dbp.navigatesTo(recaptchaTargetPage);
138-
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'invalid' }));
139-
140-
await dbp.isCaptchaError();
141-
});
55+
test('solves the captcha for the correct action data', async ({ createConfiguredDbp }) => {
56+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
57+
await dbp.navigatesTo(recaptchaTargetPage);
58+
await dbp.receivesInlineAction(createSolveRecaptchaAction());
59+
dbp.getSuccessResponse();
60+
61+
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
62+
});
63+
64+
test('solves the captcha for the correct action data without the "captchaType" field', async ({ createConfiguredDbp }) => {
65+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
66+
await dbp.navigatesTo(recaptchaTargetPage);
67+
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: undefined }));
68+
dbp.getSuccessResponse();
69+
70+
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
14271
});
14372

144-
test.describe('with useEnhancedCaptchaSystem: "disabled"', () => {
145-
test('solves the captcha for the correct action data', async ({ createConfiguredDbp }) => {
146-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
147-
await dbp.navigatesTo(recaptchaTargetPage);
148-
await dbp.receivesInlineAction(createSolveRecaptchaAction());
149-
dbp.getSuccessResponse();
150-
151-
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
152-
});
153-
154-
test('solves the captcha for the correct action data without the "captchaType" field', async ({ createConfiguredDbp }) => {
155-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
156-
await dbp.navigatesTo(recaptchaTargetPage);
157-
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: undefined }));
158-
dbp.getSuccessResponse();
159-
160-
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
161-
});
162-
163-
test('solves the captcha for an action when the "captchaType" field does not match the detected captcha type', async ({
164-
createConfiguredDbp,
165-
}) => {
166-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
167-
await dbp.navigatesTo(recaptchaTargetPage);
168-
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'recaptchaEnterprise' }));
169-
dbp.getSuccessResponse();
170-
171-
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
172-
});
173-
174-
test('solves the captcha for an action data with an invalid "captchaType" field', async ({ createConfiguredDbp }) => {
175-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
176-
await dbp.navigatesTo(recaptchaTargetPage);
177-
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'invalid' }));
178-
dbp.getSuccessResponse();
179-
180-
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
181-
});
73+
test('solves the captcha for an action data when the "captchaType" field does not match the detected captcha type', async ({
74+
createConfiguredDbp,
75+
}) => {
76+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
77+
await dbp.navigatesTo(recaptchaTargetPage);
78+
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'recaptchaEnterprise' }));
79+
dbp.getSuccessResponse();
80+
81+
await dbp.isCaptchaTokenFilled(recaptchaResponseSelector);
82+
});
83+
84+
test('returns an error response for an action data with an invalid "captchaType" field', async ({ createConfiguredDbp }) => {
85+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
86+
await dbp.navigatesTo(recaptchaTargetPage);
87+
await dbp.receivesInlineAction(createSolveRecaptchaAction({ captchaType: 'invalid' }));
88+
89+
await dbp.isCaptchaError();
18290
});
18391
});
18492

18593
test('remove query params from captcha url', async ({ createConfiguredDbp }) => {
186-
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
94+
const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.default);
18795
await dbp.navigatesTo('re-captcha.html?fname=john&lname=smith');
18896
await dbp.receivesInlineAction(createGetRecaptchaInfoAction());
18997
const sucessResponse = await dbp.getSuccessResponse();

injected/integration-test/broker-protection-tests/broker-protection.spec.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,9 @@ test.describe('Broker Protection communications', () => {
334334
});
335335
});
336336
test.describe('Executes action and sends success message', () => {
337-
test('buildUrl with useEnhancedCaptchaSystem: "enabled"', async ({ page }, workerInfo) => {
337+
test('buildUrl', async ({ page }, workerInfo) => {
338338
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
339-
await dbp.withFeatureConfig(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled);
340-
await dbp.navigatesTo('results.html');
341-
await dbp.receivesAction('navigate.json');
342-
const response = await dbp.collector.waitForMessage('actionCompleted');
343-
dbp.isSuccessMessage(response);
344-
dbp.isUrlMatch(response[0].payload.params.result.success.response);
345-
});
346-
347-
test('buildUrl with useEnhancedCaptchaSystem: "disabled"', async ({ page }, workerInfo) => {
348-
const dbp = BrokerProtectionPage.create(page, workerInfo.project.use);
349-
await dbp.withFeatureConfig(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemDisabled);
339+
await dbp.withFeatureConfig(BROKER_PROTECTION_CONFIGS.default);
350340
await dbp.navigatesTo('results.html');
351341
await dbp.receivesAction('navigate.json');
352342
const response = await dbp.collector.waitForMessage('actionCompleted');
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
import { createFeatureConfig } from '../mocks/broker-protection/feature-config';
22

33
export const BROKER_PROTECTION_CONFIGS = Object.freeze({
4-
enhancedCaptchaSystemEnabled: createFeatureConfig({
5-
state: 'enabled',
6-
settings: {
7-
useEnhancedCaptchaSystem: 'enabled',
8-
},
9-
}),
10-
enhancedCaptchaSystemDisabled: createFeatureConfig({
11-
state: 'enabled',
12-
settings: {
13-
useEnhancedCaptchaSystem: 'disabled',
14-
},
15-
}),
4+
default: createFeatureConfig(),
165
});

injected/integration-test/mocks/broker-protection/feature-config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @param {'enabled' | 'disabled'} [brokerProtection.state] - optional state of the broker protection feature
44
* @param {string[]} [brokerProtection.exceptions] - optional list of exceptions
55
* @param {object} [brokerProtection.settings] - optional settings
6-
* @param {'enabled' | 'disabled'} [brokerProtection.settings.useEnhancedCaptchaSystem] - optional flag to use new action handlers
76
*/
87
export function createFeatureConfig(brokerProtection = {}) {
98
return {

injected/src/features/broker-protection.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ export default class BrokerProtection extends ContentFeature {
5858
*/
5959
async exec(action, data) {
6060
const retryConfig = this.retryConfigFor(action);
61-
const options = { useEnhancedCaptchaSystem: this.getFeatureSettingEnabled('useEnhancedCaptchaSystem') };
62-
const { result, exceptions } = await retry(() => execute(action, data, document, options), retryConfig);
61+
const { result, exceptions } = await retry(() => execute(action, data, document), retryConfig);
6362

6463
if (result) {
6564
if ('success' in result && Array.isArray(result.success.next)) {
Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
1-
import { extract } from './extract';
2-
import { fillForm } from './fill-form';
3-
import { click } from './click';
4-
import { expectation } from './expectation';
5-
import { navigate } from './navigate';
6-
import { buildUrl } from './build-url';
7-
import * as captchaHandlers from '../captcha-services/captcha.service';
8-
import * as deprecatedCaptchaHandlers from './captcha-deprecated';
9-
10-
/**
11-
* Returns the captcha handlers based on the useEnhancedCaptchaSystem flag
12-
* @param {Object} params
13-
* @param {boolean} params.useEnhancedCaptchaSystem
14-
*/
15-
export function resolveActionHandlers({ useEnhancedCaptchaSystem }) {
16-
return {
17-
extract,
18-
fillForm,
19-
click,
20-
expectation,
21-
...(useEnhancedCaptchaSystem
22-
? {
23-
navigate,
24-
...captchaHandlers,
25-
}
26-
: {
27-
navigate: buildUrl,
28-
...deprecatedCaptchaHandlers,
29-
}),
30-
};
31-
}
1+
export { extract } from './extract';
2+
export { fillForm } from './fill-form';
3+
export { click } from './click';
4+
export { expectation } from './expectation';
5+
export { navigate } from './navigate';
6+
export { getCaptchaInfo, solveCaptcha } from '../captcha-services/captcha.service';

0 commit comments

Comments
 (0)