-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend loopback workaround #140
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -830,6 +830,38 @@ fn loopback_to_localhost_v4() -> Result { | |
run_localhost_test(IpVersion::V4, bind_addr, connect_addr) | ||
} | ||
|
||
#[test] | ||
fn loopback_wildcard_public_v4() -> Result { | ||
let bind_addr = SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 1234); | ||
let connect_addr = SocketAddr::from((Ipv4Addr::new(192, 168, 0, 1), 1234)); | ||
run_localhost_test(IpVersion::V4, bind_addr, connect_addr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this verify the stream's addrs are set the same as what tokio::net types return? These need to behave the same way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
on both server and client. |
||
} | ||
|
||
#[test] | ||
fn loopback_localhost_public_v4() -> Result { | ||
let bind_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 1234); | ||
let connect_addr = SocketAddr::from((Ipv4Addr::new(192, 168, 0, 1), 1234)); | ||
let mut sim = Builder::new().ip_version(IpVersion::V4).build(); | ||
sim.client("client", async move { | ||
let listener = TcpListener::bind(bind_addr).await?; | ||
|
||
tokio::spawn(async move { | ||
let (mut socket, socket_addr) = listener.accept().await.unwrap(); | ||
socket.write_all(&[0, 1, 3, 7, 8]).await.unwrap(); | ||
|
||
assert_eq!(socket_addr.ip(), connect_addr.ip()); | ||
assert_eq!(socket.local_addr().unwrap().ip(), connect_addr.ip()); | ||
assert_eq!(socket.peer_addr().unwrap().ip(), connect_addr.ip()); | ||
}); | ||
|
||
let res = TcpStream::connect(connect_addr).await; | ||
assert_error_kind(res, io::ErrorKind::ConnectionRefused); | ||
|
||
Ok(()) | ||
}); | ||
sim.run() | ||
} | ||
|
||
#[test] | ||
fn loopback_to_wildcard_v6() -> Result { | ||
let bind_addr = SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 1234); | ||
|
@@ -844,6 +876,38 @@ fn loopback_to_localhost_v6() -> Result { | |
run_localhost_test(IpVersion::V6, bind_addr, connect_addr) | ||
} | ||
|
||
#[test] | ||
fn loopback_wildcard_public_v6() -> Result { | ||
let bind_addr = SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 1234); | ||
let connect_addr = SocketAddr::from((Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 1), 1234)); | ||
run_localhost_test(IpVersion::V6, bind_addr, connect_addr) | ||
} | ||
|
||
#[test] | ||
fn loopback_localhost_public_v6() -> Result { | ||
let bind_addr = SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 1234); | ||
let connect_addr = SocketAddr::from((Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 1), 1234)); | ||
let mut sim = Builder::new().ip_version(IpVersion::V6).build(); | ||
sim.client("client", async move { | ||
let listener = TcpListener::bind(bind_addr).await?; | ||
|
||
tokio::spawn(async move { | ||
let (mut socket, socket_addr) = listener.accept().await.unwrap(); | ||
socket.write_all(&[0, 1, 3, 7, 8]).await.unwrap(); | ||
|
||
assert_eq!(socket_addr.ip(), connect_addr.ip()); | ||
assert_eq!(socket.local_addr().unwrap().ip(), connect_addr.ip()); | ||
assert_eq!(socket.peer_addr().unwrap().ip(), connect_addr.ip()); | ||
}); | ||
|
||
let res = TcpStream::connect(connect_addr).await; | ||
assert_error_kind(res, io::ErrorKind::ConnectionRefused); | ||
|
||
Ok(()) | ||
}); | ||
sim.run() | ||
} | ||
|
||
#[test] | ||
fn remote_to_localhost_refused() -> Result { | ||
let mut sim = Builder::new().build(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe introduce a function that can compare the host for 2 IPs.