fix(e2e): add Authorization header to API calls in gaps and webkit specs

This commit is contained in:
GitHub Actions
2026-03-21 16:21:06 +00:00
parent 66b37b5a98
commit 20537d7bd9
3 changed files with 9 additions and 8 deletions

View File

@@ -19,7 +19,7 @@
import { test, expect, type TestUser } from '../../fixtures/auth-fixtures';
import type { TestDataManager } from '../../utils/TestDataManager';
import type { Page } from '@playwright/test';
import { ensureAuthenticatedImportFormReady, ensureImportFormReady, resetImportSession } from './import-page-helpers';
import { ensureAuthenticatedImportFormReady, ensureImportFormReady, getStoredAuthHeader, resetImportSession } from './import-page-helpers';
/**
* Helper: Generate unique domain with namespace isolation
@@ -328,7 +328,7 @@ test.describe('Caddy Import Gap Coverage @caddy-import-gaps', () => {
// Gap 3: Overwrite Resolution Flow
// =========================================================================
test.describe('Overwrite Resolution Flow', () => {
test('3.1: should update existing host when selecting Replace with Imported resolution', async ({ page, request, testData, browserName, adminUser }) => {
test('3.1: should update existing host when selecting Replace with Imported resolution', async ({ page, testData, browserName, adminUser }) => {
// Create existing host with initial config
const result = await testData.createProxyHost({
domain: 'overwrite-test.example.com',
@@ -379,7 +379,7 @@ test.describe('Caddy Import Gap Coverage @caddy-import-gaps', () => {
await test.step('Verify existing host was updated (not duplicated)', async () => {
// Fetch the host via API
const response = await request.get(`/api/v1/proxy-hosts/${hostId}`);
const response = await page.request.get(`/api/v1/proxy-hosts/${hostId}`, { headers: await getStoredAuthHeader(page) });
expect(response.ok()).toBeTruthy();
const host = await response.json();
@@ -389,7 +389,7 @@ test.describe('Caddy Import Gap Coverage @caddy-import-gaps', () => {
expect(host.forward_port).toBe(9000);
// Verify no duplicate was created - fetch all hosts and check count
const allHostsResponse = await request.get('/api/v1/proxy-hosts');
const allHostsResponse = await page.request.get('/api/v1/proxy-hosts', { headers: await getStoredAuthHeader(page) });
expect(allHostsResponse.ok()).toBeTruthy();
const allHosts = await allHostsResponse.json();
@@ -627,7 +627,7 @@ test.describe('Caddy Import Gap Coverage @caddy-import-gaps', () => {
// Gap 5: Name Editing in Review
// =========================================================================
test.describe('Name Editing in Review', () => {
test('5.1: should create proxy host with custom name from review table input', async ({ page, request, testData }) => {
test('5.1: should create proxy host with custom name from review table input', async ({ page, testData }) => {
const domain = generateDomain(testData, 'custom-name-test');
const customName = 'My Custom Proxy Name';
const caddyfile = `${domain} { reverse_proxy localhost:5000 }`;
@@ -669,7 +669,7 @@ test.describe('Caddy Import Gap Coverage @caddy-import-gaps', () => {
await test.step('Verify created host has custom name', async () => {
// Fetch all proxy hosts
const response = await request.get('/api/v1/proxy-hosts');
const response = await page.request.get('/api/v1/proxy-hosts', { headers: await getStoredAuthHeader(page) });
expect(response.ok()).toBeTruthy();
const hosts = await response.json();

View File

@@ -22,6 +22,7 @@ import { Page } from '@playwright/test';
import {
attachImportDiagnostics,
ensureImportUiPreconditions,
getStoredAuthHeader,
logImportFailureContext,
resetImportSession,
waitForSuccessfulImportResponse,
@@ -72,7 +73,7 @@ async function ensureWebkitAuthSession(page: Page): Promise<void> {
});
}
const meResponse = await page.request.get('/api/v1/auth/me');
const meResponse = await page.request.get('/api/v1/auth/me', { headers: await getStoredAuthHeader(page) });
if (!meResponse.ok()) {
throw new Error(
`WebKit auth bootstrap verification failed: /api/v1/auth/me returned ${meResponse.status()} at ${page.url()}`

View File

@@ -5,7 +5,7 @@ import { STORAGE_STATE } from '../../constants';
const IMPORT_PAGE_PATH = '/tasks/import/caddyfile';
async function getStoredAuthHeader(page: Page): Promise<Record<string, string>> {
export async function getStoredAuthHeader(page: Page): Promise<Record<string, string>> {
const token = await page.evaluate(() => localStorage.getItem('charon_auth_token')).catch(() => null);
return token ? { Authorization: `Bearer ${token}` } : {};
}