|
| 1 | +use std::str::FromStr; |
| 2 | + |
1 | 3 | use tempfile::NamedTempFile; |
| 4 | +use tentacle::multiaddr::Multiaddr; |
2 | 5 |
|
3 | 6 | use crate::utils::encrypt_decrypt_file::decrypt_from_file; |
4 | 7 | use crate::utils::encrypt_decrypt_file::encrypt_to_file; |
| 8 | +use crate::utils::is_addr_reachable; |
| 9 | + |
| 10 | +#[test] |
| 11 | +fn test_is_addr_reachable_with_onion3_address() { |
| 12 | + let onion3_addr = Multiaddr::from_str( |
| 13 | + "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:8228", |
| 14 | + ) |
| 15 | + .expect("valid onion3 multiaddr"); |
| 16 | + assert!( |
| 17 | + is_addr_reachable(&onion3_addr), |
| 18 | + "onion3 address should be considered reachable" |
| 19 | + ); |
| 20 | +} |
| 21 | + |
| 22 | +#[test] |
| 23 | +fn test_is_addr_reachable_with_private_ip() { |
| 24 | + let private_addr = |
| 25 | + Multiaddr::from_str("/ip4/192.168.1.1/tcp/8228").expect("valid private ip multiaddr"); |
| 26 | + assert!( |
| 27 | + !is_addr_reachable(&private_addr), |
| 28 | + "private IP address should not be considered reachable" |
| 29 | + ); |
| 30 | +} |
| 31 | + |
| 32 | +#[test] |
| 33 | +fn test_is_addr_reachable_with_public_ip() { |
| 34 | + let public_addr = |
| 35 | + Multiaddr::from_str("/ip4/1.1.1.1/tcp/8228").expect("valid public ip multiaddr"); |
| 36 | + assert!( |
| 37 | + is_addr_reachable(&public_addr), |
| 38 | + "public IP address should be considered reachable" |
| 39 | + ); |
| 40 | +} |
| 41 | + |
| 42 | +#[test] |
| 43 | +fn test_is_addr_reachable_with_dns4_address() { |
| 44 | + let dns4_addr = |
| 45 | + Multiaddr::from_str("/dns4/example.com/tcp/8228").expect("valid dns4 multiaddr"); |
| 46 | + assert!( |
| 47 | + is_addr_reachable(&dns4_addr), |
| 48 | + "dns4 address should be considered reachable" |
| 49 | + ); |
| 50 | +} |
5 | 51 |
|
6 | 52 | #[test] |
7 | 53 | fn test_encrypt_and_decrypt_success() { |
|
0 commit comments