7a0da7932b
Backwards Compatibility / Verify Encryption Constants (push) Waiting to run
Backwards Compatibility / PyPI Version Compatibility (push) Waiting to run
Backwards Compatibility / Database Migration Tests (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (python) (push) Waiting to run
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Blocked by required conditions
Docker Tests (Consolidated) / detect-changes (push) Waiting to run
Docker Tests (Consolidated) / Build Test Image (push) Waiting to run
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Blocked by required conditions
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Blocked by required conditions
Docker Tests (Consolidated) / Accessibility Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Unit Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / LLM Example Tests (push) Blocked by required conditions
Docker Tests (Consolidated) / Production Image Smoke Test (push) Blocked by required conditions
Docker Tests (Consolidated) / Infrastructure Tests (push) Blocked by required conditions
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Waiting to run
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
99 lines
2.6 KiB
Python
99 lines
2.6 KiB
Python
"""
|
|
Pytest configuration and shared fixtures for API tests
|
|
"""
|
|
|
|
import json
|
|
import subprocess
|
|
import uuid
|
|
import pytest
|
|
import requests
|
|
from pathlib import Path
|
|
import tempfile
|
|
import os
|
|
|
|
# Base URL for tests
|
|
BASE_URL = os.environ.get("LDR_TEST_BASE_URL", "http://127.0.0.1:5000")
|
|
# Use UUID for unique usernames to avoid collisions in parallel tests
|
|
TEST_USERNAME = f"testuser_{uuid.uuid4().hex[:12]}"
|
|
TEST_PASSWORD = "TestPass123"
|
|
|
|
|
|
class AuthHelper:
|
|
"""Helper class to handle Puppeteer authentication"""
|
|
|
|
@staticmethod
|
|
def get_auth_cookies():
|
|
"""Use Puppeteer to authenticate and get cookies"""
|
|
# Create a temporary file for cookie storage
|
|
cookie_file = tempfile.NamedTemporaryFile(
|
|
mode="w", suffix=".json", delete=False
|
|
)
|
|
cookie_file.close()
|
|
|
|
# Run the Node.js auth helper. The JS file still lives under
|
|
# tests/api_tests_with_login/ — it's shared with other Puppeteer
|
|
# suites, so we reference it in place rather than duplicate.
|
|
auth_script = (
|
|
Path(__file__).parents[2]
|
|
/ "api_tests_with_login"
|
|
/ "auth_helper.js"
|
|
)
|
|
cmd = [
|
|
"node",
|
|
str(auth_script),
|
|
BASE_URL,
|
|
TEST_USERNAME,
|
|
TEST_PASSWORD,
|
|
cookie_file.name,
|
|
]
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
cmd, capture_output=True, text=True, timeout=90
|
|
)
|
|
if result.returncode != 0:
|
|
raise Exception(f"Auth failed: {result.stderr}")
|
|
|
|
# Read cookies from file
|
|
with open(cookie_file.name, "r") as f:
|
|
cookies = json.load(f)
|
|
|
|
# Convert to requests format
|
|
cookie_dict = {c["name"]: c["value"] for c in cookies}
|
|
|
|
# Extract CSRF token
|
|
csrf_token = None
|
|
for cookie in cookies:
|
|
if cookie["name"] == "csrf_token":
|
|
csrf_token = cookie["value"]
|
|
break
|
|
|
|
return cookie_dict, csrf_token
|
|
|
|
finally:
|
|
# Clean up temp file
|
|
if Path(cookie_file.name).exists():
|
|
os.unlink(cookie_file.name)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def auth_session():
|
|
"""Session-wide fixture for authenticated requests"""
|
|
cookies, csrf_token = AuthHelper.get_auth_cookies()
|
|
|
|
session = requests.Session()
|
|
session.cookies.update(cookies)
|
|
session.headers.update(
|
|
{"X-CSRFToken": csrf_token, "Accept": "application/json"}
|
|
)
|
|
|
|
yield session, csrf_token
|
|
|
|
session.close()
|
|
|
|
|
|
@pytest.fixture
|
|
def base_url():
|
|
"""Fixture to provide base URL"""
|
|
return BASE_URL
|