Skip to content

Commit 4156eb6

Browse files
committed
feat(fxa): Pass WAF bypass token with functional-test auth-client
Because: - Some functional tests make use of the auth-client for direct calls to the auth-server - And we want to enable blocking direct requests to the auth-server This commit: - Passes a unique token to the auth-client requests that are blocking to enable bypassing the rule Closes:
1 parent adf1f60 commit 4156eb6

5 files changed

Lines changed: 44 additions & 11 deletions

File tree

packages/functional-tests/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ For example, to run a specific test against stage:
3434
yarn test --project=stage --grep="errors on xss redirect_to parameter"
3535
```
3636

37+
### Running against Stage or Production
38+
39+
In order to run local tests against stage or production, you'll need to set a few environment variables first. Some tests make use of the auth-client for direct calls to auth-server, so we use a bypass header for the WAF to allow the traffic. You'll need to set both `CI=1` and `CI_WAF_TOKEN="my_token"` environment variables. You can get a copy of the bypass token from 1Password.
40+
3741
### Specifying a target in tests
3842

3943
Some tests only work with certain targets. The content-server mocha tests for example will only work on `local`. Use [annotations](https://playwright.dev/docs/test-annotations#annotations) and [TestInfo](https://playwright.dev/docs/api/class-testinfo) to determine when a test should run.

packages/functional-tests/lib/targets/base.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ export abstract class BaseTarget {
3737
return this.contentServerUrl;
3838
}
3939

40+
/**
41+
* Will return a `Headers` object with the WAF bypass header if we're in
42+
* CI and the token is set, otherwise undefined.
43+
*
44+
* This can be passed to the auth-client calls that support optional headers.
45+
*/
46+
get ciHeader(): Headers | undefined {
47+
const ci = !!process.env.CI;
48+
const ciWafToken = process.env.CI_WAF_TOKEN;
49+
return ci && ciWafToken ? new Headers({ 'fxa-ci': ciWafToken }) : undefined;
50+
}
51+
4052
constructor(
4153
readonly authServerUrl: string,
4254
emailUrl?: string

packages/functional-tests/lib/targets/local.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ export class LocalTarget extends BaseTarget {
3333
) {
3434
// Quick and dirty way to see if this works...
3535
await this.rateLimitClient.resetCounts();
36-
const result = await this.authClient.signUp(email, password, options);
36+
const result = await this.authClient.signUp(
37+
email,
38+
password,
39+
options,
40+
this.ciHeader
41+
);
3742
await this.authClient.deviceRegister(
3843
result.sessionToken,
3944
'playwright',

packages/functional-tests/lib/targets/remote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export abstract class RemoteTarget extends BaseTarget {
1919
const creds = await this.authClient.signUp(
2020
email,
2121
password,
22-
filteredOptions
22+
filteredOptions,
23+
this.ciHeader
2324
);
2425
if (preVerified === 'true') {
2526
const code = await this.emailClient.getVerifyCode(email);

packages/functional-tests/tests/misc/authClientV2.spec.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@ import AuthClient, {
88
getCredentialsV2,
99
} from '../../../fxa-auth-client/browser';
1010
import { expect, test } from '../../lib/fixtures/standard';
11+
import { BaseTarget } from '../../lib/targets/base';
1112

1213
test.describe('auth-client-tests', () => {
13-
async function signUp(client: AuthClient, email: string, password: string) {
14-
const credentials = await client.signUp(email, password, {
15-
keys: true,
16-
lang: 'en',
17-
preVerified: 'true',
18-
});
14+
async function signUp(
15+
client: AuthClient,
16+
email: string,
17+
password: string,
18+
target: BaseTarget
19+
) {
20+
const credentials = await client.signUp(
21+
email,
22+
password,
23+
{
24+
keys: true,
25+
lang: 'en',
26+
preVerified: 'true',
27+
},
28+
target.ciHeader
29+
);
1930

2031
expect(credentials.sessionToken).toBeDefined();
2132

@@ -43,7 +54,7 @@ test.describe('auth-client-tests', () => {
4354
const client = target.authClient;
4455
const { email, password } = testAccountTracker.generateAccountDetails();
4556

46-
await signUp(client, email, password);
57+
await signUp(client, email, password, target);
4758

4859
// Check the salt is V1
4960
const status = await client.getCredentialStatusV2(email);
@@ -76,7 +87,7 @@ test.describe('auth-client-tests', () => {
7687
const client = target.createAuthClient(2);
7788
const { email, password } = testAccountTracker.generateAccountDetails();
7889

79-
await signUp(client, email, password);
90+
await signUp(client, email, password, target);
8091

8192
// Check the salt is V1
8293
const status = await client.getCredentialStatusV2(email);
@@ -119,7 +130,7 @@ test.describe('auth-client-tests', () => {
119130
const client = target.authClient;
120131
const { email, password } = testAccountTracker.generateAccountDetails();
121132

122-
await signUp(client, email, password);
133+
await signUp(client, email, password, target);
123134

124135
const signInResult = await client.signIn(email, password, { keys: true });
125136
expect(signInResult.keyFetchToken).toBeDefined();

0 commit comments

Comments
 (0)