"""Database-marked tests may reach only the validated PostGIS endpoint."""

from __future__ import annotations

import socket

import pytest

from osm_lead_source_service.sidecar.migration_config import load_test_migration_settings


@pytest.mark.database
@pytest.mark.integration
def test_configured_database_endpoint_is_reachable() -> None:
    settings = load_test_migration_settings()
    connection = socket.create_connection((settings.host, settings.port), timeout=2)
    connection.close()


@pytest.mark.database
@pytest.mark.integration
def test_other_ports_and_external_hosts_are_blocked() -> None:
    settings = load_test_migration_settings()
    with pytest.raises(AssertionError, match="configured endpoint"):
        socket.create_connection((settings.host, settings.port + 1), timeout=1)
    with pytest.raises(AssertionError, match="configured endpoint"):
        socket.create_connection(("203.0.113.10", settings.port), timeout=1)
