Files
proxy-god/tests/test_ban_tester.py
Dr Jones b852fd264f
Some checks failed
CI / Test Python 3.10 (push) Has been cancelled
CI / Test Python 3.11 (push) Has been cancelled
CI / Test Python 3.12 (push) Has been cancelled
fix: audit round 3 - fail-closed leak, shared asyncio loop, GOST bundling, close-X UX, persona key lookup, +29 tests
2026-05-22 18:23:52 -07:00

49 lines
1.9 KiB
Python

"""Heuristic tests for ban_tester."""
from __future__ import annotations
import unittest
from proxy_chain_manager import ban_tester
class TestBannedBodyHints(unittest.TestCase):
def test_normal_page_is_not_banned(self) -> None:
self.assertFalse(ban_tester._looks_banned_body("Welcome to my homepage"))
self.assertFalse(ban_tester._looks_banned_body("<html><body>hello</body></html>"))
def test_naked_captcha_word_is_not_banned(self) -> None:
# 'captcha' alone is too common (privacy policies, login pages) —
# earlier audit removed it from hints.
self.assertFalse(ban_tester._looks_banned_body(
"We use a captcha on the signup page to prevent bots."
))
def test_captcha_required_phrase_is_banned(self) -> None:
self.assertTrue(ban_tester._looks_banned_body("Captcha required to continue."))
self.assertTrue(ban_tester._looks_banned_body("Complete the captcha below."))
def test_access_denied_is_banned(self) -> None:
self.assertTrue(ban_tester._looks_banned_body("Access denied"))
self.assertTrue(ban_tester._looks_banned_body("ACCESS DENIED — 403"))
def test_cloudflare_ray_is_banned(self) -> None:
self.assertTrue(ban_tester._looks_banned_body("Cloudflare Ray ID: abc123"))
def test_empty_body_is_not_banned(self) -> None:
self.assertFalse(ban_tester._looks_banned_body(""))
self.assertFalse(ban_tester._looks_banned_body(None)) # type: ignore[arg-type]
class TestSiteCategories(unittest.TestCase):
def test_all_category_includes_known_sites(self) -> None:
all_urls = {u for _, u in ban_tester.SITE_CATEGORIES["All"]}
self.assertTrue(len(all_urls) > 5)
def test_categories_present(self) -> None:
for key in ("Social / General", "Shopping", "Crypto Exchanges", "DNS Providers", "All"):
self.assertIn(key, ban_tester.SITE_CATEGORIES)
if __name__ == "__main__":
unittest.main()