test.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. """botnet/dorks.txt sanity checks."""
  3. import sys, os
  4. err = []
  5. path = "botnet/dorks.txt"
  6. if not os.path.exists(path):
  7. print("FAIL: botnet/dorks.txt missing")
  8. sys.exit(1)
  9. with open(path, encoding="utf-8", errors="replace") as f:
  10. lines = f.read().splitlines()
  11. raw = len(lines)
  12. non_empty = [l for l in lines if l.strip()]
  13. unique = sorted(set(l.strip() for l in non_empty))
  14. if raw < 100:
  15. err.append(f"dorks.txt has only {raw} lines (expected > 100)")
  16. if len(non_empty) != raw:
  17. err.append(f"{raw - len(non_empty)} blank lines found")
  18. if len(unique) != len(non_empty):
  19. err.append(f"{len(non_empty) - len(unique)} duplicate dorks")
  20. malformed = 0
  21. for ln, line in enumerate(non_empty, start=1):
  22. if not any(tok in line for tok in ("=", "?", "/")):
  23. malformed += 1
  24. if malformed <= 5:
  25. err.append(f"line {ln} doesn't look like a dork: {line!r}")
  26. print(f"total={raw} non_empty={len(non_empty)} unique={len(unique)}")
  27. for e in err:
  28. print("FAIL:", e)
  29. sys.exit(0 if not err else 1)