Skip to content

Commit 4e74b54

Browse files
WIP Add Shadowsocks access method test
1 parent 1bfe15a commit 4e74b54

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

talpid-types/src/net/proxy.rs

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ pub struct Shadowsocks {
7676
pub cipher: String,
7777
}
7878

79+
impl From<Shadowsocks> for CustomProxy {
80+
fn from(value: Shadowsocks) -> Self {
81+
CustomProxy::Shadowsocks(value)
82+
}
83+
}
84+
7985
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
8086
pub struct Socks5Local {
8187
pub remote_endpoint: Endpoint,

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

+44-4
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,59 @@ use test_rpc::ServiceClient;
2121
pub async fn test_custom_access_methods(
2222
_: TestContext,
2323
_rpc: ServiceClient,
24-
_mullvad_client: MullvadProxyClient,
24+
mullvad_client: MullvadProxyClient,
2525
) -> Result<(), Error> {
2626
log::info!("Testing Shadowsocks access method");
27-
test_shadowsocks().await?;
27+
test_shadowsocks(mullvad_client.clone()).await?;
2828
log::info!("Testing SOCKS5 (Remote) access method");
2929
test_socks_remote().await?;
3030
Ok(())
3131
}
3232

33-
async fn test_shadowsocks() -> Result<(), Error> {
34-
panic!("Testing Shadowsocks access method has not been fully implemented yet!")
33+
async fn test_shadowsocks(mut mullvad_client: MullvadProxyClient) -> Result<(), Error> {
34+
use crate::tests::helpers;
35+
use mullvad_types::relay_list::RelayEndpointData;
36+
use std::net::SocketAddr;
37+
use talpid_types::net::proxy::Shadowsocks;
38+
// Set up all the parameters needed to create a custom Shadowsocks access method.
39+
//
40+
// Since Mullvad host's Shadowsocks relays on their bridge servers, we can
41+
// simply select a bridge server to derive all the needed parameters.
42+
// mullvad_client
43+
let bridges = helpers::filter_relays(&mut mullvad_client, |relay| {
44+
matches!(relay.endpoint_data, RelayEndpointData::Bridge)
45+
})
46+
.await?;
47+
48+
let shadowsocks_relay = bridges
49+
.first()
50+
.expect("`test_shadowsocks` needs at least one shadowsocks relay to execute. Found non in relay list.");
51+
52+
let access_method = Shadowsocks {
53+
endpoint: SocketAddr::from((
54+
shadowsocks_relay.ipv4_addr_in,
55+
// TODO(markus): Will this always be valid?
56+
443,
57+
)),
58+
// TODO(markus): Will this always be valid?
59+
password: "mullvad".to_string(),
60+
// TODO(markus): Will this always be valid?
61+
cipher: "aes-256-cfb".to_string(),
62+
};
63+
64+
let successful = mullvad_client
65+
.test_custom_api_access_method(access_method.clone().into())
66+
.await?;
67+
68+
assert!(
69+
successful,
70+
"Failed while testing access method - {access_method:?}"
71+
);
72+
73+
Ok(())
3574
}
3675

76+
#[allow(clippy::unused_async)]
3777
async fn test_socks_remote() -> Result<(), Error> {
3878
unimplemented!("Testing SOCKS5 (Remote) access method is not implemented")
3979
}

0 commit comments

Comments
 (0)