From 96237d28d0cc4e4cd8c3a0107d4cecf2c5be734e Mon Sep 17 00:00:00 2001 From: Mihai Criveti Date: Fri, 12 Dec 2025 13:36:40 +0000 Subject: [PATCH] fix: use Settings to load credentials in admin_page fixture Handle login page redirect when AUTH_REQUIRED is set by using the Settings class to get the correct basic_auth_user and basic_auth_password values for the Playwright tests. Signed-off-by: Mihai Criveti --- tests/playwright/conftest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/playwright/conftest.py b/tests/playwright/conftest.py index dfebe5219..2250b235e 100644 --- a/tests/playwright/conftest.py +++ b/tests/playwright/conftest.py @@ -18,6 +18,9 @@ from playwright.sync_api import APIRequestContext, Page, Playwright import pytest +# First-Party +from mcpgateway.config import Settings + # Get configuration from environment BASE_URL = os.getenv("TEST_BASE_URL", "http://localhost:8000") API_TOKEN = os.getenv("MCP_AUTH", "test-token") @@ -85,8 +88,14 @@ def authenticated_page(page: Page) -> Page: @pytest.fixture def admin_page(page: Page): """Provide a logged-in admin page for UI tests.""" + settings = Settings() # Go directly to admin - HTTP Basic Auth is handled by the page fixture page.goto("/admin") + # Handle login page redirect if auth is required + if re.search(r"login", page.url): + page.fill('[name="email"]', settings.basic_auth_user) + page.fill('[name="password"]', settings.basic_auth_password.get_secret_value()) + page.click('button[type="submit"]') # Verify we're on the admin page page.wait_for_url(re.compile(r".*admin")) return page