Skip to content

Commit bd817db

Browse files
committed
only use xsrf token for organization requests
1 parent 97f4bce commit bd817db

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

e2e/time.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ test('test that billable icon shows dollar sign for USD currency on time entry r
608608
page,
609609
ctx,
610610
}) => {
611-
await updateOrganizationCurrencyViaWeb(ctx, 'USD');
611+
await updateOrganizationCurrencyViaWeb(page, ctx, 'USD');
612612
await goToTimeOverview(page);
613613
await createEmptyTimeEntry(page);
614614
const timeEntryRow = page.locator('[data-testid="time_entry_row"]').first();
@@ -621,7 +621,7 @@ test('test that billable icon shows euro sign for EUR currency on time entry row
621621
page,
622622
ctx,
623623
}) => {
624-
await updateOrganizationCurrencyViaWeb(ctx, 'EUR');
624+
await updateOrganizationCurrencyViaWeb(page, ctx, 'EUR');
625625
await goToTimeOverview(page);
626626
await createEmptyTimeEntry(page);
627627
const timeEntryRow = page.locator('[data-testid="time_entry_row"]').first();

e2e/timetracker.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test('test that starting and stopping a timer without description and project wo
3030
});
3131

3232
test('test that billable icon shows dollar sign for USD currency', async ({ page, ctx }) => {
33-
await updateOrganizationCurrencyViaWeb(ctx, 'USD');
33+
await updateOrganizationCurrencyViaWeb(page, ctx, 'USD');
3434
await goToDashboard(page);
3535
await page.waitForLoadState('networkidle');
3636
const billableButton = page.getByRole('button', { name: 'Non Billable' }).first();
@@ -39,7 +39,7 @@ test('test that billable icon shows dollar sign for USD currency', async ({ page
3939
});
4040

4141
test('test that billable icon shows euro sign for EUR currency', async ({ page, ctx }) => {
42-
await updateOrganizationCurrencyViaWeb(ctx, 'EUR');
42+
await updateOrganizationCurrencyViaWeb(page, ctx, 'EUR');
4343
await goToDashboard(page);
4444
await page.waitForLoadState('networkidle');
4545
const billableButton = page.getByRole('button', { name: 'Non Billable' }).first();

e2e/utils/api.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,10 @@ async function createApiToken(page: Page): Promise<string> {
6565
throw new Error('Failed to create API token after retries');
6666
}
6767

68-
function buildAuthHeaders(token: string, xsrfToken: string): Record<string, string> {
68+
function bearerHeaders(token: string): Record<string, string> {
6969
return {
7070
Accept: 'application/json',
7171
Authorization: `Bearer ${token}`,
72-
// XSRF header is needed for web routes (e.g. PUT /teams) that go through
73-
// VerifyCsrfToken middleware. API routes ignore it but it doesn't hurt.
74-
...(xsrfToken ? { 'X-XSRF-TOKEN': xsrfToken } : {}),
7572
};
7673
}
7774

@@ -82,11 +79,7 @@ function buildAuthHeaders(token: string, xsrfToken: string): Record<string, stri
8279
export async function setupTestContext(page: Page): Promise<TestContext> {
8380
const token = await createApiToken(page);
8481
const request = page.request;
85-
86-
const cookies = await page.context().cookies();
87-
const xsrfCookie = cookies.find((c) => c.name === 'XSRF-TOKEN');
88-
const xsrfToken = xsrfCookie ? decodeURIComponent(xsrfCookie.value) : '';
89-
const headers = buildAuthHeaders(token, xsrfToken);
82+
const headers = bearerHeaders(token);
9083

9184
const orgId = await getOrganizationId(request, headers);
9285
const memberId = await getCurrentMemberId(request, orgId, headers);
@@ -547,11 +540,17 @@ export async function updateOrganizationSettingViaApi(
547540
}
548541

549542
export async function updateOrganizationCurrencyViaWeb(
543+
page: Page,
550544
ctx: TestContext,
551545
currency: string,
552546
name: string = 'Test Organization'
553547
) {
554-
const response = await ctx.request.put(`${PLAYWRIGHT_BASE_URL}/teams/${ctx.orgId}`, {
548+
const cookies = await page.context().cookies();
549+
const xsrfCookie = cookies.find((c) => c.name === 'XSRF-TOKEN');
550+
const xsrfToken = xsrfCookie ? decodeURIComponent(xsrfCookie.value) : '';
551+
552+
const response = await page.request.put(`${PLAYWRIGHT_BASE_URL}/teams/${ctx.orgId}`, {
553+
headers: { 'X-XSRF-TOKEN': xsrfToken },
555554
data: { name, currency },
556555
});
557556
expect(response.status()).toBe(200);

0 commit comments

Comments
 (0)