@@ -17,9 +17,12 @@ import { BaseTarget } from '../targets/base';
1717import { TestAccountTracker } from '../testAccountTracker' ;
1818import { PasskeyPage } from '../../pages/passkey' ;
1919import { GleanEventsHelper } from '../glean' ;
20+ import { addWafBypassHeader } from '../waf' ;
2021import { existsSync , readFileSync } from 'fs' ;
2122import { join , dirname , basename } from 'path' ;
2223
24+ export { addWafBypassHeader } ;
25+
2326// The DEBUG env is used to debug without the playwright inspector, like in vscode
2427// see .vscode/launch.json
2528const DEBUG = ! ! process . env . DEBUG ;
@@ -35,42 +38,6 @@ export type TestOptions = {
3538} ;
3639export type WorkerOptions = { targetName : TargetName ; target : ServerTarget } ;
3740
38- const CI_WAF_TOKEN = process . env . CI_WAF_TOKEN ;
39-
40- /**
41- * Adds a route handler that injects the WAF bypass header on requests to
42- * FXA-owned domains only, leaving third-party origins (Stripe, hCaptcha)
43- * untouched. No-op when CI_WAF_TOKEN is unset.
44- */
45- export async function addWafBypassHeader ( page : Page , target : BaseTarget ) {
46- if ( ! CI_WAF_TOKEN ) {
47- if ( target . name === 'stage' || target . name === 'production' ) {
48- // eslint-disable-next-line no-console
49- console . warn (
50- `⚠ CI_WAF_TOKEN is not set for target "${ target . name } ". Requests may be blocked by the WAF.`
51- ) ;
52- }
53- return ;
54- }
55- const fxaDomains = [
56- new URL ( target . contentServerUrl ) . host ,
57- new URL ( target . authServerUrl ) . host ,
58- new URL ( target . paymentsNextUrl ) . host ,
59- new URL ( target . relierUrl ) . host ,
60- ] ;
61- const pattern = new RegExp (
62- fxaDomains . map ( ( d ) => d . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ) . join ( '|' )
63- ) ;
64- await page . route ( pattern , async ( route ) => {
65- await route . continue ( {
66- headers : {
67- ...route . request ( ) . headers ( ) ,
68- 'fxa-ci' : CI_WAF_TOKEN ,
69- } ,
70- } ) ;
71- } ) ;
72- }
73-
7441export const test = base . extend < TestOptions , WorkerOptions > ( {
7542 targetName : [ 'local' , { scope : 'worker' , option : true } ] ,
7643
0 commit comments