Loading crates/tor-circmgr/src/path/exitpath.rs +31 −0 Original line number Diff line number Diff line Loading @@ -326,4 +326,35 @@ mod test { let owned: Result<OwnedPath> = (&bogus_path).try_into(); assert!(owned.is_err()); } #[test] fn no_exits() { // Construct a netdirwith no exits. let netdir = testnet::construct_custom_netdir(|_idx, bld| { bld.md.parse_ipv4_policy("reject 1-65535").unwrap(); }) .unwrap() .unwrap_if_sufficient() .unwrap(); let mut rng = rand::thread_rng(); let dirinfo = (&netdir).into(); let guards: OptDummyGuardMgr<'_> = None; let config = PathConfig::default(); // With target ports let outcome = ExitPathBuilder::from_target_ports(vec![TargetPort::ipv4(80)]) .pick_path(&mut rng, dirinfo, guards, &config); assert!(outcome.is_err()); assert!(matches!(outcome, Err(Error::NoRelays(_)))); // For any exit let outcome = ExitPathBuilder::for_any_exit().pick_path(&mut rng, dirinfo, guards, &config); assert!(outcome.is_err()); assert!(matches!(outcome, Err(Error::NoRelays(_)))); // For any exit (non-strict, so this will work). let outcome = ExitPathBuilder::for_timeout_testing().pick_path(&mut rng, dirinfo, guards, &config); assert!(outcome.is_ok()); } } crates/tor-circmgr/src/usage.rs +45 −25 Original line number Diff line number Diff line Loading @@ -608,7 +608,6 @@ mod test { assert_eq!(p_exit.len(), 3); // Now try testing circuits. for _ in 1..50 { let (path, usage, _, _) = TargetCircUsage::TimeoutTesting .build_path(&mut rng, di, guards, &config) .unwrap(); Loading @@ -633,6 +632,27 @@ mod test { } ); } #[test] fn build_testing_noexit() { // Here we'll try to build paths for testing circuits on a network // with no exits. let mut rng = rand::thread_rng(); let netdir = testnet::construct_custom_netdir(|_idx, bld| { bld.md.parse_ipv4_policy("reject 1-65535").unwrap(); }) .unwrap() .unwrap_if_sufficient() .unwrap(); let di = (&netdir).into(); let config = crate::PathConfig::default(); let guards: OptDummyGuardMgr<'_> = None; let (path, usage, _, _) = TargetCircUsage::TimeoutTesting .build_path(&mut rng, di, guards, &config) .unwrap(); assert_eq!(path.len(), 3); assert_eq!(usage, SupportedCircUsage::NoUsage); } #[test] Loading Loading
crates/tor-circmgr/src/path/exitpath.rs +31 −0 Original line number Diff line number Diff line Loading @@ -326,4 +326,35 @@ mod test { let owned: Result<OwnedPath> = (&bogus_path).try_into(); assert!(owned.is_err()); } #[test] fn no_exits() { // Construct a netdirwith no exits. let netdir = testnet::construct_custom_netdir(|_idx, bld| { bld.md.parse_ipv4_policy("reject 1-65535").unwrap(); }) .unwrap() .unwrap_if_sufficient() .unwrap(); let mut rng = rand::thread_rng(); let dirinfo = (&netdir).into(); let guards: OptDummyGuardMgr<'_> = None; let config = PathConfig::default(); // With target ports let outcome = ExitPathBuilder::from_target_ports(vec![TargetPort::ipv4(80)]) .pick_path(&mut rng, dirinfo, guards, &config); assert!(outcome.is_err()); assert!(matches!(outcome, Err(Error::NoRelays(_)))); // For any exit let outcome = ExitPathBuilder::for_any_exit().pick_path(&mut rng, dirinfo, guards, &config); assert!(outcome.is_err()); assert!(matches!(outcome, Err(Error::NoRelays(_)))); // For any exit (non-strict, so this will work). let outcome = ExitPathBuilder::for_timeout_testing().pick_path(&mut rng, dirinfo, guards, &config); assert!(outcome.is_ok()); } }
crates/tor-circmgr/src/usage.rs +45 −25 Original line number Diff line number Diff line Loading @@ -608,7 +608,6 @@ mod test { assert_eq!(p_exit.len(), 3); // Now try testing circuits. for _ in 1..50 { let (path, usage, _, _) = TargetCircUsage::TimeoutTesting .build_path(&mut rng, di, guards, &config) .unwrap(); Loading @@ -633,6 +632,27 @@ mod test { } ); } #[test] fn build_testing_noexit() { // Here we'll try to build paths for testing circuits on a network // with no exits. let mut rng = rand::thread_rng(); let netdir = testnet::construct_custom_netdir(|_idx, bld| { bld.md.parse_ipv4_policy("reject 1-65535").unwrap(); }) .unwrap() .unwrap_if_sufficient() .unwrap(); let di = (&netdir).into(); let config = crate::PathConfig::default(); let guards: OptDummyGuardMgr<'_> = None; let (path, usage, _, _) = TargetCircUsage::TimeoutTesting .build_path(&mut rng, di, guards, &config) .unwrap(); assert_eq!(path.len(), 3); assert_eq!(usage, SupportedCircUsage::NoUsage); } #[test] Loading