Skip to content

Commit

Permalink
Add SOCKS5 (remote) access method test
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Feb 12, 2024
1 parent f516bb6 commit 107d0f3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
18 changes: 18 additions & 0 deletions talpid-types/src/net/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ impl CustomProxy {
}
}

impl From<Socks5Remote> for CustomProxy {
fn from(value: Socks5Remote) -> Self {
CustomProxy::Socks5Remote(value)
}
}

impl From<Socks5Local> for CustomProxy {
fn from(value: Socks5Local) -> Self {
CustomProxy::Socks5Local(value)
}
}

impl From<Shadowsocks> for CustomProxy {
fn from(value: Shadowsocks) -> Self {
CustomProxy::Shadowsocks(value)
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Shadowsocks {
pub endpoint: SocketAddr,
Expand Down
46 changes: 33 additions & 13 deletions test/test-manager/src/tests/access_methods.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Integration tests for API access methods.
use super::{Error, TestContext};
use mullvad_management_interface::MullvadProxyClient;
use talpid_types::net::proxy::CustomProxy;
use test_macro::test_function;
use test_rpc::ServiceClient;

Expand All @@ -26,13 +27,27 @@ pub async fn test_custom_access_methods(
log::info!("Testing Shadowsocks access method");
test_shadowsocks(mullvad_client.clone()).await?;
log::info!("Testing SOCKS5 (Remote) access method");
test_socks_remote().await?;
test_socks_remote(mullvad_client.clone()).await?;
Ok(())
}

macro_rules! assert_access_method_works {
($mullvad_client:expr, $access_method:expr) => {
let successful = $mullvad_client
.test_custom_api_access_method($access_method.clone().into())
.await
.expect("Failed to test custom API access method");

assert!(
successful,
"Failed while testing access method - {:?}",
$access_method
);
};
}

async fn test_shadowsocks(mut mullvad_client: MullvadProxyClient) -> Result<(), Error> {
use mullvad_types::relay_list::RelayEndpointData;
use talpid_types::net::proxy::CustomProxy;
// Set up all the parameters needed to create a custom Shadowsocks access method.
//
// Since Mullvad host's Shadowsocks relays on their bridge servers, we can
Expand All @@ -53,19 +68,24 @@ async fn test_shadowsocks(mut mullvad_client: MullvadProxyClient) -> Result<(),
})
.expect("`test_shadowsocks` needs at least one shadowsocks relay to execute. Found non in relay list.");

let successful = mullvad_client
.test_custom_api_access_method(access_method.clone().into())
.await?;

assert!(
successful,
"Failed while testing access method - {access_method:?}"
);
assert_access_method_works!(mullvad_client, access_method);

Ok(())
}

#[allow(clippy::unused_async)]
async fn test_socks_remote() -> Result<(), Error> {
unimplemented!("Testing SOCKS5 (Remote) access method is not implemented")
async fn test_socks_remote(mut mullvad_client: MullvadProxyClient) -> Result<(), Error> {
use crate::vm::network::{NON_TUN_GATEWAY, SOCKS5_PORT};
use std::net::SocketAddr;
use talpid_types::net::proxy::Socks5Remote;
// Set up all the parameters needed to create a custom SOCKS5 access method.
//
// The remote SOCKS5 proxy is assumed to be running on the test manager. On
// which port it listens to is defined as a constant in the `test-manager`
// crate.
let endpoint = SocketAddr::from((NON_TUN_GATEWAY, SOCKS5_PORT));
let access_method = CustomProxy::from(Socks5Remote::new(endpoint));

assert_access_method_works!(mullvad_client, access_method);

Ok(())
}

0 comments on commit 107d0f3

Please sign in to comment.