Skip to content

Commit 4a4c857

Browse files
fix: use Settings to load credentials in admin_page fixture (#1519)
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 <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
1 parent 03aa8ec commit 4a4c857

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/playwright/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
from playwright.sync_api import APIRequestContext, Page, Playwright
1919
import pytest
2020

21+
# First-Party
22+
from mcpgateway.config import Settings
23+
2124
# Get configuration from environment
2225
BASE_URL = os.getenv("TEST_BASE_URL", "http://localhost:8000")
2326
API_TOKEN = os.getenv("MCP_AUTH", "test-token")
@@ -85,8 +88,14 @@ def authenticated_page(page: Page) -> Page:
8588
@pytest.fixture
8689
def admin_page(page: Page):
8790
"""Provide a logged-in admin page for UI tests."""
91+
settings = Settings()
8892
# Go directly to admin - HTTP Basic Auth is handled by the page fixture
8993
page.goto("/admin")
94+
# Handle login page redirect if auth is required
95+
if re.search(r"login", page.url):
96+
page.fill('[name="email"]', settings.basic_auth_user)
97+
page.fill('[name="password"]', settings.basic_auth_password.get_secret_value())
98+
page.click('button[type="submit"]')
9099
# Verify we're on the admin page
91100
page.wait_for_url(re.compile(r".*admin"))
92101
return page

0 commit comments

Comments
 (0)