Skip to content

Commit 06e1a6f

Browse files
Add integration tests for API access methods
Add Shadowsocks access method tests. Simply try to access the Mullvad API using custom access methods.
1 parent 4011170 commit 06e1a6f

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//! Integration tests for API access methods.
2+
use super::{Error, TestContext};
3+
use mullvad_management_interface::MullvadProxyClient;
4+
use test_macro::test_function;
5+
use test_rpc::ServiceClient;
6+
7+
/// Assert that custom access methods may be used to access the Mullvad API.
8+
///
9+
/// The tested access methods are:
10+
/// * Shadowsocks
11+
/// * Socks5 in remote mode
12+
///
13+
/// # Note
14+
///
15+
/// This tests assume that there exists working proxies *somewhere* for all
16+
/// tested protocols. If the proxies themselves are bad/not running, this test
17+
/// will fail due to issues that are out of the test manager's control.
18+
///
19+
///
20+
#[test_function]
21+
pub async fn test_custom_access_methods(
22+
_: TestContext,
23+
_rpc: ServiceClient,
24+
mullvad_client: MullvadProxyClient,
25+
) -> Result<(), Error> {
26+
log::info!("Testing Shadowsocks access method");
27+
test_shadowsocks(mullvad_client.clone()).await?;
28+
log::info!("Testing SOCKS5 (Remote) access method");
29+
test_socks_remote().await?;
30+
Ok(())
31+
}
32+
33+
async fn test_shadowsocks(mut mullvad_client: MullvadProxyClient) -> Result<(), Error> {
34+
use mullvad_types::relay_list::RelayEndpointData;
35+
use talpid_types::net::proxy::CustomProxy;
36+
// Set up all the parameters needed to create a custom Shadowsocks access method.
37+
//
38+
// Since Mullvad host's Shadowsocks relays on their bridge servers, we can
39+
// simply select a bridge server to derive all the needed parameters.
40+
// mullvad_client
41+
let relay_list = mullvad_client.get_relay_locations().await.unwrap();
42+
let bridge = relay_list
43+
.relays()
44+
.filter(|relay| matches!(relay.endpoint_data, RelayEndpointData::Bridge))
45+
.next()
46+
.expect("`test_shadowsocks` needs at least one shadowsocks relay to execute. Found non in relay list.");
47+
48+
let access_method: CustomProxy = relay_list
49+
.bridge
50+
.shadowsocks
51+
.first()
52+
.map(|shadowsocks| {
53+
shadowsocks.to_proxy_settings(bridge.ipv4_addr_in.into())
54+
})
55+
.expect("`test_shadowsocks` needs at least one shadowsocks relay to execute. Found non in relay list.");
56+
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+
);
65+
66+
Ok(())
67+
}
68+
69+
#[allow(clippy::unused_async)]
70+
async fn test_socks_remote() -> Result<(), Error> {
71+
unimplemented!("Testing SOCKS5 (Remote) access method is not implemented")
72+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod access_methods;
12
mod account;
23
pub mod config;
34
mod dns;

0 commit comments

Comments
 (0)