Spaces:
Paused
Paused
Malina
Claude Fable 5.1
v0.90: scoped single-use tokens, hardened link fetch, 45-minute cap, whole-video digest, one classification call, no OCR
1d697a7 Download tests/test_fetch_validation.py from NextNeural/NINA: direct link, hf CLI and curl.
- Browser
- Download file 2.77 kB
-
https://huggingface.co/spaces/NextNeural/NINA/resolve/main/tests/test_fetch_validation.py
- Command line
-
hf download hf://spaces/NextNeural/NINA/tests/test_fetch_validation.py
-
curl -L -o test_fetch_validation.py https://huggingface.co/spaces/NextNeural/NINA/resolve/main/tests/test_fetch_validation.py
2.77 kB
| import pytest | |
| import fetch | |
| def _public_dns(monkeypatch): | |
| # Resolve every allowed host to a public address so tests need no network. | |
| monkeypatch.setattr(fetch.socket, "getaddrinfo", | |
| lambda host, *a, **k: [(None, None, None, None, ("142.250.1.1", 0))]) | |
| def test_allowed(url): | |
| assert fetch.check_url(url) is None | |
| def test_refused(url): | |
| assert fetch.check_url(url) is not None | |
| def test_private_resolution_refused(monkeypatch): | |
| monkeypatch.setattr(fetch.socket, "getaddrinfo", | |
| lambda host, *a, **k: [(None, None, None, None, ("10.0.0.5", 0))]) | |
| assert fetch.check_url("https://www.youtube.com/watch?v=abc") is not None | |
| def test_unresolvable_refused(monkeypatch): | |
| def boom(*a, **k): | |
| raise OSError("nxdomain") | |
| monkeypatch.setattr(fetch.socket, "getaddrinfo", boom) | |
| assert "can't be reached" in fetch.check_url("https://vimeo.com/1") | |
| def test_generic_extractor_not_allowed(): | |
| assert "generic" not in fetch.ALLOWED_EXTRACTORS or "generic:unsupported" in fetch.ALLOWED_EXTRACTORS | |
| assert not any(e == "generic" for e in fetch.ALLOWED_EXTRACTORS) | |
| def test_cookie_filter(monkeypatch, tmp_path): | |
| raw = ("# Netscape HTTP Cookie File\n" | |
| ".youtube.com\tTRUE\t/\tTRUE\t0\tSID\tabc\n" | |
| ".bank.example\tTRUE\t/\tTRUE\t0\tSESSION\tsecret\n" | |
| "accounts.google.com\tFALSE\t/\tTRUE\t0\tX\ty\n") | |
| monkeypatch.setenv("YT_DLP_COOKIES", raw) | |
| monkeypatch.delenv("YT_DLP_COOKIES_B64", raising=False) | |
| monkeypatch.setattr(fetch, "_cookie_path", None) | |
| p = fetch._cookiefile() | |
| assert p | |
| text = open(p, encoding="utf-8").read() | |
| assert "youtube.com" in text and "accounts.google.com" in text | |
| assert "bank.example" not in text | |
| def test_bad_token_short_circuits(monkeypatch): | |
| monkeypatch.setattr(fetch, "verify_usage_token", lambda t, s=None: False) | |
| assert fetch.fetch_video("https://youtu.be/x", "nope") == (None, "Not authorized.") | |