Download tests/unit/shared/test_validators.py from paisaly/backend: direct link, hf CLI and curl.
- Browser
- Download file 6.13 kB
-
https://huggingface.co/spaces/paisaly/backend/resolve/main/tests/unit/shared/test_validators.py
- Command line
-
hf download hf://spaces/paisaly/backend/tests/unit/shared/test_validators.py
-
curl -L -o test_validators.py https://huggingface.co/spaces/paisaly/backend/resolve/main/tests/unit/shared/test_validators.py
6.13 kB
| from __future__ import annotations | |
| import pytest | |
| from app.shared.validators import ( | |
| validate_alias, | |
| validate_blocked_url, | |
| validate_url, | |
| validate_url_password, | |
| ) | |
| # --------------------------------------------------------------------------- | |
| # shared.validators — validate_url | |
| # --------------------------------------------------------------------------- | |
| def test_validate_url(url, expected): | |
| assert validate_url(url) is expected | |
| def test_validate_url_custom_blocked_domain(): | |
| assert validate_url("https://evil.com", blocked_self_domains=("evil.com",)) is False | |
| def test_validate_url_empty_blocked_list_allows_spoo(): | |
| assert validate_url("https://spoo.me/x", blocked_self_domains=()) is True | |
| def test_validate_url_malformed_bracket_host_is_invalid_not_an_error(): | |
| # urlparse raises on "]" in the netloc; must answer False, never a 500. | |
| assert validate_url("https://example.com]:80/x") is False | |
| def test_validate_url_rejects_non_http_schemes(url): | |
| assert validate_url(url) is False | |
| def test_validate_url_blocks_self_link_across_schemes(): | |
| # Bare hostname catches both http:// and https:// variants — guards | |
| # against the wiring bug where the full app_url only matched one scheme. | |
| assert validate_url("http://spoo.me/abc") is False | |
| assert validate_url("https://spoo.me/abc") is False | |
| assert validate_url("https://docs.spoo.me/x") is False | |
| # --------------------------------------------------------------------------- | |
| # shared.validators — validate_url_password | |
| # --------------------------------------------------------------------------- | |
| def test_validate_url_password(password, valid): | |
| assert validate_url_password(password) is valid | |
| # --------------------------------------------------------------------------- | |
| # shared.validators — validate_alias | |
| # --------------------------------------------------------------------------- | |
| def test_validate_alias(alias, expected): | |
| assert validate_alias(alias) is expected | |
| # --------------------------------------------------------------------------- | |
| # shared.validators — validate_blocked_url | |
| # --------------------------------------------------------------------------- | |
| def test_validate_blocked_url(url, patterns, expected): | |
| assert validate_blocked_url(url, patterns) is expected | |
| def test_validate_blocked_url_timeout_fails_open(mocker): | |
| """Timed-out patterns must fail open (URL stays allowed).""" | |
| mocker.patch("app.shared.validators.regex.search", side_effect=TimeoutError) | |
| assert validate_blocked_url("https://example.com", [r"any_pattern"]) is True | |