Skip to content

Commit

Permalink
fix localhost mapping in config
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Oct 13, 2023
1 parent ab7d132 commit 40bcbf8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/cli/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ mod tests {
let mut t = TestHelper::default();

let endpoint = t.open_socket_and_recv_single_packet().await;
let local_addr = available_addr(&AddressType::Random).await;
let mut local_addr = available_addr(&AddressType::Ipv6).await;
crate::test_utils::map_addr_to_localhost(&mut local_addr);
let proxy = crate::cli::Proxy {
port: local_addr.port(),
..<_>::default()
Expand All @@ -278,14 +279,16 @@ mod tests {
config.clusters.modify(|clusters| {
clusters.insert_default(
[Endpoint::new(
endpoint.socket.local_ipv4_addr().unwrap().into(),
endpoint.socket.local_ipv6_addr().unwrap().into(),
)]
.into(),
);
});
t.run_server(config, proxy, None);
tokio::time::sleep(std::time::Duration::from_millis(100)).await;

let msg = "hello";
tracing::debug!(%local_addr, "sending packet");
endpoint
.socket
.send_to(msg.as_bytes(), &local_addr)
Expand Down
12 changes: 2 additions & 10 deletions src/proxy/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,21 +658,13 @@ mod tests {
let mut t = TestHelper::default();
let dest = t.run_echo_server(&AddressType::Ipv6).await;
let mut dest = dest.to_socket_addr().await.unwrap();
crate::test_utils::map_addr_to_localhost(&mut dest);
let source = available_addr(&AddressType::Ipv6).await;
let socket = tokio::net::UdpSocket::bind(source).await.unwrap();
let mut source = socket.local_addr().unwrap();
crate::test_utils::map_addr_to_localhost(&mut source);
let (pool, _sender) = new_pool(None).await;

match &mut dest {
std::net::SocketAddr::V4(addr) => addr.set_ip(std::net::Ipv4Addr::LOCALHOST),
std::net::SocketAddr::V6(addr) => addr.set_ip(std::net::Ipv6Addr::LOCALHOST),
};

match &mut source {
std::net::SocketAddr::V4(addr) => addr.set_ip(std::net::Ipv4Addr::LOCALHOST),
std::net::SocketAddr::V6(addr) => addr.set_ip(std::net::Ipv6Addr::LOCALHOST),
};

let key: SessionKey = (source, dest).into();
let msg = b"helloworld";

Expand Down
8 changes: 5 additions & 3 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,15 @@ where

pub async fn map_to_localhost(address: &mut EndpointAddress) {
let mut socket_addr = address.to_socket_addr().await.unwrap();
map_addr_to_localhost(&mut socket_addr);
*address = socket_addr.into();
}

match &mut socket_addr {
pub fn map_addr_to_localhost(address: &mut SocketAddr) {
match address {
SocketAddr::V4(addr) => addr.set_ip(std::net::Ipv4Addr::LOCALHOST),
SocketAddr::V6(addr) => addr.set_ip(std::net::Ipv6Addr::LOCALHOST),
}

*address = socket_addr.into();
}

/// Opens a new socket bound to an ephemeral port
Expand Down
3 changes: 2 additions & 1 deletion tests/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use quilkin::{
#[tokio::test]
async fn token_router() {
let mut t = TestHelper::default();
let echo = t.run_echo_server(&AddressType::Random).await;
let mut echo = t.run_echo_server(&AddressType::Random).await;
quilkin::test_utils::map_to_localhost(&mut echo).await;
let server_port = 12348;
let server_proxy = quilkin::cli::Proxy {
port: server_port,
Expand Down
4 changes: 3 additions & 1 deletion tests/token_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ use quilkin::{
/// since they work in concert together.
#[tokio::test]
async fn token_router() {
quilkin::test_utils::enable_log("quilkin=trace");
let mut t = TestHelper::default();
let echo = t.run_echo_server(&AddressType::Ipv6).await;
let mut echo = t.run_echo_server(&AddressType::Ipv6).await;
quilkin::test_utils::map_to_localhost(&mut echo).await;

let capture_yaml = "
suffix:
Expand Down

0 comments on commit 40bcbf8

Please sign in to comment.