fix: audit round 3 - fail-closed leak, shared asyncio loop, GOST bundling, close-X UX, persona key lookup, +29 tests
This commit is contained in:
48
tests/test_ban_tester.py
Normal file
48
tests/test_ban_tester.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user