feat: Improve scraper resiliency and add both proxy and FlareSolverr support (#7953)

This commit is contained in:
Michael Genson
2026-07-26 14:33:51 -05:00
committed by GitHub
parent 1dca53dc29
commit 17398941ef
12 changed files with 1140 additions and 110 deletions

View File

@@ -5,6 +5,7 @@ from pathlib import Path
from typing import Any
import pytest
from pydantic import ValidationError
from mealie.core.config import get_app_settings
from mealie.core.settings.settings import AppSettings, determine_secrets
@@ -395,6 +396,51 @@ def test_sensitive_settings_mask(monkeypatch: pytest.MonkeyPatch):
assert settings_json[setting] == "*****"
_SCRAPER_URL_FIELDS = ["SCRAPER_PROXY_URL", "SCRAPER_FLARESOLVERR_URL"]
@pytest.mark.parametrize("field", _SCRAPER_URL_FIELDS)
@pytest.mark.parametrize(
"value",
[
"flaresolverr:8191", # missing scheme
"192.168.1.5:8191", # bare host:port
"just-a-hostname", # no scheme, no port
],
)
def test_scraper_url_rejects_missing_scheme(field: str, value: str, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv(field, value)
get_app_settings.cache_clear()
with pytest.raises(ValidationError):
get_app_settings()
@pytest.mark.parametrize("field", _SCRAPER_URL_FIELDS)
@pytest.mark.parametrize(
"value",
[
"http://flaresolverr:8191",
"https://fs.example.com:8191/",
"http://user:pass@host:8080", # userinfo is allowed
"socks5://host:1080", # non-http schemes (valid for proxies) are not rejected
],
)
def test_scraper_url_accepts_valid(field: str, value: str, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv(field, value)
get_app_settings.cache_clear()
assert getattr(get_app_settings(), field) == value
@pytest.mark.parametrize("field", _SCRAPER_URL_FIELDS)
def test_scraper_url_allows_unset(field: str, monkeypatch: pytest.MonkeyPatch):
monkeypatch.delenv(field, raising=False)
get_app_settings.cache_clear()
assert getattr(get_app_settings(), field) is None
class DetermineSecretsTests:
def test_non_production_returns_fixed_key(self, tmp_path: Path):
result = determine_secrets(tmp_path, ".secret", production=False)