diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2016-12-07 12:36:10 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2016-12-07 12:36:10 +0100 |
| commit | 6cda4d3f9e8c9086731f714488af7c7fd4979726 (patch) | |
| tree | 88f45ebb6473bc8e3077fd3098f8efa7d3721c40 /src | |
| parent | db4fc5acc9278d13af9b8439953c43394289351d (diff) | |
| download | mullvadvpn-6cda4d3f9e8c9086731f714488af7c7fd4979726.tar.xz mullvadvpn-6cda4d3f9e8c9086731f714488af7c7fd4979726.zip | |
Properly show that RemoteAddr does not handle IPv6
Diffstat (limited to 'src')
| -rw-r--r-- | src/net.rs | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/net.rs b/src/net.rs index 2a7d64b861..70d585bba2 100644 --- a/src/net.rs +++ b/src/net.rs @@ -42,6 +42,8 @@ impl From<SocketAddr> for RemoteAddr { impl FromStr for RemoteAddr { type Err = AddrParseError; + /// Parse a string into a `RemoteAddr`. Does not work correctly with IPv6, see tests for + /// defined behavior fn from_str(s: &str) -> Result<Self, Self::Err> { let (address_str, port_str) = split_at_colon(s).map_err(|_| AddrParseError::InvalidPort)?; let port = u16::from_str(port_str).map_err(|_| AddrParseError::InvalidPort)?; @@ -122,18 +124,32 @@ mod tests { assert_eq!(3333, remote_addr.port()); } - #[test] - fn remote_addr_from_ipv6_str() { - let remote_addr = RemoteAddr::from_str("[fe80::1]:1337").unwrap(); - assert_eq!("[fe80::1]", remote_addr.address()); - assert_eq!(1337, remote_addr.port()); - } + // These tests exist to show that the parsing does not work exactly as the standard suggests + // https://tools.ietf.org/html/rfc3986#appendix-A + mod ipv6_invalid_parsing { + use std::str::FromStr; + use super::super::*; - #[test] - fn remote_addr_from_ipv6_str_without_port() { - let remote_addr = RemoteAddr::from_str("fe80::1").unwrap(); - assert_eq!("fe80:", remote_addr.address()); - assert_eq!(1, remote_addr.port()); + #[test] + fn remote_addr_from_ipv6_str_without_brackets() { + let remote_addr = RemoteAddr::from_str("fe80::1:1337").unwrap(); + assert_eq!("fe80::1", remote_addr.address()); + assert_eq!(1337, remote_addr.port()); + } + + #[test] + fn remote_addr_from_ipv6_str_with_brackets() { + let remote_addr = RemoteAddr::from_str("[fe80::1]:1337").unwrap(); + assert_eq!("[fe80::1]", remote_addr.address()); + assert_eq!(1337, remote_addr.port()); + } + + #[test] + fn remote_addr_from_ipv6_str_without_port() { + let remote_addr = RemoteAddr::from_str("fe80::1").unwrap(); + assert_eq!("fe80:", remote_addr.address()); + assert_eq!(1, remote_addr.port()); + } } #[test] |
