//! The three private ranges — the cases that came with the predicate from //! `cotton-ffi — shell::lan`, where it used to live. use super::*; #[test] fn it_knows_the_three_private_ranges_and_nothing_else() { assert!(is_private_ipv4("10.1.2.3")); assert!(is_private_ipv4("172.16.0.1")); assert!(!is_private_ipv4("172.32.0.1")); assert!(is_private_ipv4("192.168.99.1")); assert!(!is_private_ipv4("8.8.8.8")); assert!(!is_private_ipv4("not.an.ip")); assert!(!is_private_ipv4("999.1.1.1")); } #[test] fn it_holds_the_edges_of_the_172_range() { assert!(!is_private_ipv4("172.15.255.255")); assert!(is_private_ipv4("172.16.0.0")); assert!(is_private_ipv4("172.31.255.255")); assert!(!is_private_ipv4("172.32.0.0")); } #[test] fn anything_that_is_not_four_decimal_octets_is_not_an_address() { assert!(!is_private_ipv4("")); assert!(!is_private_ipv4("10.1.2")); assert!(!is_private_ipv4("10.1.2.3.4")); assert!(!is_private_ipv4("10.1.2.-3")); assert!(!is_private_ipv4("10.1.2. 3")); assert!(!is_private_ipv4("10.1.2.03x")); // IPv6 never reaches the octet parse: it has no dots to split on. assert!(!is_private_ipv4("fe80::1")); } #[test] fn loopback_is_this_machine_not_a_home_network() { assert!(!is_private_ipv4("127.0.0.1")); } // A tailnet address is a way of its own, never a LAN address: the two tests // never agree on one, so a tailnet hop is never taken for "across the room". #[test] fn a_tailnet_address_is_tailscales_range_and_never_a_lan_address() { for tailnet in ["100.64.0.1", "100.100.42.7", "100.127.255.255"] { assert!(is_tailnet_ipv4(tailnet), "{tailnet}"); assert!(!is_private_ipv4(tailnet), "{tailnet}"); } for other in ["100.63.255.255", "100.128.0.0", "192.168.1.14", "10.0.0.1", "127.0.0.1", "fd7a:115c:a1e0::1", "mac-c.tail0000.ts.net", ""] { assert!(!is_tailnet_ipv4(other), "{other}"); } }