Skip to content

Commit d130699

Browse files
committed
Don't inspect request headers in cron jobs
1 parent eed2d7f commit d130699

File tree

9 files changed

+67
-35
lines changed

9 files changed

+67
-35
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ ADMINS=
106106
MONTHLY_CRON_ENABLED=
107107

108108
# Functional tests
109-
E2E_TEST_ENV=local
109+
E2E_TEST_ENV="not running e2e tests"
110110
E2E_TEST_SECRET=test-secret
111111
E2E_TEST_ACCOUNT_BASE_EMAIL=test-account
112112
E2E_TEST_ACCOUNT_BASE_PASSWORD=test-password

functional-tests/playwright.config.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ const webServerConfig = {
3434

3535
// Geo locations
3636
export const locations = [
37-
{
38-
name: "US",
39-
geolocation: { latitude: 40.7167, longitude: -74.0 },
40-
locale: "en-US",
41-
},
37+
// {
38+
// name: "US",
39+
// geolocation: { latitude: 40.7167, longitude: -74.0 },
40+
// locale: "en-US",
41+
// },
4242
{
4343
name: "NL",
4444
geolocation: { latitude: 52.370216, longitude: 4.895168 },
@@ -59,21 +59,21 @@ const baseDevices: Array<{ name: string; use: (typeof devices)[string] }> = [
5959
},
6060
},
6161
},
62-
{
63-
name: "firefox",
64-
use: {
65-
...devices["Desktop Firefox"],
66-
viewport: {
67-
width: 1920,
68-
height: 1080,
69-
},
70-
},
71-
},
72-
/* Test against mobile viewports. */
73-
{
74-
name: "Mobile Chrome",
75-
use: devices["Pixel 5"],
76-
},
62+
// {
63+
// name: "firefox",
64+
// use: {
65+
// ...devices["Desktop Firefox"],
66+
// viewport: {
67+
// width: 1920,
68+
// height: 1080,
69+
// },
70+
// },
71+
// },
72+
// /* Test against mobile viewports. */
73+
// {
74+
// name: "Mobile Chrome",
75+
// use: devices["Pixel 5"],
76+
// },
7777
];
7878

7979
export const getEnabledFeatureFlags = () => {

functional-tests/tests/global-setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ async function setupUserAccount(browser: Browser) {
6767
);
6868

6969
// Validate user is signed in
70+
console.log("SIGNED IN:", page.url());
7071
await page.waitForURL("**/user/**");
72+
console.log("WAITED:", page.url());
7173

7274
// Store test user session
7375
const storageStatePath = getTestUserSessionFilePath(project.name);
@@ -94,6 +96,9 @@ setup("Set up feature flags and user accounts", async ({ browser }) => {
9496
const dir = path.resolve(__dirname, "../functional-test-cache");
9597
fs.mkdirSync(dir, { recursive: true });
9698

99+
console.log("CREATING ACCOUNT", browser.browserType().name(), browser.version());
97100
await setupFeatureFlags();
101+
console.log("SET UP FLAGS", browser.browserType().name(), browser.version());
98102
await setupUserAccount(browser);
103+
console.log("SET UP ACCOUNT", browser.browserType().name(), browser.version());
99104
});

functional-tests/utils/fxa.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ async function fillAndSubmitConfirmationCode(page: Page, email: string) {
7070

7171
async function signUpUser(page: Page, email: string, password: string) {
7272
// Fill and submit sign-up form
73+
console.log("SIGNING IN AS", email, password);
7374
await fillAndSubmitEmail(page, email);
7475
await fillAndSubmitPassword(page, password);
7576
await fillAndSubmitConfirmationCode(page, email);

package-lock.json

Lines changed: 15 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/[[...slug]]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ export default async function DashboardPage(props: Props) {
7575

7676
const session = await getServerSession();
7777
if (!checkSession(session) || !session?.user?.subscriber?.fxa_uid) {
78+
console.log("NO SESSION FOUND, LOGGING OUT:", { session });
7879
return redirect("/auth/logout");
7980
}
8081

8182
const subscriber = await getSubscriberByFxaUid(
8283
session.user.subscriber.fxa_uid,
8384
);
8485
if (!subscriber) {
86+
console.log("NO SUBSCRIBER FOUND, LOGGING OUT:", { subscriber });
8587
redirect("/auth/logout");
8688
}
8789

src/app/functions/server/getExperiments.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ describe("getExperiments", () => {
9999
});
100100

101101
it("calls Cirrus V2 when feature flag is enabled with preview param", async () => {
102+
process.env.NEXT_RUNTIME = "test";
102103
process.env.NIMBUS_SIDECAR_URL = "https://cirrus.example";
103104
getEnabledFeatureFlagsMock.mockReturnValue([
104105
"CirrusV2",
@@ -150,6 +151,8 @@ describe("getExperiments", () => {
150151
previewMode: true,
151152
}),
152153
);
154+
155+
delete process.env.NEXT_RUNTIME;
153156
});
154157

155158
it("calls Cirrus V1 when featurn flag is disabled", async () => {
@@ -188,7 +191,8 @@ describe("getExperiments", () => {
188191
);
189192
});
190193

191-
it("fallsback to defaultExperimentData when not experiment data is returned by Cirrus", async () => {
194+
it("fallsback to defaultExperimentData when no experiment data is returned by Cirrus", async () => {
195+
process.env.NEXT_RUNTIME = "test";
192196
process.env.NIMBUS_SIDECAR_URL = "https://cirrus.example";
193197
getEnabledFeatureFlagsMock.mockReturnValue([
194198
"CirrusV2",
@@ -235,6 +239,7 @@ describe("getExperiments", () => {
235239
previewMode: true,
236240
}),
237241
);
242+
delete process.env.NEXT_RUNTIME;
238243
});
239244

240245
it("logs error, captures exception, and returns defaultExperimentData on error response", async () => {

src/app/functions/server/getExperiments.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ export async function getExperiments(params: {
5959
serverUrl.pathname += "v1/features";
6060
}
6161

62-
const nextHeaders = await loadNextHeaders();
62+
const nextHeaders =
63+
// We also check for experiments in cron jobs, where there are
64+
// no HTTP requests. Skip the headers there; we don't need to
65+
// force-enable experiments in cronjobs.
66+
typeof process.env.NEXT_RUNTIME === "string"
67+
? await loadNextHeaders()
68+
: null;
6369
let previewMode = false;
6470
if (nextHeaders) {
6571
const headersList = await nextHeaders.headers();

src/db/tables/featureFlags.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ export async function getEnabledFeatureFlags(
9292
options: { isSignedOut?: false; email: string } | { isSignedOut: true },
9393
): Promise<FeatureFlagName[]> {
9494
// Force feature flags for E2E tests via URL query params
95-
if (process.env.E2E_TEST_ENV === "local") {
95+
if (
96+
// Check that we're running under Next.js; in cronjobs
97+
// there's no request to inspect. We're not force-enabling
98+
// feature flags in that environment anyway.
99+
typeof process.env.NEXT_RUNTIME === "string" &&
100+
// When running end-to-end tests locally or in a PR,
101+
// we can force-enable feature flags that haven't been enabled
102+
// yet on stage or on prod:
103+
process.env.E2E_TEST_ENV === "local"
104+
) {
96105
const { headers } = await import("next/headers");
97106
const forcedFeatureFlags = (await headers()).get("x-forced-feature-flags");
98107

0 commit comments

Comments
 (0)