test.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. """Search engine helpers: registry, query builder, decoder."""
  3. import sys, base64
  4. err = []
  5. from core.main import UFONet
  6. app = UFONet()
  7. try:
  8. app.start_ship_engine()
  9. except SystemExit:
  10. pass
  11. except Exception as e:
  12. err.append(f"start_ship_engine raised: {type(e).__name__}: {e}")
  13. expected_engines = ['bing', 'duck', 'brave', 'mojeek', 'yahoo', 'startpage', 'ecosia']
  14. for e in expected_engines:
  15. if e not in app.search_engines:
  16. err.append(f"search engine missing in registry: {e}")
  17. target = "https://example.com/page.php"
  18. b64 = base64.urlsafe_b64encode(target.encode("utf-8")).decode("ascii").rstrip("=")
  19. sample_bing = f"https://www.bing.com/ck/a?!&&p=xyz&u=a1{b64}&ntb=1"
  20. got = app._bing_decode(sample_bing)
  21. if got != target:
  22. err.append(f"_bing_decode mismatch: expected {target!r}, got {got!r}")
  23. raw_yahoo = "https://r.search.yahoo.com/_ylt=xxxx/RV=2/RE=00/RO=10/RU=https%3a%2f%2fexample.com%2fpage%3fa%3d1/RK=2/RS=zzz"
  24. got2 = app._yahoo_decode(raw_yahoo)
  25. if "example.com/page" not in got2:
  26. err.append(f"_yahoo_decode unexpected: {got2!r}")
  27. class _O: pass
  28. app.options = _O()
  29. app.options.search = "page.php?url="
  30. app.options.dorks = None
  31. app.options.autosearch = None
  32. sep, q = app._engine_query_string(None)
  33. if sep != "page.php?url=" or "instreamset" not in q:
  34. err.append(f"query_string (search mode) wrong: sep={sep!r} q={q!r}")
  35. app.options.search = None
  36. app.options.dorks = "dorks.txt"
  37. sep2, q2 = app._engine_query_string("redirect.php?url=")
  38. if sep2 != "redirect.php?url=" or "redirect.php" not in q2:
  39. err.append(f"query_string (dork mode) wrong: sep={sep2!r} q={q2!r}")
  40. print(f"registry: {app.search_engines}")
  41. print(f"bing decode OK: {got == target}")
  42. print(f"yahoo decode OK: {'example.com/page' in got2}")
  43. print(f"query_string (search): {sep!r}, {q!r}")
  44. print(f"query_string (dork): {sep2!r}, {q2!r}")
  45. for e in err:
  46. print("FAIL:", e)
  47. sys.exit(0 if not err else 1)