Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_net/tests/routable.rs

1.2 KiB, 1 run

created by r1870400018:68850, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! Which addresses a server may connect to on a user's say-so: the special-purpose ranges that are
2//! neither private nor documentation by the usual names.
3//!
4//! [Written with AI entirely](https://need2know.ai/entirely-ai/code)\
5//! Anthropic Claude
6
7use oxedyne_fe2o3_net::addr::is_publicly_routable;
8
9use std::net::IpAddr;
10
11fn routable(s: &str) -> bool {
12 is_publicly_routable(&s.parse::<IpAddr>().expect("test address"))
13}
14
15#[test]
16fn test_special_purpose_ranges_are_refused_00() {
17 for s in [
18 "64:ff9b:1::a00:1", // local-use NAT64 carrying 10.0.0.1
19 "fec0::1", // site-local
20 "3fff::1", // documentation, RFC 9637
21 "2001:0:4136:e378:8000:63bf:3fff:fdd2", // Teredo
22 "2001:2::1", // benchmarking
23 "192.0.0.8", // IETF protocol assignments
24 "0.1.2.3", // "this network"
25 ] {
26 assert!(!routable(s), "{} should be refused", s);
27 }
28 for s in ["2606:4700::1111", "2001:4860:4860::8888", "193.0.0.1", "1.0.0.1", "2002:808:808::1"] {
29 assert!(routable(s), "{} should be allowed", s);
30 }
31}