49 lines
1.9 KiB
Python
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()
|