mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-22 23:22:18 +01:00
The installer ships as the steam_installer package beside steam_backlog_enforcer, with its tests, docs and Proton lock. The enforcer's fast install now starts the installer from this checkout. Both appinfo.vdf readers share one key-value decoder (steam_installer.appinfo_kv), and the duplicated test fixtures and helpers are folded into conftest and _cli_helpers so the whole-tree duplicate-code check is clean. check_requirements_sync treats sibling packages as first-party. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZCxnNWLtpVwFLVk9w
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""The one https-only way the package opens a URL."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Self
|
|
|
|
import pytest
|
|
|
|
from steam_installer import _http
|
|
|
|
if TYPE_CHECKING:
|
|
import urllib.request
|
|
|
|
|
|
class _Response:
|
|
def __enter__(self) -> Self:
|
|
return self
|
|
|
|
def __exit__(self, *exc: object) -> None:
|
|
return None
|
|
|
|
|
|
def test_a_non_https_url_is_refused_before_any_request(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""Not even file:// or plain http gets as far as urlopen."""
|
|
monkeypatch.setattr(
|
|
_http.urllib.request, "urlopen", lambda *a, **kw: pytest.fail("no request")
|
|
)
|
|
for url in ("http://example.invalid/x", "file:///etc/passwd", "ftp://x/y"):
|
|
with (
|
|
pytest.raises(ValueError, match="non-https"),
|
|
_http.open_https(url, timeout=1, user_agent="ua"),
|
|
):
|
|
pass
|
|
|
|
|
|
def test_an_https_url_is_opened_with_the_agent_and_timeout(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
"""The request carries the caller's User-Agent, and the timeout is passed on."""
|
|
seen: dict[str, object] = {}
|
|
|
|
def fake_urlopen(request: urllib.request.Request, timeout: float) -> _Response:
|
|
seen["url"] = request.full_url
|
|
seen["agent"] = request.get_header("User-agent")
|
|
seen["timeout"] = timeout
|
|
return _Response()
|
|
|
|
monkeypatch.setattr(_http.urllib.request, "urlopen", fake_urlopen)
|
|
with _http.open_https("https://example.invalid/x", timeout=7, user_agent="ua"):
|
|
pass
|
|
assert seen == {"url": "https://example.invalid/x", "agent": "ua", "timeout": 7}
|