Skip to content

Commit

Permalink
Add SOCKS5 server to test-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Feb 6, 2024
1 parent f42dcb3 commit 419ea4f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/test-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rust-version.workspace = true
workspace = true

[dependencies]
fast-socks5 = "0.9.5"
anyhow = { version = "1", features = ["backtrace"] }
futures = { workspace = true }
regex = "1"
Expand Down
31 changes: 31 additions & 0 deletions test/test-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use std::path::PathBuf;
use anyhow::Context;
use anyhow::Result;
use clap::Parser;
use futures::StreamExt;
use std::net::SocketAddr;
use tests::config::DEFAULT_MULLVAD_HOST;

/// Test manager for Mullvad VPN app
Expand Down Expand Up @@ -248,6 +250,34 @@ async fn main() -> Result<()> {
.await
.context("Failed to run provisioning for VM")?;

let socks_server: fast_socks5::server::Socks5Server =
fast_socks5::server::Socks5Server::bind(SocketAddr::new(
crate::vm::network::NON_TUN_GATEWAY.into(),
crate::vm::network::SOCKS5_PORT,
))
.await
.context("Failed to start SOCKS5 server")?;
let socks_server = tokio::spawn(async move {
let mut incoming = socks_server.incoming();

while let Some(new_client) = incoming.next().await {
match new_client {
Ok(socket) => {
let fut = socket.upgrade_to_socks5();
tokio::spawn(async move {
match fut.await {
Ok(socket) => log::info!("socks client connected"),
Err(error) => log::error!("socks client failed: {error}"),
}
});
}
Err(error) => {
log::error!("failed to accept socks client: {error}");
}
}
}
});

let skip_wait = vm_config.provisioner != config::Provisioner::Noop;

let result = run_tests::run(
Expand Down Expand Up @@ -291,6 +321,7 @@ async fn main() -> Result<()> {
if display {
instance.wait().await;
}
socks_server.abort();
result
}
Commands::FormatTestReports { reports } => {
Expand Down
3 changes: 3 additions & 0 deletions test/test-manager/src/vm/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ pub use platform::{
CUSTOM_TUN_REMOTE_REAL_PORT, CUSTOM_TUN_REMOTE_TUN_ADDR, DUMMY_LAN_INTERFACE_IP,
NON_TUN_GATEWAY,
};

/// Port on NON_TUN_GATEWAY that hosts a SOCKS5 server
pub const SOCKS5_PORT: u16 = 54321;

0 comments on commit 419ea4f

Please sign in to comment.