|
| 1 | +import { test as base } from '@playwright/test'; |
| 2 | +import { createConfiguredDbpTest } from './fixtures'; |
| 3 | +import { createGetRecaptchaInfoAction, createSolveRecaptchaAction } from '../mocks/broker-protection/captcha.js'; |
| 4 | +import { BROKER_PROTECTION_CONFIGS } from './tests-config.js'; |
| 5 | + |
| 6 | +const test = createConfiguredDbpTest(base); |
| 7 | + |
| 8 | +test.describe('Broker Protection Captcha', () => { |
| 9 | + test.describe('recaptcha2', () => { |
| 10 | + const recaptchaTargetPage = 're-captcha.html'; |
| 11 | + const recaptchaResponseSelector = '#g-recaptcha-response'; |
| 12 | + |
| 13 | + 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 | + }); |
| 55 | + }); |
| 56 | + |
| 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 | + }); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + 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 | + }); |
| 142 | + }); |
| 143 | + |
| 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 | + }); |
| 182 | + }); |
| 183 | + }); |
| 184 | + |
| 185 | + test('remove query params from captcha url', async ({ createConfiguredDbp }) => { |
| 186 | + const dbp = await createConfiguredDbp(BROKER_PROTECTION_CONFIGS.enhancedCaptchaSystemEnabled); |
| 187 | + await dbp.navigatesTo('re-captcha.html?fname=john&lname=smith'); |
| 188 | + await dbp.receivesInlineAction(createGetRecaptchaInfoAction()); |
| 189 | + const sucessResponse = await dbp.getSuccessResponse(); |
| 190 | + |
| 191 | + dbp.isQueryParamRemoved(sucessResponse); |
| 192 | + }); |
| 193 | + }); |
| 194 | +}); |
0 commit comments