Skip to content

Commit

Permalink
Add integration tests for API access methods
Browse files Browse the repository at this point in the history
Add Shadowsocks access method tests. Simply try to access the Mullvad
API using custom access methods.
  • Loading branch information
MarkusPettersson98 committed Feb 12, 2024
1 parent 88fcf98 commit f516bb6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/test-manager/src/tests/access_methods.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//! Integration tests for API access methods.
use super::{Error, TestContext};
use mullvad_management_interface::MullvadProxyClient;
use test_macro::test_function;
use test_rpc::ServiceClient;

/// Assert that custom access methods may be used to access the Mullvad API.
///
/// The tested access methods are:
/// * Shadowsocks
/// * Socks5 in remote mode
///
/// # Note
///
/// This tests assume that there exists working proxies *somewhere* for all
/// tested protocols. If the proxies themselves are bad/not running, this test
/// will fail due to issues that are out of the test manager's control.
///
///
#[test_function]
pub async fn test_custom_access_methods(
_: TestContext,
_rpc: ServiceClient,
mullvad_client: MullvadProxyClient,
) -> Result<(), Error> {
log::info!("Testing Shadowsocks access method");
test_shadowsocks(mullvad_client.clone()).await?;
log::info!("Testing SOCKS5 (Remote) access method");
test_socks_remote().await?;
Ok(())
}

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
// simply select a bridge server to derive all the needed parameters.
// mullvad_client
let relay_list = mullvad_client.get_relay_locations().await.unwrap();
let bridge = relay_list
.relays()
.find(|relay| matches!(relay.endpoint_data, RelayEndpointData::Bridge) && relay.active)
.expect("`test_shadowsocks` needs at least one shadowsocks relay to execute. Found non in relay list.");

let access_method: CustomProxy = relay_list
.bridge
.shadowsocks
.first()
.map(|shadowsocks| {
shadowsocks.to_proxy_settings(bridge.ipv4_addr_in.into())
})
.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:?}"
);

Ok(())
}

#[allow(clippy::unused_async)]
async fn test_socks_remote() -> Result<(), Error> {
unimplemented!("Testing SOCKS5 (Remote) access method is not implemented")
}
1 change: 1 addition & 0 deletions test/test-manager/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod access_methods;
mod account;
pub mod config;
mod dns;
Expand Down

0 comments on commit f516bb6

Please sign in to comment.