Skip to content

Commit 73f3342

Browse files
WIP Add SOCKS5 (remote) access method test
1 parent 0f66296 commit 73f3342

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

talpid-types/src/net/proxy.rs

+18
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ impl CustomProxy {
6565
}
6666
}
6767

68+
impl From<Socks5Remote> for CustomProxy {
69+
fn from(value: Socks5Remote) -> Self {
70+
CustomProxy::Socks5Remote(value)
71+
}
72+
}
73+
74+
impl From<Socks5Local> for CustomProxy {
75+
fn from(value: Socks5Local) -> Self {
76+
CustomProxy::Socks5Local(value)
77+
}
78+
}
79+
80+
impl From<Shadowsocks> for CustomProxy {
81+
fn from(value: Shadowsocks) -> Self {
82+
CustomProxy::Shadowsocks(value)
83+
}
84+
}
85+
6886
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
6987
pub struct Shadowsocks {
7088
pub endpoint: SocketAddr,

test/test-manager/src/tests/access_methods.rs

+33-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Integration tests for API access methods.
22
use super::{Error, TestContext};
33
use mullvad_management_interface::MullvadProxyClient;
4+
use talpid_types::net::proxy::CustomProxy;
45
use test_macro::test_function;
56
use test_rpc::ServiceClient;
67

@@ -26,13 +27,27 @@ pub async fn test_custom_access_methods(
2627
log::info!("Testing Shadowsocks access method");
2728
test_shadowsocks(mullvad_client.clone()).await?;
2829
log::info!("Testing SOCKS5 (Remote) access method");
29-
test_socks_remote().await?;
30+
test_socks_remote(mullvad_client.clone()).await?;
3031
Ok(())
3132
}
3233

34+
macro_rules! assert_access_method_works {
35+
($mullvad_client:expr, $access_method:expr) => {
36+
let successful = $mullvad_client
37+
.test_custom_api_access_method($access_method.clone().into())
38+
.await
39+
.expect("Failed to test custom API access method");
40+
41+
assert!(
42+
successful,
43+
"Failed while testing access method - {:?}",
44+
$access_method
45+
);
46+
};
47+
}
48+
3349
async fn test_shadowsocks(mut mullvad_client: MullvadProxyClient) -> Result<(), Error> {
3450
use mullvad_types::relay_list::RelayEndpointData;
35-
use talpid_types::net::proxy::CustomProxy;
3651
// Set up all the parameters needed to create a custom Shadowsocks access method.
3752
//
3853
// Since Mullvad host's Shadowsocks relays on their bridge servers, we can
@@ -54,19 +69,24 @@ async fn test_shadowsocks(mut mullvad_client: MullvadProxyClient) -> Result<(),
5469
})
5570
.expect("`test_shadowsocks` needs at least one shadowsocks relay to execute. Found non in relay list.");
5671

57-
let successful = mullvad_client
58-
.test_custom_api_access_method(access_method.clone().into())
59-
.await?;
60-
61-
assert!(
62-
successful,
63-
"Failed while testing access method - {access_method:?}"
64-
);
72+
assert_access_method_works!(mullvad_client, access_method.clone());
6573

6674
Ok(())
6775
}
6876

69-
#[allow(clippy::unused_async)]
70-
async fn test_socks_remote() -> Result<(), Error> {
71-
unimplemented!("Testing SOCKS5 (Remote) access method is not implemented")
77+
async fn test_socks_remote(mut mullvad_client: MullvadProxyClient) -> Result<(), Error> {
78+
use crate::vm::network::{NON_TUN_GATEWAY, SOCKS5_PORT};
79+
use std::net::SocketAddr;
80+
use talpid_types::net::proxy::Socks5Remote;
81+
// Set up all the parameters needed to create a custom SOCKS5 access method.
82+
//
83+
// The remote SOCKS5 proxy is assumed to be running on the test manager. On
84+
// which port it listens to is defined as a constant in the `test-manager`
85+
// crate.
86+
let endpoint = SocketAddr::from((NON_TUN_GATEWAY, SOCKS5_PORT));
87+
let access_method = CustomProxy::from(Socks5Remote::new(endpoint));
88+
89+
assert_access_method_works!(mullvad_client, access_method);
90+
91+
Ok(())
7292
}

0 commit comments

Comments
 (0)