import pytest PRIVATE_RANGES = [ "127.0.0.1", "10.0.0.1", "192.168.1.1", "172.16.0.1", "169.254.0.1", "::1", "fc00::1" ] def is_private_ip(ip: str) -> bool: import ipaddress try: addr = ipaddress.ip_address(ip) return addr.is_private or addr.is_loopback or addr.is_link_local except ValueError: return True def test_private_ips_rejected(): for ip in PRIVATE_RANGES: assert is_private_ip(ip), f"{ip} should be private" def test_public_ip_accepted(): assert not is_private_ip("8.8.8.8") assert not is_private_ip("1.1.1.1")