test.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. """CDN/WAF detection: registry has the expected providers and detect_cdn returns expected shapes."""
  3. import sys
  4. err = []
  5. from core._cdn import detect_cdn, CDN_HEADER_SIGNATURES
  6. EXPECTED = ['Cloudflare', 'Akamai', 'AWS CloudFront', 'Fastly', 'Sucuri',
  7. 'Imperva (Incapsula)', 'Google Cloud / GFE', 'Microsoft Azure',
  8. 'KeyCDN', 'StackPath / MaxCDN', 'Bunny.net', 'CDN77',
  9. 'OVH / EdgeCDN', 'Section.io', 'Reblaze', 'F5 BIG-IP',
  10. 'Varnish (front)']
  11. for name in EXPECTED:
  12. if name not in CDN_HEADER_SIGNATURES:
  13. err.append(f"missing CDN signature: {name}")
  14. cdn, evidence = detect_cdn(None)
  15. if cdn is not None:
  16. err.append(f"detect_cdn(None) should return (None, None), got ({cdn}, {evidence})")
  17. try:
  18. cdn, evidence = detect_cdn("https://example.com/")
  19. print(f"example.com -> {cdn} ({evidence})")
  20. except Exception as e:
  21. err.append(f"detect_cdn raised on real URL: {type(e).__name__}: {e}")
  22. print(f"registry size: {len(CDN_HEADER_SIGNATURES)}")
  23. for e in err:
  24. print("FAIL:", e)
  25. sys.exit(0 if not err else 1)