fix(e2e): add Authorization header to API calls in gaps and webkit specs
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
import { test, expect, type TestUser } from '../../fixtures/auth-fixtures';
|
import { test, expect, type TestUser } from '../../fixtures/auth-fixtures';
|
||||||
import type { TestDataManager } from '../../utils/TestDataManager';
|
import type { TestDataManager } from '../../utils/TestDataManager';
|
||||||
import type { Page } from '@playwright/test';
|
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
|
* 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
|
// Gap 3: Overwrite Resolution Flow
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
test.describe('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
|
// Create existing host with initial config
|
||||||
const result = await testData.createProxyHost({
|
const result = await testData.createProxyHost({
|
||||||
domain: 'overwrite-test.example.com',
|
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 () => {
|
await test.step('Verify existing host was updated (not duplicated)', async () => {
|
||||||
// Fetch the host via API
|
// 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();
|
expect(response.ok()).toBeTruthy();
|
||||||
|
|
||||||
const host = await response.json();
|
const host = await response.json();
|
||||||
@@ -389,7 +389,7 @@ test.describe('Caddy Import Gap Coverage @caddy-import-gaps', () => {
|
|||||||
expect(host.forward_port).toBe(9000);
|
expect(host.forward_port).toBe(9000);
|
||||||
|
|
||||||
// Verify no duplicate was created - fetch all hosts and check count
|
// 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();
|
expect(allHostsResponse.ok()).toBeTruthy();
|
||||||
const allHosts = await allHostsResponse.json();
|
const allHosts = await allHostsResponse.json();
|
||||||
|
|
||||||
@@ -627,7 +627,7 @@ test.describe('Caddy Import Gap Coverage @caddy-import-gaps', () => {
|
|||||||
// Gap 5: Name Editing in Review
|
// Gap 5: Name Editing in Review
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
test.describe('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 domain = generateDomain(testData, 'custom-name-test');
|
||||||
const customName = 'My Custom Proxy Name';
|
const customName = 'My Custom Proxy Name';
|
||||||
const caddyfile = `${domain} { reverse_proxy localhost:5000 }`;
|
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 () => {
|
await test.step('Verify created host has custom name', async () => {
|
||||||
// Fetch all proxy hosts
|
// 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();
|
expect(response.ok()).toBeTruthy();
|
||||||
|
|
||||||
const hosts = await response.json();
|
const hosts = await response.json();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { Page } from '@playwright/test';
|
|||||||
import {
|
import {
|
||||||
attachImportDiagnostics,
|
attachImportDiagnostics,
|
||||||
ensureImportUiPreconditions,
|
ensureImportUiPreconditions,
|
||||||
|
getStoredAuthHeader,
|
||||||
logImportFailureContext,
|
logImportFailureContext,
|
||||||
resetImportSession,
|
resetImportSession,
|
||||||
waitForSuccessfulImportResponse,
|
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()) {
|
if (!meResponse.ok()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`WebKit auth bootstrap verification failed: /api/v1/auth/me returned ${meResponse.status()} at ${page.url()}`
|
`WebKit auth bootstrap verification failed: /api/v1/auth/me returned ${meResponse.status()} at ${page.url()}`
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { STORAGE_STATE } from '../../constants';
|
|||||||
|
|
||||||
const IMPORT_PAGE_PATH = '/tasks/import/caddyfile';
|
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);
|
const token = await page.evaluate(() => localStorage.getItem('charon_auth_token')).catch(() => null);
|
||||||
return token ? { Authorization: `Bearer ${token}` } : {};
|
return token ? { Authorization: `Bearer ${token}` } : {};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user