Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ COPY --chown=app:app tests/ /app/tests/
COPY --chown=app:app examples/ /app/examples/
COPY --chown=app:app docs/ /app/docs/

RUN mkdir -p /app/data/ipinfo
RUN uv pip install --python .venv/bin/python --no-deps -e /app \
&& mkdir -p /app/data/ipinfo

# Probes the app service on port 8000. Any HTTP answer counts as alive; a refused connection or a timeout fails.
HEALTHCHECK --interval=10s --timeout=5s --start-period=20s --retries=3 \
Expand Down
1 change: 0 additions & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ services:
- ./tornadoapi_guard:/app/tornadoapi_guard:z
- ./tests:/app/tests:z
- ./pyproject.toml:/app/pyproject.toml:z
- ./uv.lock:/app/uv.lock:z
- ./vulture_whitelist.py:/app/vulture_whitelist.py:z
depends_on:
redis:
Expand Down
10 changes: 7 additions & 3 deletions tests/test_middleware_unit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
from collections.abc import AsyncGenerator
from types import SimpleNamespace
from typing import cast
Expand All @@ -8,13 +9,16 @@
import pytest
from guard_core.decorators.base import RouteConfig
from guard_core.handlers.cloud_handler import cloud_handler
from guard_core.handlers.ipinfo_handler import IPInfoManager
from guard_core.handlers.security_headers_handler import security_headers_manager
from guard_core.models import SecurityConfig
from tornado.web import RequestHandler

from tornadoapi_guard import SecurityMiddleware
from tornadoapi_guard.adapters import TornadoGuardRequest, get_guard_state

REDIS_URL = os.getenv("REDIS_URL") or "redis://localhost:6379"


class _StampedEndpoint:
__module__ = "tests.test_middleware_unit"
Expand Down Expand Up @@ -91,7 +95,7 @@ async def test_init_with_redis_enabled() -> None:
config = SecurityConfig(
geo_ip_handler=None,
enable_redis=True,
redis_url="redis://localhost:6379",
redis_url=REDIS_URL,
redis_prefix="test_init",
enable_penetration_detection=False,
)
Expand All @@ -100,7 +104,7 @@ async def test_init_with_redis_enabled() -> None:


async def test_init_with_blocked_countries_sets_geoip() -> None:
geo = MagicMock()
geo = IPInfoManager("test-token", None)
config = SecurityConfig(
geo_ip_handler=geo,
enable_redis=False,
Expand Down Expand Up @@ -409,7 +413,7 @@ async def test_refresh_cloud_ip_ranges_redis_path() -> None:
config = SecurityConfig(
geo_ip_handler=None,
enable_redis=True,
redis_url="redis://localhost:6379",
redis_url=REDIS_URL,
redis_prefix="test_cloud",
enable_penetration_detection=False,
block_cloud_providers={"AWS"},
Expand Down
Loading