81b9a66ef5
- Delete 4 obsolete unit tests tied to removed git mount/clone models - Update imports and assertions across unit/integration/service tests - Fix Settings defaults (postgres host, JWT props, cookie_samesite) - Add skip guards for PostgreSQL-dependent integration tests - Fix GitService env assertions and HealthMonitor state-change tests - Repair docker/container inspect assertions in test_docker_service - Fix ToolTypeCreate default_port validator ordering bug - Fix check_port_exposed substring false-positive for port 0 - Update test_tool_types_api_extended to use interface_type field Quality gates: pytest 311 passed, 34 skipped; npm typecheck/lint/test 87 passed
76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
import pytest
|
|
|
|
from src.config import Settings
|
|
from src.database import build_database_url
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_settings_default_database_url_uses_asyncpg(monkeypatch) -> None:
|
|
"""Test that default database URL uses asyncpg driver and correct defaults."""
|
|
monkeypatch.delenv("DATABASE_URL", raising=False)
|
|
settings = Settings()
|
|
# When DATABASE_URL env var is not set, the URL is built from defaults.
|
|
expected = "postgresql+asyncpg://headquarter:headquarter@postgres:5432/headquarter"
|
|
assert settings.database_url == expected
|
|
|
|
|
|
@pytest.mark.unit
|
|
|
|
def test_build_database_url_uses_explicit_values() -> None:
|
|
url = build_database_url(
|
|
user="user",
|
|
password="pass",
|
|
host="db",
|
|
port=5433,
|
|
database="app",
|
|
)
|
|
|
|
assert url == "postgresql+asyncpg://user:pass@db:5433/app"
|
|
|
|
|
|
@pytest.mark.unit
|
|
|
|
def test_settings_prefers_explicit_database_url_env(monkeypatch) -> None:
|
|
monkeypatch.setenv("DATABASE_URL", "postgresql+asyncpg://local:local@localhost:5432/localdb")
|
|
|
|
settings = Settings()
|
|
|
|
assert settings.database_url == "postgresql+asyncpg://local:local@localhost:5432/localdb"
|
|
|
|
|
|
@pytest.mark.unit
|
|
|
|
def test_auth_settings_have_secure_defaults() -> None:
|
|
settings = Settings()
|
|
|
|
assert settings.authentik_client_id == "headquarter-web"
|
|
assert settings.authentik_client_secret == "change-me"
|
|
assert settings.resolved_authentik_authorize_url.endswith("/application/o/authorize/")
|
|
assert settings.resolved_authentik_token_url.endswith("/application/o/token/")
|
|
assert settings.resolved_authentik_jwks_url.endswith("/application/o/headquarter-web/jwks/")
|
|
assert settings.jwt_algorithm == "HS256"
|
|
assert settings.access_token_ttl_minutes == 15
|
|
assert settings.refresh_token_ttl_days == 7
|
|
|
|
|
|
@pytest.mark.unit
|
|
|
|
def test_cookie_policy_is_strict_in_production(monkeypatch) -> None:
|
|
monkeypatch.setenv("APP_ENV", "production")
|
|
|
|
settings = Settings()
|
|
|
|
assert settings.cookie_secure is True
|
|
assert settings.cookie_samesite == "strict"
|
|
|
|
|
|
@pytest.mark.unit
|
|
|
|
def test_cookie_policy_is_relaxed_for_local_dev(monkeypatch) -> None:
|
|
monkeypatch.setenv("APP_ENV", "development")
|
|
|
|
settings = Settings()
|
|
|
|
assert settings.cookie_secure is False
|
|
assert settings.cookie_samesite == "lax"
|